我正在开发一款游戏。现在,在我的游戏中,当我到达一个名为“room01”的特定地点(一个功能),虽然我还没有进一步指示它在哪里/如何继续前进,它会跳回到厨房功能的一个地方。为什么会这样?
我是新手,我无法弄清楚如何能够证明我的问题。这是我的完整代码:
#!/usr/bin/python2
def entrance_hall(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked):
if already_there_ent == False:
print("---------------------------------------------------------")
print "You are standing at the entrance hall of an apartment.The door you came through won't open.\
\nTo your immediate right is the kitchen(0),\
\nTo your left ahead is the main Lounge(1),\
\nStraight ahead is Room 1's door(2).\
\nFind you're way out!"
choice01 = raw_input("Where do you go? > ")
if choice01 == "right" or choice01 == "kitchen" or choice01 == "0" or choice01 == "go right" or choice01 == "go to kitchen":
kitchen(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
elif choice01 == "left" or choice01 == "main lounge" or choice01 == "1" or choice01 == "go left" or choice01 == "go to main lounge":
main_lounge(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
elif choice01 == "room" or choice01 == "straight" or choice01 == "2" or choice01 == "go straight" or choice01 == "go to room":
room01(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
else:
print "Not a valid option."
raw_input("> ")
already_there_ent = True
entrance_hall(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
elif already_there_ent == True:
choice01 = raw_input("Where do you go? > ")
if choice01 == "right" or choice01 == "kitchen" or choice01 == "0" or choice01 == "go right" or choice01 == "go to kitchen":
kitchen(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
elif choice01 == "left" or choice01 == "main lounge" or choice01 == "1" or choice01 == "go left" or choice01 == "go to main lounge":
main_Lounge(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
elif choice01 == "room" or choice01 == "straight" or choice01 == "2" or choice01 == "go straight" or choice01 == "go to room":
room01(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
else:
print "Not a valid option."
raw_input(">")
already_there_ent = True
entrance_hall(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
def kitchen(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked):
alias = {
'0': '0',
'first cupboard': '0',
'check first cupboard': '0',
'open first cupboard': '0',
'1': '1',
'second cupboard': '1',
'check second cupboard': '1',
'open second cupboard': '1',
'2': '2',
'third cupboard': '2',
'check third cupboard': '2',
'open third cupboard': '2',
'3': '3',
'read letter': '3',
'check letter': '3',
}
dic = {
"0":"You see a dusty empty bottles of milks, with spiderwebs at the corners of the cupboard. Nothing of Interest here.", \
"1":"You see some packs of likely expired cereal and a key(0).", \
"2":"You see an empty or dusty cupboard. Nothing of interest here.", \
"3":"Dear Shawn..... nothing of interest",
}
if already_there_kit == False:
print("---------------------------------------------------------")
print "There are 3 different cupboards(0, 1, 2) or a letter(3) placed on the counter."
choice02 = raw_input("What do you do? > ")
if choice02 == "leave kitchen" or choice02 == "entrance hall" or choice02 == "back" or choice02 == "go to entrance hall":
already_there_ent = False
already_there_kit = False
entrance_hall(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
elif choice02 in alias:
print dic[alias[choice02]]
if choice02 == "1":
print "..."
choice02_key = raw_input("What do you do? >")
if choice02_key == "pick key" or choice02_key == "0" or choice02_key == "key":
print("---------------------------------------------------------")
print "You picked the key. It probably unlocks some door."
key_picked = True
already_there_kit = True
kitchen(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
elif choice02 == "leave kitchen" or choice02 == "entrance hall" or choice02 == "back" or choice02 == "go to entrance hall":
already_there_ent = False
already_there_kit = False
entrance_hall(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
already_there_kit = True
kitchen(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
else:
print "Not a valid Option."
already_there_kit = True
kitchen(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
elif already_there_kit == True:
print "..."
choice02 = raw_input("What do you do? >")
if choice02 == "leave kitchen" or choice02 == "entrance hall" or choice02 == "back" or choice02 == "go to entrance hall":
already_there_ent = False
already_there_kit = False
entrance_hall(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
elif choice02 in alias:
print dic[alias[choice02]]
if choice02 == "1":
print "..."
choice02_key = raw_input("What do you do? >")
if choice02_key == "pick key" or choice02_key == "0" or choice02_key == "key":
print("---------------------------------------------------------")
print "You picked the key. It probably unlocks some door."
key_picked = True
already_there_kit = True
kitchen(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
elif choice02 == "leave kitchen" or choice02 == "entrance hall" or choice02 == "back" or choice02 == "go to entrance hall":
already_there_ent = False
already_there_kit = False
entrance_hall(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
already_there_kit = True
kitchen(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
else:
print "Not a valid Option."
already_there_kit = True
kitchen(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
def room01(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked):
if key_picked == True:
print("---------------------------------------------------------")
print "You unlocked the room using the key."
raw_input("> ")
print "You are now inside the room!. There is a bed, 2 drawers on its sides.\
\n The only window the room has is barricaded with iron grills.\
\n Apart, from that there is a fine painting of an old man on the western side wall."
choice02 = raw_input("What do you do? ")
elif key_picked == False:
print "This room is locked."
already_there_ent = True
entrance_hall(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
def main_lounge(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked):
print "Hmm.. How do i make this game interesting?"
entrance_hall(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
#-----------------------------------------------------------------------------------------------------------------------------------------------#
print "Welcome to the game"
raw_input("Press RETURN to start the hunt or CTRL + C to quit anytime.")
print "Hint: Make use the keys to easily navigate through i.e. xyz(1) or do not use CAPS in your input."
raw_input("> ")
already_there_ent = False
already_there_kit = False
already_there_room = False
already_there_lounge = False
key_picked = False
entrance_hall(already_there_ent, already_there_kit, already_there_room, already_there_lounge, key_picked)
答案 0 :(得分:0)
当你的函数结束时,它返回到它被调用的位置,然后程序继续到函数调用后的下一行。 它就是函数的工作原理