我正在写一个可怕的基于文本的冒险,我不知道如何打破这个循环。我将尝试在此处发布相关内容。如果我的评论不能充分解释我想要做什么,请告诉我。
chained = 1
finished = 0
# home() and club() act as rooms in the game
def home():
while chained == 1:
# there's a way to unchain yourself that works
chained = 0
while chained == 0:
print 'your are in the room'
input = raw_input('> ')
if 'exit' in input or 'leave' in input or 'club' in input:
current_room = 'club'
break
def club():
print "this works"
# These sort of move you around the rooms.
# current_room keeps track of what room you're in
current_room = 'home'
while finished == 0:
if current_room == 'home':
home()
if current_room == 'club':
club()
预期的行为是我将在输入中输入“exit”或“leave”或“club”,home() 函数将结束,club() 函数将启动。实际发生的是终端一直在打印“你在房间里”并不断给我输入。
如果必须,我会发布我完全未删节的代码,但我不想这样做,因为实际的冒险并不完全......专业。