Untitled
unknown
plain_text
2 years ago
1.5 kB
2
Indexable
import random def main(): print("Welcome to the Text Adventure Game!") print("You wake up in a strange room. There is a door to the north and a window to the east.") direction = input("Which direction would you like to go? (north/east): ") if direction == "north": print("You try to open the door, but it's locked. You need to find the key.") explore() elif direction == "east": print("You look out the window and see a beautiful garden. But you can't get out that way.") explore() else: print("Invalid direction. Please try again.") main() def explore(): print("You explore the room and find a key hidden under a rug. There is also a book on a shelf.") action = input("What would you like to do? (take key/read book): ") if action == "take key": print("You take the key.") unlocked = random.choice([True, False]) if unlocked: print("You use the key to unlock the door and escape!") else: print("You try to use the key on the door, but it doesn't work. You need to keep looking for another way out.") explore() elif action == "read book": print("You pick up the book and start reading. It's a fascinating story, but it doesn't help you escape.") explore() else: print("Invalid action. Please try again.") explore() if __name__ == "__main__": main()
Editor is loading...