Skip to content

Instantly share code, notes, and snippets.

@ryanorsinger
Created December 18, 2018 01:09
Show Gist options
  • Save ryanorsinger/be0ee4f14a63f4fdb0b054991aa0bfdb to your computer and use it in GitHub Desktop.
Save ryanorsinger/be0ee4f14a63f4fdb0b054991aa0bfdb to your computer and use it in GitHub Desktop.
Intro game in python
treasure = 0
def get_input(string):
print(string)
user_input = input("> ")
return user_input.upper()
def end_game():
if treasure > 0:
print("You got " + str(treasure) + " treasures!")
print("Game is over.")
def start_game():
print("welcome to the game!")
room1()
def room1():
print("You find yourself in room #1.")
decision = get_input("You see a DOOR and a WIN")
if decision == "WIN":
print("You win instantly. What a challenging game!")
end_game()
elif decision == "DOOR":
room2()
else:
print("That's not an option in this room.")
room1()
def room2():
global treasure
print("You're now in room #2")
decision = get_input("You see a DOOR back to room #1, a treasure CHEST, and a HALLWAY")
if decision == "DOOR":
room1()
elif decision == "CHEST":
treasure = treasure + 1
print("You now have " + str(treasure) + " treasure(s).")
room2()
elif decision == "HALLWAY":
room3()
else:
print("You remain in room #2")
room2()
def room3():
print("You are now in room #3")
decision = get_input("You see an EXIT and a HALLWAY back to room #2")
if decision == "EXIT":
end_game()
elif decision == "HALLWAY":
room2()
else:
room3()
wants_to_play = get_input("Would you like to play a game? Input y or yes. ")
if wants_to_play == "Y" or wants_to_play == "YES":
start_game()
else:
end_game()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment