Jessica Brown Posted December 25, 2024 Posted December 25, 2024 Objective Write a program that simulates an interactive text-based adventure game. The player must navigate through a series of challenges, make decisions, and reach the treasure at the end of the journey. The program should provide multiple paths and outcomes based on the player's choices. Requirements Input Handling: The program should take user input to make decisions (e.g., choosing between different paths or actions). Dynamic Storyline: Create at least three branches in the story with unique outcomes based on user decisions. Data Structures: Use appropriate data structures to manage the game's state (e.g., dictionaries for story branches, lists for inventory). Game Elements: Include a simple inventory system where the player can collect and use items. Incorporate at least one puzzle or riddle that the player must solve to progress. Add a "health" system where the player loses health points for wrong choices. Winning and Losing Conditions: The player should "win" by reaching the treasure. The game ends if the player's health reaches zero or they make a critical mistake. Code Reusability: Use functions or classes to avoid repetitive code. Bonus Challenges Add sound effects or animations (like ASCII art) for critical moments in the story. Implement a "save" and "load" feature to allow players to return to their last checkpoint. Allow players to retry from the last decision point if they lose. Example Output Start: Welcome to the Adventurer's Quest! You find yourself in a dark forest with two paths ahead. 1. Take the left path. 2. Take the right path. What do you choose? (Enter 1 or 2): Puzzle Encounter: You've encountered a mysterious gatekeeper who asks you a riddle: "I speak without a mouth and hear without ears. I have no body, but I come alive with wind. What am I?" Enter your answer: Inventory Use: You find a locked chest. You see a key in your inventory. Use it? (yes/no): Winning: Congratulations! You've reached the treasure and completed the Adventurer's Quest! Submission Guidelines Include your code with proper comments explaining each section. Provide a brief summary of your approach. If possible, share a link to a GitHub repository or CodeSandbox to showcase your work. Discussion Once you complete the challenge, share your program and discuss your approach with others in this thread. Feel free to ask for help or provide feedback on others' submissions. Let the adventure begin! CodeName: Jessica 💻 Linux Enthusiast | 🌍 Adventurer | 🦄 Unicorn 🌐 My Site | 📢 Join the Forum
Jessica Brown Posted yesterday at 01:10 PM Author Posted yesterday at 01:10 PM I wanted to give an example. Here is a python script to answer this challenge. import random def start_game(): print("\nWelcome to the Adventurer's Quest!") player = { "health": 100, "inventory": [] } main_path(player) def main_path(player): print("\nYou find yourself in a dark forest with two paths ahead.") print("1. Take the left path.") print("2. Take the right path.") choice = input("What do you choose? (Enter 1 or 2): ") if choice == "1": left_path(player) elif choice == "2": right_path(player) else: print("Invalid choice. Please choose 1 or 2.") main_path(player) def left_path(player): print("\nYou encounter a river. You can either swim across or look for a bridge.") print("1. Swim across.") print("2. Look for a bridge.") choice = input("What do you choose? (Enter 1 or 2): ") if choice == "1": player["health"] -= 20 print("\nThe water is cold and you lose 20 health points. Your health is now", player["health"]) if player["health"] <= 0: print("\nYou have succumbed to the cold. Game Over.") return left_forest(player) elif choice == "2": print("\nYou find a bridge and cross safely.") left_forest(player) else: print("Invalid choice. Please choose 1 or 2.") left_path(player) def left_forest(player): print("\nYou find a locked chest.") if "key" in player["inventory"]: print("You use the key from your inventory to open the chest.") print("Congratulations! You've found the treasure and won the game!") else: print("You don't have a key to open the chest. Keep exploring.") puzzle(player) def right_path(player): print("\nYou encounter a mysterious gatekeeper who asks you a riddle:") print("\"I speak without a mouth and hear without ears. I have no body, but I come alive with wind. What am I?\"") answer = input("Enter your answer: ").lower() if answer == "echo": print("\nCorrect! The gatekeeper lets you pass.") player["inventory"].append("key") print("You receive a key for your inventory.") left_forest(player) else: player["health"] -= 30 print("\nWrong answer! You lose 30 health points. Your health is now", player["health"]) if player["health"] <= 0: print("\nThe gatekeeper banishes you. Game Over.") return right_path(player) def puzzle(player): print("\nYou encounter another traveler who offers a riddle:") print("\"The more you take, the more you leave behind. What am I?\"") answer = input("Enter your answer: ").lower() if answer == "footsteps": print("\nCorrect! The traveler gives you a key.") player["inventory"].append("key") left_forest(player) else: print("\nWrong answer. Keep exploring.") main_path(player) if __name__ == "__main__": start_game() CodeName: Jessica 💻 Linux Enthusiast | 🌍 Adventurer | 🦄 Unicorn 🌐 My Site | 📢 Join the Forum
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now