2016-05-12 15 views
0

Ich versuche, ein Spiel zu machen, wo Sie durch ein Labyrinth gehen und versuchen, von einer Stimme zu entkommen, aber jedes Mal sagt der Spieler die falsche Antwort auf eine der Fragen sagt es "Game Over" aber dann führt auf, wo sie gehalten weg, ich habe eine Menge Dinge, und recherchiert habe versucht, aber ich kann es nicht herausgefunden scheinen, ich bin nur ein AnfängerPython Maze Spiel Trouble

`

Importzeit import os

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)` 
+1

Sorry, wenn der Code als nächstes passiert ist zu chaotisch, hoffentlich hast du die Zeit es zu lesen. – AGAC

+1

Sie könnten etwas Arbeit für die Organisation verwenden. Verwenden Sie Leerzeichen (übermäßig, wenn nötig). – Jerrybibo

+0

Stimme völlig zu, Alter, war in Eile, dies zu tun, habe nicht viel Zeit, nur ein Hobby lol – AGAC

Antwort

2

nehmen Sie diesen Block, zum Beispiel

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 

Wenn der Benutzer "Nein" eingibt, wird "Game Over" gedruckt - was ich für richtig halte. Der Steuerungsablauf im Programm wird jedoch über den Block if/else hinaus fortgesetzt. Was Sie tun müssen, ist das Programm zu beenden, mit so etwas wie sys.exit() oder stellen Sie sicher, Ihre Steuerfluss nur Wege nach vorne, wenn es Umwickeln sollte also das, was im truthy Teil des if/else Block

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 
+2

Oder alternativ, fügen Sie eine 'return' Aussage nach' print ("Game Over.") ') – alfasin

+0

Vielen Dank, zurück ist eine gute Idee, es jetzt zu testen – AGAC

+0

Works, great job. Ich war dumm ahah – AGAC