Python迷宫游戏麻烦
我试着做一个游戏,让你穿过迷宫,试图逃离一个声音,但每次玩家对其中一个问题说了错误的答案,它说“游戏结束”,然后继续它阻止的地方,我已经尝试了很多事情和研究,但我似乎不明白,我只是一个初学者 ` 导入时间 导入操作系统Python迷宫游戏麻烦,python,maze,Python,Maze,我试着做一个游戏,让你穿过迷宫,试图逃离一个声音,但每次玩家对其中一个问题说了错误的答案,它说“游戏结束”,然后继续它阻止的地方,我已经尝试了很多事情和研究,但我似乎不明白,我只是一个初学者 ` 导入时间 导入操作系统 print ("Your adventure starts as a young boy, running away from home becuase you're a rebel") time.sleep(2) print ("You find the
print ("Your adventure starts as a young boy, running away from home becuase you're a rebel")
time.sleep(2)
print ("You find the famous labyrinth, do you go in?")
time.sleep(2)
answer = input("Make your choice, Yes OR No")
time.sleep(2)
print ("The answer",answer ,"got you stuck in a hole")
time.sleep(2)
print ("But you find a secret passage")
answer = input("Do you go through the door, Yes or No?")
if answer == "No":
time.sleep(2)
print ("Game Over.")
elif answer == "Yes":
time.sleep(2)
print("You hear a strange voice")
time.sleep(2)
answer = input("What do you say to the Voice, Hello or Who are you?")
if answer == "Hello":
print ("Hello")
elif answer == "Who are you?":
print ("Im your worst nightmare")
time.sleep(2)
print("You try and escape the labyrinth and turn a large gate with a gnome on the over end")
answer = input("Do you open the gate, Yes Or No?")
if answer == "Yes":
time.sleep(3)
print ("Game Over, you get brutally killed by a gnome, good job")
os._exit(0)
elif answer == "No":
time.sleep(3)
print ("You go the other way and see a light at the end of the tunnel")
answer = input("You see your family outside crying and waiting for you, do you go with them?")
if answer == "Yes":
print("You have a nice ending and you're sorry you ran away")
print("You have been graded: ")
elif answer == "No":
print("God smites you for being stupid.")
os._exit(0)`
以这个街区为例
print ("But you find a secret passage")
answer = input("Do you go through the door, Yes or No?")
if answer == "No":
time.sleep(2)
print ("Game Over.")
elif answer == "Yes":
time.sleep(2)
print("You hear a strange voice")
time.sleep(2)
# continuation
如果用户输入“否”,它将打印“游戏结束”-我认为这是正确的。但是,程序中的控制流继续通过if/else
块。您需要做的是使用类似于sys.exit()
的方法退出程序,或者确保您的控制流只有前进的路径(如果应该的话),即在if/else
块的真实部分包装接下来发生的事情
if answer == "No":
time.sleep(2)
print ("Game Over.")
elif answer == "Yes":
time.sleep(2)
print("You hear a strange voice")
time.sleep(2)
# put continuation here
以这个街区为例
print ("But you find a secret passage")
answer = input("Do you go through the door, Yes or No?")
if answer == "No":
time.sleep(2)
print ("Game Over.")
elif answer == "Yes":
time.sleep(2)
print("You hear a strange voice")
time.sleep(2)
# continuation
如果用户输入“否”,它将打印“游戏结束”-我认为这是正确的。但是,程序中的控制流继续通过if/else
块。您需要做的是使用类似于sys.exit()
的方法退出程序,或者确保您的控制流只有前进的路径(如果应该的话),即在if/else
块的真实部分包装接下来发生的事情
if answer == "No":
time.sleep(2)
print ("Game Over.")
elif answer == "Yes":
time.sleep(2)
print("You hear a strange voice")
time.sleep(2)
# put continuation here
抱歉,如果代码太混乱,希望您有时间阅读。您可以在组织方面做一些工作。使用空格(如果需要的话,可以使用过多的空格)。完全同意dude,当时正忙着这么做,没有太多时间,只是一个爱好。如果代码太乱,很抱歉,希望你有时间阅读。你可以在组织上做些工作。使用空格(如果需要的话,可以使用过多的空格)。完全同意dude,当时正忙着这么做,没有太多时间,只是一个业余爱好。或者,在
打印(“游戏结束”)后添加return
语句。
;)或者,在打印(“游戏结束”)
;)之后添加返回
语句