python开发_自己开发的一个小游戏
先看看游戏的运行效果:




看完游戏的运行情况,你可能对游戏有了一定了了解:
#运行游戏后,玩家首先要进行语音的选择,1选择英语,2选择汉语,其他则默认选择英语
#根据玩家选择的语音,进入不同的语音环境
#游戏规则:玩家输入一个0-9的数字,系统根据玩家输入的数字,打印出数字的信息
# 如果玩家输入的数字范围不在0-9,则会打印出"Error!"
#退出游戏:游戏会随着打印信息的完成提示退出游戏
代码部分:
#运行游戏后,玩家首先要进行语音的选择,1选择英语,2选择汉语,其他则默认选择英语
#根据玩家选择的语音,进入不同的语音环境
#游戏规则:玩家输入一个0-9的数字,系统根据玩家输入的数字,打印出数字的信息
# 如果玩家输入的数字范围不在0-9,则会打印出"Error!"
#退出游戏:游戏会随着打印信息的完成提示退出游戏
language_option = """\
Language: Choose the language for System[OPTION]
-1 Choose English Language
-2 Choose Chinese Language
"""
enter_str = 'please enter an integer:'
#开始游戏前的说明
en_game_start_str = 'You choose English language!,Now,Game Start!'
cn_game_start_str = '你选择的中文模式!现在,开始游戏!'
#游戏规则
en_game_rule_str = 'you should enter a number that from 0 to 9,then the \nSystem will print the information of the number'
cn_game_rule_str = '你输入一个0-9的数字,系统会打印出该数字的信息'
#结束游戏
en_game_over_str = 'Game Over!'
cn_game_over_str = '游戏结束!'
print(language_option)
number = int(input(enter_str)) def print_info(num):
if num == 0:
print('0 zero 零')
elif num == 1:
print('1 one 壹')
elif num == 2:
print('2 two 贰')
elif num == 3:
print('3 three 叁')
elif num == 4:
print('4 four 肆')
elif num == 5:
print('5 five 伍')
elif num == 6:
print('6 six 陆')
elif num == 7:
print('7 seven 柒')
elif num == 8:
print('8 eight 捌')
elif num == 9:
print('9 nine 玖')
else:
print('Error!') def start_game(num):
if num == 1:
print(en_game_rule_str)
elif num == 2:
print(cn_game_rule_str)
else:
print(en_game_rule_str)
n = int(input(enter_str))
print_info(n) if number == 1:
print(en_game_start_str)
start_game(1)
print(en_game_over_str)
exit()
elif number == 2:
print(cn_game_start_str)
start_game(2)
print(cn_game_over_str)
exit()
else:
print(en_game_start_str)
start_game(number)
print(en_game_over_str)
exit()

才刚开始接触python,希望志同道合的朋友一起学习python....
=================================================
Edit by Hongten 2013-07-21
=================================================
下面是对以上程序的改进:
优化了print_info()方法,增加了询问玩家是继续玩功能..详细请参看代码
#运行游戏后,玩家首先要进行语音的选择,1选择英语,2选择汉语,其他则默认选择英语
#根据玩家选择的语音,进入不同的语音环境
#游戏规则:玩家输入一个0-9的数字,系统根据玩家输入的数字,打印出数字的信息
# 如果玩家输入的数字范围不在0-9,则会打印出"Error!"
#退出游戏:游戏会随着打印信息的完成提示退出游戏
language_option = """\
Language: Choose the language for System[OPTION]
-1 Choose English Language
-2 Choose Chinese Language
"""
enter_str = 'please enter an integer:' #开始游戏前的说明
en_game_start_str = 'You choose English language!,Now,Game Start!'
cn_game_start_str = '你选择的中文模式!现在,开始游戏!' #游戏规则
en_game_rule_str = 'you should enter a number that from 0 to 9,then the \nSystem will print the information of the number'
cn_game_rule_str = '你输入一个0-9的数字,系统会打印出该数字的信息' #结束游戏
en_game_over_str = 'Game Over!'
cn_game_over_str = '游戏结束!'
print(language_option) #定义列表
en_list = ['zero','one','two','three','four','five','six','seven','eight','nine']
cn_list = ['零','壹','贰','叁','肆','伍','陆','柒','捌','玖'] #循环标志
FLAG = True #还需要玩吗?
en_play_again_str = """\
#############################################
Do you want play again?
-1 Play Again
-2 Exit Game
"""
cn_play_again_str = """\
#############################################
你还要继续玩吗?
-1 继续玩
-2 退出游戏
""" number = int(input(enter_str)) #游戏打印信息
def print_info(num):
if num in range(0,9):
print(num,en_list[num],cn_list[num])
else:
print('Error!') #开始游戏
def start_game(num):
if num == 1:
print(en_game_rule_str)
elif num == 2:
print(cn_game_rule_str)
else:
print(en_game_rule_str)
n = int(input(enter_str))
print_info(n) #循环玩游戏
def play_again(n):
if n == 1:
print(en_play_again_str)
elif n == 2:
print(cn_play_again_str)
else:
print(en_play_again_str)
again = int(input(enter_str))
if again == 1:
pass
elif again == 2:
#这里使用的是全局变量,注意这里不要写成:global FLAG = False
global FLAG
FLAG = False #游戏的循环体
while True:
if FLAG:
if number == 1:
print(en_game_start_str)
start_game(1)
play_again(1)
elif number == 2:
print(cn_game_start_str)
start_game(2)
play_again(2)
else:
print(en_game_start_str)
start_game(number)
play_again(number)
else:
print(en_game_over_str)
break
#exit()
运行效果:


python开发_自己开发的一个小游戏的更多相关文章
- DirectX游戏开发——从一个小游戏開始
本系列文章由birdlove1987编写,转载请注明出处. 文章链接: http://blog.csdn.net/zhurui_idea/article/details/26364129 写在前面:自 ...
- Pygame:编写一个小游戏 标签: pythonpygame游戏 2017-06-20 15:06 103人阅读 评论(0)
大学最后的考试终于结束了,迎来了暑假和大四的漫长的"自由"假期.当然要自己好好"玩玩"了. 我最近在学习Python,本意是在机器学习深度学习上使用Python ...
- 使用PixiJS做一个小游戏
PixiJS PixiJS使用WebGL,是一个超快的HTML5 2D渲染引擎.作为一个Javascript的2D渲染器,Pixi.js的目标是提供一个快速的.轻量级而且是兼任所有设备的2D库. 官方 ...
- 零基础入门学习Python(4)--改进我们的小游戏
前言 在以前的博客中有做个一个小游戏,但是太简单了,所以这次就来对我们做的小游戏进行改进,改善从以下四个方面进行: 程序猜错的时候要给出提示,例如告诉用户输入的值是大了还是小了. 以前程序每运行一次只 ...
- js实现一个小游戏(飞翔的jj)
js实现一个小游戏(飞翔的jj) 源代码+素材图片在我的仓库 <!DOCTYPE html> <html lang="en"> <head> & ...
- 【h5-egret】如何快速开发一个小游戏
1.环境搭建 安装教程传送门:http://edn.egret.com/cn/index.php?g=&m=article&a=index&id=207&terms1_ ...
- 13、Cocos2dx 3.0三,找一个小游戏开发3.0中间Director :郝梦主,一统江湖
重开发人员的劳动成果.转载的时候请务必注明出处:http://blog.csdn.net/haomengzhu/article/details/27706967 游戏中的基本元素 在曾经文章中,我们具 ...
- Egret白鹭开发微信小游戏程序跳转功能(由一个小游戏跳转到另一个小游戏)
假设我们要实现的功能是从小游戏A跳转到小游戏B 对于小游戏A: (1)在platform.ts中添加代码如下: /** * 平台数据接口. * 由于每款游戏通常需要发布到多个平台上,所以提取出一个统一 ...
- iOS开发实战-基于SpriteKit的FlappyBird小游戏
写在前面 最近一直在忙自己的维P恩的事情 公司项目也是一团乱 于是...随手找了个游戏项目改了改就上线了,就当充数了. SpriteKit简介 SpriteKit是iOS 7之后苹果推出的2D游戏框架 ...
- 通过一个小游戏开始接触Python!
之前就一直嚷嚷着要找视频看学习Python,可是一直拖到今晚才开始....好好加油吧骚年,坚持不一定就能有好的结果,但是不坚持就一定是不好的!! 看着视频学习1: 首先,打开IDLE,在IDLE中新建 ...
随机推荐
- 前端神器!!gulp livereload实现浏览器自动刷新
首先gulp是基于Node的,所以确保你已经安装 node.js,在Nodejs官方网站下载跟自己操作系统相对应的安装包. 先说一下gulp安装流程: 1:全局安装gulp,操作为: npm inst ...
- weight decay (权值衰减)
http://blog.sina.com.cn/s/blog_890c6aa30100z7su.html 在机器学习或者模式识别中,会出现overfitting,而当网络逐渐overfitting时网 ...
- Android Jni调用浅述
声明:欢迎转载,转载时请注明出处!http://blog.csdn.net/flydream0/article/details/7371692 1 简述 JNI是Java Native Interfa ...
- Intro to DBSCAN
DBSCAN Density-Based Spatial Clustering of Application with Noise It can discover cluster of arbitra ...
- Jmeter-JDBC Connection Configuration和JDBC Request注释
1.JDBC Connection Configuration Variable Name--变量名,唯一值不可重复,给JDBC Request确定使用哪个配置 Max Number of Conne ...
- BZOJ - 4318: OSU! (期望DP&Attention)
Description osu 是一款群众喜闻乐见的休闲软件. 我们可以把osu的规则简化与改编成以下的样子: 一共有n次操作,每次操作只有成功与失败之分,成功对应1,失败对应0,n次操作对应为1 ...
- HDU2222 Keywords Search ac自动机第一题
指针我一般都会出错,所以还是自己写数组版本. In the modern time, Search engine came into the life of everybody like Google ...
- BZOJ2565 最长双回文串 【Manacher】
BZOJ2565 最长双回文串 Description 顺序和逆序读起来完全一样的串叫做回文串.比如acbca是回文串,而abc不是(abc的顺序为"abc",逆序为"c ...
- Win32 程序在启动时激活前一个启动程序的窗口
UWP 程序天生单实例.当然,新 API (10.0.17134)开始也提供了多实例功能.不过,传统 Win32 程序可就要自己来控制单实例了. 本文介绍简单的几个 Win32 方法调用,使 Win3 ...
- C++ sort 函数用法
MSDN中的定义: template<class RanIt>void sort(RanIt first, RanIt last); //--> 1)template<clas ...