sys.exit 用于结束程序
from sys import exit # 进入黄金房间后的逻辑
def gold_room():
print("This room is full of gold. How much do you take?") choice = input("> ")
# 如果输入不包含 0 或 1 则死
if "" in choice or "" in choice:
how_much = int(choice)
else:
dead("Man, learn to type a number.") # 如果输入的数字大于等于 50 则死
if how_much < 50:
print("Nice, you're not greedy, you win!")
exit(0)
else:
dead("You greedy basterd!") # 实现熊房间的逻辑
def bear_room():
print("There is a bear here.")
print("The bear has a bunch of honey.")
print("The fat bear is in front of another door.")
print("How are you going to move the bear?")
bear_moved = False # 如果熊离开后直接开门就用不到 while 循环了.
while True:
# print(">>> bear_moved1 = ", bear_moved)
choice = input("> ") if choice == "take honey":
# print(">>> bear_moved2 = ", bear_moved)
dead("The bear looks at you then slaps your face off.")
elif choice == "taunt bear" and not bear_moved:
# print(">>> bear_moved3 = ", bear_moved)
print("The bear has moved from the door.")
print("You can go through it now.")
bear_moved = True
elif choice == "taunt bear" and bear_moved:
# print(">>> bear_moved4 = ", bear_moved)
dead("The bear gets pissed off and chews your legs off.")
elif choice == "open door" and bear_moved:
# print(">>> bear_moved5 = ", bear_moved)
gold_room()
else:
print("I go no idea what that means.") # 恶魔房逻辑
def cthulhu_room():
print("Here you see the great evil Cthulhu.")
print("He, it, whatever stares at you and you go insane.")
print("Do you flee for your life or eat your head?") choice = input("> ") # 二选一,否则恶魔放循环
if "flee" in choice:
start()
elif "head" in choice:
dead("Well that was tasty!")
else:
cthulhu_room() # 惨死函数
def dead(why):
print(why, "Good job!")
exit(0) # 启动函数
def start():
print("You are in a dark room.")
print("There is a door to your right and left.")
print("Which one do you take?") choice = input("> ") if choice == "left":
bear_room()
elif choice == "right":
cthulhu_room()
else:
dead("You stumble around the room until you starve.") # 开始游戏
start()

运行结果

最新文章

  1. Appirater -- app中提示用户为app评价的提示框
  2. 解决UIButton 连续点击重复响应事件问题
  3. Android用ImageView显示本地和网上的图片
  4. 20个命令行工具监控Linux系统性能
  5. 特性节点Attribute
  6. php array_walk 和 array_reduce函数
  7. C++学习笔记(十六):友元
  8. 四元数(Quaternion)详细讲解以及在图形图像编程中的使用
  9. GUI之CCControlExtension
  10. H5 视频直播相关技术
  11. Python:操作数据库
  12. CSS的优先级和继承问题
  13. js中defer实现等文档加载完在执行脚本
  14. 用到的linux命令
  15. Struts2漏洞拉响网站安全红色警报以及把Struts2更新为最新版本Struts2.3.15.1步骤
  16. Eclipse及IDEA插件开发
  17. nyoj------------找球号(一)
  18. ENUMSTXT.H中的指针数组
  19. ryu 下发流表配置
  20. c++我在努力----第三次作业体会

热门文章

  1. .yaml参数文件的编写和使用
  2. Btrace官方教程-中文版
  3. Anatomy of a Database System学习笔记 - 公共模块、结语
  4. 菜鸟教程之学习Shell script笔记(中)
  5. GDI+ 或 GdiPlus 在VC6下的使用方法
  6. 基于JSP servlet mysql 的登陆页面
  7. nginx配置location总结及rewrite规则写法(转)
  8. CentOS编译安装软件过程中遇到zlib.h: No such file or directory
  9. 可视化n次贝塞尔曲线及过程动画演示--大宝剑
  10. Filter过滤器 不登陆无法访问其他页面