Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- # Define interactions with a dictionary
- interactions = {
- "orc_riddle": {
- "text": "You encounter two orcs who will give you directions if you solve their riddle.",
- "encountered": False
- },
- "mimic_chest": {
- "text": "You see a suspicious-looking chest. Do you open it?",
- "encountered": False
- },
- "shadow_dog": {
- "text": "A dog runs into a dark shadow. Do you follow it?",
- "encountered": False
- },
- "magic_sword": {
- "text": "You find a glowing sword on a pedestal.",
- "encountered": False,
- "item": "Magic Sword"
- },
- "healing_potion": {
- "text": "A mysterious bottle labeled 'Healing Potion' sits on a shelf. Do you take it?",
- "encountered": False,
- "item": "Healing Potion"
- },
- "ancient_key": {
- "text": "There's an ancient key hanging on the wall. It looks important.",
- "encountered": False,
- "item": "Ancient Key"
- },
- "mysterious_door": {
- "text": "You come across a large door with an intricate lock. It seems to require a key.",
- "encountered": False
- }
- # Add more interactions as needed
- }
- # Initial empty inventory
- inventory = []
- # Function to handle encounters
- def encounter(interaction_key):
- interaction = interactions[interaction_key]
- if interaction["encountered"]:
- return True
- print(interaction["text"])
- # Handling for item interactions
- if "item" in interaction:
- item_choice = input(f"Do you take the {interaction['item']}? (y/n) > ").lower().strip()
- if item_choice == "y":
- inventory.append(interaction['item'])
- print(f"You have obtained the {interaction['item']}. It's now in your inventory.")
- else:
- print(f"You decide not to take the {interaction['item']}.")
- interaction["encountered"] = False # Allow to encounter again since the item was not taken
- return True
- # Custom handling for each interaction
- if interaction_key == "orc_riddle":
- if "Magic Sword" in inventory:
- fight_choice = input("You have a Magic Sword. Do you want to fight the orcs? (y/n) > ").lower().strip()
- if fight_choice == "y":
- print("You wield your sword and with a swift motion, you defeat the orcs!")
- return True
- riddle_answer = input("Solve the riddle or pass: I am an odd number. Take away a letter and I become even. What number am I? > ").lower().strip()
- if riddle_answer == "seven":
- print("The orcs nod in approval and point you in the right direction.")
- else:
- print("The orcs laugh at your incorrect answer and disappear.")
- return False # Can add consequences here
- if interaction_key == "mimic_chest":
- open_choice = input("Do you open the chest? (y/n) > ").lower().strip()
- if open_choice == "y":
- if "Magic Sword" in inventory:
- fight_choice = input("It's a mimic! You have a Magic Sword. Do you want to fight? (y/n) > ").lower().strip()
- if fight_choice == "y":
- print("You fight off the mimic with your sword. Close call!")
- return True
- print("Teeth! It's a mimic! You've been bitten!")
- if "Healing Potion" in inventory:
- use_potion = input("You've been injured. Do you want to use your Healing Potion? (y/n) > ").lower().strip()
- if use_potion == "y":
- print("You quickly drink the Healing Potion and recover from your wounds!")
- inventory.remove("Healing Potion")
- return True
- # Can result in a game over if no potion is used and no sword to defend
- return "Healing Potion" in inventory # Survives if they have the potion
- if interaction_key == "mysterious_door":
- if "Ancient Key" in inventory:
- use_key = input("You have the Ancient Key. Do you want to use it on the door? (y/n) > ").lower().strip()
- if use_key == "y":
- print("The key turns with a satisfying click. The door swings open to reveal a treasure chamber!")
- # Victory condition
- return "victory"
- else:
- print("You decide not to use the key just yet.")
- interaction["encountered"] = False # Allow to encounter again since the door was not opened
- return False
- else:
- print("The door is locked. You'll need to find a key to open it.")
- interaction["encountered"] = False # Allow to encounter again since the door was not opened
- return True
- # Handling for the shadow dog interaction
- if interaction_key == "shadow_dog":
- dog_choice = input("Do you follow the dog into the shadow? (y/n) > ").lower().strip()
- if dog_choice == "y":
- print("You decide to follow the dog and find yourself in a serene meadow. It was just a friendly spirit.")
- else:
- print("You choose not to follow the dog, and it disappears into the shadow.")
- return True
- return True # The interaction was completed
- # Function to handle the game loop
- def game_loop():
- interaction_keys = list(interactions.keys())
- random.shuffle(interaction_keys) # Shuffle to randomize the order of encounters
- game_over = False
- while interaction_keys and not game_over:
- current_interaction_key = interaction_keys.pop()
- print("\nYou walk through the maze...")
- result = encounter(current_interaction_key)
- if result == "victory":
- print("Congratulations, you've completed the maze!")
- break # End game if the treasure is found
- elif result is False:
- # If interaction was not completed or player died, add it back to the list
- interaction_keys.append(current_interaction_key)
- random.shuffle(interaction_keys) # Shuffle again to ensure randomness
- elif result == "Healing Potion" in inventory:
- # The player survives the mimic but loses the potion
- inventory.remove("Healing Potion")
- print("You've used your Healing Potion to heal from the mimic's attack.")
- elif not result:
- # If result is a strict False, it means game over without a potion
- print("Without a potion to heal your wounds, you succumb to the mimic's poison.")
- game_over = True
- # Check if the door is the last remaining interaction
- if not game_over and len(interaction_keys) == 1 and "mysterious_door" in interaction_keys:
- print("\nAs you wander the maze, you realize there is nowhere left to go. The door with the intricate lock is your final challenge.")
- # Prompt for the next action
- if not game_over:
- while True: # Keep asking until a valid input is given
- player_choice = input("Do you want to continue exploring or check inventory? (c/i) > ").lower().strip()
- if player_choice == "i":
- print("Your inventory:", inventory)
- break # Break out of the inner loop to ask for the next action again
- elif player_choice == "c":
- # If the mysterious door is the last interaction, prompt the player to use the key
- if len(interaction_keys) == 1 and "mysterious_door" in interaction_keys:
- print("The mysterious door stands before you. It's time to use the key.")
- break # Continue with the next encounter
- else:
- print("Invalid input. Please type 'c' to continue or 'i' to check your inventory.")
- # Start the game
- print("Welcome to the Maze Adventure!")
- game_loop()
Add Comment
Please, Sign In to add comment