Treasure_Adventure

Prompt:
Using Python’s time module and print statement, design and implement a text-based adventure for a friend to play.


import time

def start_game(string):
   print("Welcome to the Treasure Hunt Adventure", string + "!")
   print("You find yourself at the entrance of a mysterious forest.")
   print("You have three paths in front of you: left, right, and straight.")


   while True:
       choice = input("Which path will you choose? (left/right/straight): ").lower()

       if choice == "left":
           go_left()
           break
       elif choice == "right":
           go_right()
           break
       elif choice == "straight":
           go_straight() 
           break
       else:
           print("Invalid choice. Please enter 'left', 'right', or 'straight'.")


def go_left():
   print("\nYou chose the left path.")
   print("You come across a river with a bridge.")
   print("Do you want to swim across or cross the bridge?")

   while True:
       choice = input("What will you do? (swim/bridge): ").lower()

       if choice == "swim":
           print("\nYou attempted to swim but got caught in a strong current.")
           print("Game Over. You didn't make it.")
           time.sleep(5)
           break
       elif choice == "bridge":
           print("\nYou safely cross the bridge and find an old temple.")
           explore_temple()
           break
       else:
           print("Invalid choice. Please enter 'swim' or 'bridge'.")


def go_right():
   print("\nYou chose the right path.")
   print("You encounter a cave entrance.")
   print("Do you want to enter the cave or continue along the path?")

   while True:
       choice = input("What will you do? (cave/continue): ").lower()

       if choice == "cave":
           explore_cave()
           break
       elif choice == "continue":
           print("\nYou continue along the path and reach a village.")
           print("You hear rumors of treasure hidden in the forest.")
           print("You've completed your adventure, but did not find the treasure.")
           time.sleep(5)
           break
       else:
           print("Invalid choice. Please enter 'cave' or 'continue'.")


# New function for the straight path
def go_straight():
   print("\nYou chose the straight path.")
   print("You find an ancient ruin with a mysterious door.")
   print("Do you want to try to open the door or go back?")

   while True:
       choice = input("What will you do? (open/back): ").lower()

       if choice == "open":
           explore_ruin()  # New function for exploring the ruin
           break
       elif choice == "back":
           print("\nYou decide to go back.")
           start_game(name)  # Restart the game
           break
       else:
           print("Invalid choice. Please enter 'open' or 'back'.")


def explore_ruin():
   print("\nYou successfully open the door and enter the ruin.")
   print("Inside, you find an ancient artifact with inscriptions.")
   print("You've found another valuable item, but not the real treasure!")

   # Continue
   continue_game()


def continue_game():
   print("Would you like to continue your adventure?")
   choice = input("Yes or No: ").lower()

   if choice == "yes":
       start_game(name)  # Restart the game
   elif choice == "no":
       print("\nThank you for playing!")
   else:
       print("Invalid choice. Please enter 'yes' or 'no'.")


def explore_temple():
   print("\nYou explore the temple and find a hidden chamber.")
   print("Inside, you discover a chest with a treasure!")
   print("Congratulations" , name + "! You found the hidden treasure.")
   print("You've successfully completed the adventure!")
   print("PS: The real treasure was the coding we learned along the way.")
   time.sleep(5)


def explore_cave():
   print("\nYou enter the cave and find it filled with bats.")
   print("You can't proceed further. You decide to turn back.")
   print("You've completed your adventure, but did not find the treasure.")
   time.sleep(5)

name = str(input("What is your name? : "))
# Start the game
start_game(name)

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *