# coding:utf-8
#!/usr/bin/python
'''
Created on Jan 4, 2018
@author: wayne
'''
import random #导入模块
import time
def displayIntro(): #定义一个函数,不执行代码,在调用的时候才执行
print('you are in a land full of dragons.In front of you')
print('you see two caves.In one cave,the dragon is friendly')
print('and will share his treasure with you the other dragon')
print('is greedy and hungry,and will eat you on sight.')
print()
def chooseCave(): #定义一个玩家选择要进入的1或者2的函数
cave = '' #创建一个新的空字符串
while cave != '1' and cave != '2':
'''
布尔操作符,and,or,not
and 表示:表达式全为true为true,其中一个值为False或者全为False 表达式结果为False
>>> True and True
True
>>>True and False
False
>>> False and False
False
or:只要其中一个值为True 那么结果就为True ,只有两个值都为False的时候才是False
>>>True or False
True
>>> True or True
True
>>>False or False
False
not :只能作用一个值,不能两个值组合在一起,not是取值的反值
>>> not True
False
>>> not False
True
>>> not (1 ==2)
True
'''
print('which cave will you go into?(1 or 2)')
cave = input() #接收输入值,
return cave
def checkCave(chosenCave): #继承chosenCave的函数值
print('you approach the cave .....')
time.sleep(2)
print('it is dark and spooky.....')
time.sleep(2)
print('A large dragon jumps out in front of you!he opens his jaws and .....')
print()
time.sleep(2)
friendlyCave = random.randint(1,2) #随机产生一个数字,在1,2中间
if chosenCave == str(friendlyCave): #判断输入值和随机产生的值是否一致,一致则玩家获胜,否则失败
print('Gives you his treasure!')
else:
print('Gobbles you down in one bite!')
playAgain = 'yes' #存储一个初始值,"yes"
while playAgain == 'yes' or playAgain == 'y': #判断条件是否为True
displayIntro() #调用函数
caveNumber = chooseCave() #调用输入值的函数
checkCave(caveNumber) #调用checkCave的函数
print('Do you want to play again!(yes or no)') #判断玩家是否还要玩
playAgain = input() #接收键盘输入的值,如果是True则循环开始
python学习-游戏2
原创
©著作权归作者所有:来自51CTO博客作者abcwayne的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:html2练习
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
C语言学习2
第二天
操作符 数组 字符串 -
python学习-游戏
python 猜数字小游戏
python game python3 -
Cocos2dx学习笔记2:初识游戏引擎
一、分析proj.win32工程项目的主要构成 打开D:\cocos2d-x-3.4\tests\cocosxuexi\proj.win32目录下的cocosxuexi.sln 文件启动项目解决方案。 启动成功后,发现我们的解决方案由4个工程文件构成。 整个cocosxuexi的解决方案由cocosxuexi、libbox2d、libcocos2d、lib
cocos2dx cocos2dx创建项目 cocos2dx教程 win7+cocos2dx环境 cocos2dx技巧 -
通过游戏学习java面向对象编程(2)
通过游戏学习java面向对象编程(2)
数组 休闲 内部类 继承 javaswing事件 -
construct2游戏开发学习(四):循环
construct2提供了以下几种循环Repeatrepeat很简单,设定一个次数就可以了。c#里好像没有对应的。Forfor循环很常见,
游戏开发 2d construct2 循环 c# -
js基础笔记学习288游戏终止2
前端
学习 游戏 -
construct2游戏开发学习(二):变量
Construct2的变量分事件变量和对象变量,事件变量中又分全局变量和区域变量事件变量co
2d construct2 游戏开发 变量 全局变量