Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def inside(command, state):
- if "yes" in command:
- state["won"] = True
- elif "no" in command:
- state["hp"] = -100
- else:
- print("Unknown command")
- def outside(command, state):
- if "use" in command and "key" in command:
- if state.get("has_key") == True:
- print ("You use the key and enter inside the building.")
- print ("Now that you are inside, do you want to win?")
- state["location"] = inside
- else:
- print ("You do not have a key and you get shocked for trying (-1hp)")
- state["hp"] -= 1
- elif "look" in command:
- if "key" in command:
- print ("The key is nice and shiny")
- elif "door" in command:
- print ("The door is nice and strong")
- else:
- print ("You are standing outside. There is a key and a door")
- elif ("get" in command or "pick" in command) and "key" in command:
- state["has_key"] = True
- print("You got the key")
- else:
- print ("Unknown command")
- def intro(command, state):
- print("Welcome to the text adventure tutorial. You are standing outside. There is a key and a door")
- state["location"] = outside
- state = {"hp": 3, "location": intro, "won": False}
- command = ""
- state["location"](command, state)
- while state["hp"] > 0 and state["won"] == False:
- command = input("Command? ").lower()
- state["location"](command, state)
- if state["hp"] <= 0:
- print ("You died.")
- elif state["won"] == True:
- print ("You win! (hp:", state["hp"],")")
Advertisement
Add Comment
Please, Sign In to add comment