Python文字游戏,功能不起作用?

我一直在阅读这本书:用艰苦的方式学习python,我来练习43,在那里你可以建立自己的"游戏"。这是我迄今为止的尝试,除了death()函数之外,所有函数都在工作?为什么不起作用?当我键入:python游戏。py>admin>left应该说我死了,但它也进入了"right"选项?这里是:

选择 | 换行 | 行号
  1. from sys import exit
  2. from random import randint
  3.  
  4.  
  5.  
  6.  
  7. def main_hall():
  8.     print "You are on the war ship. You need to get into the elevator to get to the bridge; where the General is."
  9.     print "The whole destroyer is on alert and nearly every door is locked. There is a keypad on the elevator."
  10.     print "There is a warning saying you only have 10 attemps, then the system deactivates and you cannot complete your mission. Be careful!"
  11.  
  12.     combination = "%d%d%d"  % (randint(1,9), randint(1,9), randint(1,9))
  13.  
  14.     guess = raw_input ("[Keypad:] ")
  15.  
  16.     guesses = 0
  17.  
  18.     while guess != combination and guesses < 10 and guess != "admin":
  19.         print "*BZZT!* ERROR 2355: Incorrect combination!"
  20.         guesses += 1
  21.         guess = raw_input ("[Keypad:] ")
  22.  
  23.     if guess == combination:
  24.         print "You open the elevator and start going up, fast. "
  25.         return 'junction'
  26.  
  27.     elif guess == "admin":
  28.         return 'junction'
  29.  
  30.     else:
  31.         print "You have had more than 10 attempts! \n A small self destruct system in the lock blows you up!\n"
  32.         return 'death'
  33.  
  34.  
  35.  
  36.  
  37. main_hall()
  38.  
  39.  
  40.  
  41. def junction():
  42.     print "When you get to the top, you are at a T-junction. Do you go left or right?"
  43.     action = raw_input ("> ")
  44.  
  45.     if action == "left":
  46.         print "You start running left, gun in hand, until you come across a turn, with some dark mist. You attempt to run through the mist, but you start to choke and you cannot get out. You die!"
  47.         return 'death'
  48.  
  49.     elif action == "right":
  50.         print "You start running down the right corridor, gun in hand. You finally make it to the brige where you must take control of the ship. You then reallize there is a crew of around 4-5 people. What do you do?"
  51.         return 'bridge'
  52.  
  53. def bridge():
  54.     action = raw_input ("Kill;\nPretend you're one of them?\nRun?\n> ")
  55.  
  56.     if action == "kill":
  57.         print "You click the safety off you rifle, and start opening fire. You manage to kill all but one of them. You try to shoot at the last man, but he is too fast! You see him initiate the self destruct! You die!"
  58.         return 'death'
  59.  
  60.     elif action == "pretend":
  61.         print "You walk into the bridge, casually. They dont make any signs of noticing at first, but then they see your uniform and start shouting questions at you. Then, they start shooting you. You start shooting back but it was too late. You die!"
  62.  
  63.     elif action == "run":
  64.         print "You start running back the way you came, until  you find somebody else from you ship. You tell him about what happens, you go back and complete the mission. Congratulations!"
  65.         return 'win'
  66.  
  67.  
  68. def win():
  69.     print "Horray! You take control of the ship, and become a hero!"
  70.     exit (1)
  71.  
  72. def death():
  73.     print "Well you really have failed this mission. GO HOME LOSER!"
  74.     exit (1)
  75.  
  76. junction()
  77. bridge()
  78. win()
  79. death()
# 回答1

不要抓住任何回报。将最后一行更改为

选择 | 换行 | 行号
  1. result = junction()
  2. if result != "death":
  3.     bridge()
  4.     win()
  5.     death() 

标签: python

添加新评论