Certainly! Here's an example of a Python script that implements a simple command-line text-based adventure game. The game will ask the player for inputs and navigate them through a small story with choices and outcomes.
python
import random
def print_intro():
print("Welcome to the Adventure Game!")
print("You find yourself in a dark forest.")
print("There are two paths in front of you: one leading left and the other leading right.")
def choose_path():
path = ""
while path != "left" and path != "right":
path = input("Which path will you choose? (left/right): ").lower()
return path
def encounter_beast():
print("As you walk down the path, you suddenly encounter a fearsome beast!")
print("You have two choices: fight or run.")
choice = ""
while choice != "fight" and choice != "run":
choice = input("What will you do? (fight/run): ").lower()
if choice == "fight":
outcome = random.choice(["win", "lose"])
if outcome == "win":
print("You bravely fought the beast and emerged victorious!")
return True
else:
print("You fought bravely, but the beast was too strong. You have fallen...")
return False
else:
print("You chose to run away. You manage to escape but feel shame for not facing the beast.")
return True
def find_treasure():
print("You stumble upon a hidden cave glittering with treasure!")
print("Do you wish to take some treasure or leave it?")
choice = ""
while choice != "take" and choice != "leave":
choice = input("What will you do? (take/leave): ").lower()
if choice == "take":
print("You take some treasure and feel rich! You win!")
return True
else:
print("You decide to leave the treasure behind, feeling it's not yours. You return home safely.")
return True
def main():
print_intro()
path = choose_path()
if path == "left":
success = encounter_beast()
if success:
print("You continue your adventure and eventually find a way out of the forest.")
else:
print("Game over. Thank you for playing!")
else:
success = find_treasure()
if success:
print("You have completed your adventure. Well done!")
if __name__ == "__main__":
main()
How the Game Works:
The game starts with a brief introduction and asks the player to choose between two paths (left or right).
Depending on the chosen path:
If the player goes left, they encounter a beast and can either fight or run away.
If the player goes right, they find a hidden cave filled with treasure and can decide to take some or leave it.
There are random outcomes during the fight with the beast.
The game concludes based on the player's decisions and actions.
Running the Game:
To run this game, copy the code into a Python environment and execute the file. The game will prompt you for input based on the choices available.
Feel free to modify or expand the game! You can add more encounters and choices to make it more intricate.