Guest User

Untitled

a guest
Nov 1st, 2023
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.89 KB | Source Code | 0 0
  1. import random
  2.  
  3. # Define interactions with a dictionary
  4. interactions = {
  5.     "orc_riddle": {
  6.         "text": "You encounter two orcs who will give you directions if you solve their riddle.",
  7.         "encountered": False
  8.     },
  9.     "mimic_chest": {
  10.         "text": "You see a suspicious-looking chest. Do you open it?",
  11.         "encountered": False
  12.     },
  13.     "shadow_dog": {
  14.         "text": "A dog runs into a dark shadow. Do you follow it?",
  15.         "encountered": False
  16.     },
  17.     "magic_sword": {
  18.         "text": "You find a glowing sword on a pedestal.",
  19.         "encountered": False,
  20.         "item": "Magic Sword"
  21.     },
  22.     "healing_potion": {
  23.         "text": "A mysterious bottle labeled 'Healing Potion' sits on a shelf. Do you take it?",
  24.         "encountered": False,
  25.         "item": "Healing Potion"
  26.     },
  27.     "ancient_key": {
  28.         "text": "There's an ancient key hanging on the wall. It looks important.",
  29.         "encountered": False,
  30.         "item": "Ancient Key"
  31.     },
  32.     "mysterious_door": {
  33.         "text": "You come across a large door with an intricate lock. It seems to require a key.",
  34.         "encountered": False
  35.     }
  36.     # Add more interactions as needed
  37. }
  38.  
  39. # Initial empty inventory
  40. inventory = []
  41.  
  42. # Function to handle encounters
  43. def encounter(interaction_key):
  44.     interaction = interactions[interaction_key]
  45.     if interaction["encountered"]:
  46.         return True
  47.     print(interaction["text"])
  48.    
  49.     # Handling for item interactions
  50.     if "item" in interaction:
  51.         item_choice = input(f"Do you take the {interaction['item']}? (y/n) > ").lower().strip()
  52.         if item_choice == "y":
  53.             inventory.append(interaction['item'])
  54.             print(f"You have obtained the {interaction['item']}. It's now in your inventory.")
  55.         else:
  56.             print(f"You decide not to take the {interaction['item']}.")
  57.             interaction["encountered"] = False  # Allow to encounter again since the item was not taken
  58.         return True
  59.  
  60.     # Custom handling for each interaction
  61.     if interaction_key == "orc_riddle":
  62.         if "Magic Sword" in inventory:
  63.             fight_choice = input("You have a Magic Sword. Do you want to fight the orcs? (y/n) > ").lower().strip()
  64.             if fight_choice == "y":
  65.                 print("You wield your sword and with a swift motion, you defeat the orcs!")
  66.                 return True
  67.         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()
  68.         if riddle_answer == "seven":
  69.             print("The orcs nod in approval and point you in the right direction.")
  70.         else:
  71.             print("The orcs laugh at your incorrect answer and disappear.")
  72.             return False  # Can add consequences here
  73.  
  74.     if interaction_key == "mimic_chest":
  75.         open_choice = input("Do you open the chest? (y/n) > ").lower().strip()
  76.         if open_choice == "y":
  77.             if "Magic Sword" in inventory:
  78.                 fight_choice = input("It's a mimic! You have a Magic Sword. Do you want to fight? (y/n) > ").lower().strip()
  79.                 if fight_choice == "y":
  80.                     print("You fight off the mimic with your sword. Close call!")
  81.                     return True
  82.             print("Teeth! It's a mimic! You've been bitten!")
  83.             if "Healing Potion" in inventory:
  84.                 use_potion = input("You've been injured. Do you want to use your Healing Potion? (y/n) > ").lower().strip()
  85.                 if use_potion == "y":
  86.                     print("You quickly drink the Healing Potion and recover from your wounds!")
  87.                     inventory.remove("Healing Potion")
  88.                     return True
  89.                 # Can result in a game over if no potion is used and no sword to defend
  90.             return "Healing Potion" in inventory  # Survives if they have the potion
  91.  
  92.     if interaction_key == "mysterious_door":
  93.         if "Ancient Key" in inventory:
  94.             use_key = input("You have the Ancient Key. Do you want to use it on the door? (y/n) > ").lower().strip()
  95.             if use_key == "y":
  96.                 print("The key turns with a satisfying click. The door swings open to reveal a treasure chamber!")
  97.                 # Victory condition
  98.                 return "victory"
  99.             else:
  100.                 print("You decide not to use the key just yet.")
  101.                 interaction["encountered"] = False  # Allow to encounter again since the door was not opened
  102.                 return False
  103.         else:
  104.             print("The door is locked. You'll need to find a key to open it.")
  105.             interaction["encountered"] = False  # Allow to encounter again since the door was not opened
  106.             return True
  107.    
  108.     # Handling for the shadow dog interaction
  109.     if interaction_key == "shadow_dog":
  110.         dog_choice = input("Do you follow the dog into the shadow? (y/n) > ").lower().strip()
  111.         if dog_choice == "y":
  112.             print("You decide to follow the dog and find yourself in a serene meadow. It was just a friendly spirit.")
  113.         else:
  114.             print("You choose not to follow the dog, and it disappears into the shadow.")
  115.         return True
  116.     return True  # The interaction was completed
  117.  
  118. # Function to handle the game loop
  119. def game_loop():
  120.     interaction_keys = list(interactions.keys())
  121.     random.shuffle(interaction_keys)  # Shuffle to randomize the order of encounters
  122.  
  123.     game_over = False
  124.     while interaction_keys and not game_over:
  125.         current_interaction_key = interaction_keys.pop()
  126.         print("\nYou walk through the maze...")
  127.         result = encounter(current_interaction_key)
  128.  
  129.         if result == "victory":
  130.             print("Congratulations, you've completed the maze!")
  131.             break  # End game if the treasure is found
  132.         elif result is False:
  133.             # If interaction was not completed or player died, add it back to the list
  134.             interaction_keys.append(current_interaction_key)
  135.             random.shuffle(interaction_keys)  # Shuffle again to ensure randomness
  136.         elif result == "Healing Potion" in inventory:
  137.             # The player survives the mimic but loses the potion
  138.             inventory.remove("Healing Potion")
  139.             print("You've used your Healing Potion to heal from the mimic's attack.")
  140.         elif not result:
  141.             # If result is a strict False, it means game over without a potion
  142.             print("Without a potion to heal your wounds, you succumb to the mimic's poison.")
  143.             game_over = True
  144.        
  145.         # Check if the door is the last remaining interaction
  146.         if not game_over and len(interaction_keys) == 1 and "mysterious_door" in interaction_keys:
  147.             print("\nAs you wander the maze, you realize there is nowhere left to go. The door with the intricate lock is your final challenge.")
  148.  
  149.         # Prompt for the next action
  150.         if not game_over:
  151.             while True:  # Keep asking until a valid input is given
  152.                 player_choice = input("Do you want to continue exploring or check inventory? (c/i) > ").lower().strip()
  153.                 if player_choice == "i":
  154.                     print("Your inventory:", inventory)
  155.                     break  # Break out of the inner loop to ask for the next action again
  156.                 elif player_choice == "c":
  157.                     # If the mysterious door is the last interaction, prompt the player to use the key
  158.                     if len(interaction_keys) == 1 and "mysterious_door" in interaction_keys:
  159.                         print("The mysterious door stands before you. It's time to use the key.")
  160.                     break  # Continue with the next encounter
  161.                 else:
  162.                     print("Invalid input. Please type 'c' to continue or 'i' to check your inventory.")
  163.  
  164. # Start the game
  165. print("Welcome to the Maze Adventure!")
  166. game_loop()
  167.  
Add Comment
Please, Sign In to add comment