Untitled

 avatar
unknown
plain_text
a month ago
2.9 kB
1
Indexable


Code: Adventure Game in Python

import time

def print_pause(message):
    print(message)
    time.sleep(2)

def intro():
    print_pause("You find yourself standing at the entrance of a dark cave.")
    print_pause("Legends say the cave is filled with treasures but also guarded by a fearsome dragon.")
    print_pause("With a sword in hand and a torch, you step inside.")

def cave_adventure():
    print_pause("\nAs you move deeper into the cave, you come to a fork.")
    print_pause("To the left, you hear the faint sound of running water.")
    print_pause("To the right, there's an eerie silence.")
    choice = input("Which way do you go? (left/right): ").lower()

    if choice == "left":
        waterfall_scene()
    elif choice == "right":
        dragon_scene()
    else:
        print_pause("Invalid choice. Please type 'left' or 'right'.")
        cave_adventure()

def waterfall_scene():
    print_pause("\nYou head left, following the sound of water.")
    print_pause("You discover a beautiful underground waterfall.")
    print_pause("Behind the waterfall, you find a chest filled with gold and jewels!")
    print_pause("Congratulations! You've found the treasure.")
    play_again()

def dragon_scene():
    print_pause("\nYou head right, stepping into the silent corridor.")
    print_pause("Suddenly, a massive dragon blocks your path!")
    print_pause("It roars, and flames light up the cave walls.")
    choice = input("Do you fight the dragon or run away? (fight/run): ").lower()

    if choice == "fight":
        print_pause("You charge at the dragon with your sword raised.")
        print_pause("But the dragon is too strong. You are defeated.")
        print_pause("Game Over.")
        play_again()
    elif choice == "run":
        print_pause("You turn around and run as fast as you can.")
        print_pause("You escape the cave, but the treasure remains undiscovered.")
        play_again()
    else:
        print_pause("Invalid choice. Please type 'fight' or 'run'.")
        dragon_scene()

def play_again():
    choice = input("\nWould you like to play again? (yes/no): ").lower()
    if choice == "yes":
        print_pause("Restarting the game...")
        play_game()
    elif choice == "no":
        print_pause("Thanks for playing! Goodbye.")
    else:
        print_pause("Invalid choice. Please type 'yes' or 'no'.")
        play_again()

def play_game():
    intro()
    cave_adventure()

# Start the game
play_game()

Features:

1. Storyline: Players explore a cave, choose paths, and encounter challenges.


2. Choices: The player's decisions (e.g., left/right, fight/run) affect the outcome.


3. Replayability: Players can replay the game with different choices.


4. Simplicity: Easy to understand and expand upon.



You can enhance the game by adding more paths, challenges, or inventory management. Let me know if you'd like help with that!

Leave a Comment