2017-01-25 3 views
0

In meiner Computer-Klasse wurden wir beauftragt, ein Text-Abenteuer-Spiel in Python zu erstellen. Ich habe schon etwas bekommen, aber mit meinem Wissen konnte ich nur so weit kommen. Vermutlich vermisse ich etwas sehr Einfaches, aber ich stecke gerade fest. Es ist ein Multiple-Choice-Deal, bei dem der Charakter mit 3 Optionen präsentiert wird, sich umschaut, bewegt oder auf Inventar zugreift. Ich bin ratlos darüber, wie man den Code auf seiner eigenen Tangente ablaufen lässt.Probleme im Text Abenteuer Python Spiel

Ich habe es zu, wo der Spieler eine Beschreibung ihrer Umgebung bekommen kann, aber wenn sie tun und die Optionen kommen wieder, es irgendwie Fehler und zeigt die Optionen wieder und dann die nächste Spielereingabe stoppt den Code alle zusammen. Wenn der Spieler also "sich umschaut" und dann entscheidet, dass er "Bewegen" möchte, hört der Code auf.

Und im ersten Bereich gibt es zwei Richtungen können Sie, Norden und Osten gehen. Selbst wenn du nach Osten gehst und dich dann umschaust, erhältst du eine Beschreibung, wie der nördliche Raum aussieht.

auch, ich brauche Hilfe ein Inventar-System bekommen konkretisiert. Ich habe keine Ahnung, wie ich das machen würde.

Und es gibt bestimmte Zeiten im Spiel (zumindest plante ich, sie eingeschlossen zu haben), wo der Spieler Aussagen machen konnte wie "Get Artikel hier einfügen" Wie würde ich diese Aktionen erstellen?

Hier ist der Code.

import random 
import time 
print ("You awake in what looks like an adandoned diner with a pounding headache.") 

d1a = input ("""What would you like to do?: 
    1. Look around 
    2. Move 
    3. Inventory """) 
while d1a != "1" and d1a != "2": 
    #add option 3 to the loop 

    d1a = input ("What would you like to do?") 

if d1a == "1": 
    print() 
    print ("It looks like an old diner. Dust and grime coat the tables, chairs and counter tops. You see a door to the North and another to the East.") 
    print() 
    time.sleep(1.5) 
    d1a = input ("""What would you like to do?: 
    1. Look around 
    2. Move 
    3. Inventory """) 




elif d1a == "2": 
    d2a = input ("""Where? 
    North 
    West 
    South 
    East""") 

    while d2a != "North" and d2a != "north" and d2a != "West" and d2a != "west" and d2a != "South" and d2a != "south" and d2a != "East" and d2a != "east": 
     d2a = input ("Where?") 


    if d2a == "North" or d2a == "north": 
     print() 
     print ("You go through through the door to the North") 
     print ("which has lead to you what looks to be the kitchen") 
     print() 
     time.sleep(1) 

    elif d2a == "East" or d2a == "east": 
     print() 
     print("You step through the door to the east which") 
     print ("takes you out to the streets. They look") 
     print ("musty and old, cracks ravaging the asphalt.") 
     print() 
     time.sleep(1) 

    elif d2a == "West" or d2a == "west": 
     print() 
     print ("I can't move there.") 
     print() 
     time.sleep(1) 

    elif d2a == "South" or d2a == "south": 
     print() 
     print ("I can't move there.") 
     print() 
     time.sleep(1) 





d1a = input ("""What would you like to do?: 
    1. Look around 
    2. Move 
    3. Inventory """) 
while d1a != "1" and d1a != "2": 
    #add option 3 to the loop 

    d1a = input ("What would you like to do?") 

if d1a == "1": 
    print() 
    print ("Must be the kitchen area. You can see stoves, ovens, cabinets containing pots and pans. A dishwasher is open exposing a group of knives. If they're clean or not is unknown.") 
    print() 
    time.sleep(1.5) 
    d1a = input ("""What would you like to do?: 
    1. Look around 
    2. Move 
    3. Inventory """) 

elif d1a == "2": 
    d2a = input ("""Where?: 
    North 
    west 
    south 
    East""") 

Sorry, ich relativ neu bin zu Codierung meiner Klasse habe gerade angefangen in sie einzutauchen, aber ich wollte testen, was ich mit diesem Spiel tun könnte.

+0

Willkommen bei Stack Overflow! Sie können [die Tour] (http://stackoverflow.com/tour) zuerst und lernen [Wie man eine gute Frage stellt] (http://stackoverflow.com/help/how-to-ask) und erstellen Sie eine [ Minimal, vollständig und verifizierbar] (http://stackoverflow.com/help/mcve) Beispiel. Das erleichtert es uns, Ihnen zu helfen. –

Antwort

0

Ich denke, wenn Sie sich nach Norden/Osten bewegen, sollten Sie eine Variable, 'Ort', zum Beispiel der Stelle zuweisen, an die Sie sich bewegen. Wenn Sie sich dann umsehen, sollten Sie eine if-Anweisung verwenden, um zu sehen, wo sich der Standort befindet, und dann die korrekte Beschreibung eingeben.