DEV Community

Cover image for Interactive Adventure: A Step-by-Step CLI Choice Game
Joe Antebi
Joe Antebi

Posted on

Interactive Adventure: A Step-by-Step CLI Choice Game

Life is full of unknowns, and navigating through uncertainty requires thoughtful decision-making and adaptability. Imagine being thrust into a mysterious and unfamiliar world, where every choice you make can lead to danger, discovery, or triumph. This scenario mirrors the challenges we often face in real life—decisions with unclear outcomes that demand courage and wisdom.

Introduce the problem

print("Life is full of unknowns, and every choice you make can lead to different outcomes.")
print("Are you ready to navigate this adventure?")

In the context of game, the solution lies in your ability to make thoughtful decisions, observe your surroundings, and use the resources you discover along the way. The game presents you with two doors: one leads to an empty room with hidden potential, while the other introduces you to a fearsome dragon. Each choice you make—from choosing a door to deciding whether to explore or fight—shapes the course of your journey.

Present the player with a choice of two doors

print("You see two doors before you. Which one will you choose?")
choice = input("Type 'left' for the left door or 'right' for the right door: ").lower()
if choice == 'left':
print("You enter an empty room. What will you do next?")
elif choice == 'right':
print("You encounter a fearsome dragon! Prepare yourself!")
else:
print("Invalid choice. Try again.")

By applying a mix of strategy, observation, and bravery, you can overcome challenges, uncover hidden tools (like a sword in the seemingly empty room), and prepare yourself for encounters with powerful foes. The game teaches the importance of preparation and how seizing opportunities can lead to success.

Through this interactive adventure, you’ll learn valuable lessons about risk assessment, strategic thinking, and the importance of curiosity. Each scenario presents an opportunity to reflect on how choices impact outcomes. Whether it’s deciding to explore an empty room, taking the sword, or facing the dragon, you’ll experience firsthand how preparation and decision-making intertwine.

Simulate finding a sword in the empty room

print("The room seems empty, but you decide to look around.")
found_item = "sword"
print(f"You found a {found_item}! This might come in handy later.")

Embarking on the Journey
The Adventure of the Two Doors begins with a simple question: What is your name? From there, you’ll step into a world where every action counts. Choose a door, explore your surroundings, and decide how to respond to challenges. Will you uncover the hidden sword and defeat the dragon, or will hesitation lead to an untimely end? The choices are yours to make, and the lessons are yours to take away.

Simulate the dragon encounter and decision to fight

name = input("What is your name, traveler? ")
print(f"Welcome, {name}, to the Adventure of the Two Doors!")
has_sword = False

Player chooses a door

print("You see two doors before you. Which one will you choose?")
choice = input("Type 'left' for the left door or 'right' for the right door: ").lower()

if choice == 'left':
print("You enter an empty room.")
explore = input("Do you want to look around? (yes/no): ").lower()
if explore == 'yes':
print("You found a sword!")
has_sword = True
elif choice == 'right':
print("You encounter a dragon!")

Dragon encounter

print("You face a fearsome dragon!")
if has_sword:
print("You draw your sword and defeat the dragon. You win!")
else:
print("You have no weapon to defend yourself. The dragon defeats you. Game over.")

Are you ready to face the unknown? Take the first step, and let the adventure begin!

Top comments (0)