CSharp Text Adventure

Lessons C# Book Chapter 4
C# Book · Chapter 4

Project 2 — The Text Adventure Engine

You’ve built a math engine. Now you’re going to build a story engine — a branching narrative system where the player makes choices, scenes change, and the world reacts instantly.

This is your first taste of real software architecture: scenes, state, input handling, and reusable structures. And yes — you’ll break it beautifully.

Chapter 4 of 6

A branching story engine.

The Text Adventure Engine is a console program that:

  • prints a scene description,
  • shows two or more choices,
  • lets the player type a number,
  • jumps to the next scene instantly,
  • and loops forever until the story ends.

It’s a choose‑your‑own‑adventure engine — and you can twist every knob.


The prompt recipe.

Copy and paste this prompt into your AI assistant:

“Write a complete C# console application called The Text Adventure Engine. Include: 1. A Scene class with: a description string, a list of choices, and a list of next-scene indexes. 2. A list of scenes that form a branching story. 3. A loop that prints the current scene, waits for user input, and jumps to the next scene. 4. Error handling for invalid input. 5. Clear comments explaining where to add new scenes and choices.”

Assemble the sandbox.

Once the AI gives you the code:

1
Create a new project

Open Visual Studio → Create a new project → Console App.

2
Paste the code

Replace everything in Program.cs with the AI’s output.

3
Run it

Press F5. Make choices. Watch the story branch.

Now let’s twist the knobs.


Twisting the knobs (how to play).

These tweaks turn your story engine into something wild.

🧩
Knob 1: Add hidden choices
Add a secret option that only appears if the player typed a specific word earlier.

You’ve just added state — the backbone of real game engines.

🔀
Knob 2: Randomized outcomes
Use Random.Shared.Next() to make certain choices unpredictable.

Now your story has chaos — and replay value.

🎭
Knob 3: Dynamic descriptions
Change scene text based on previous decisions.

You’ve created a reactive narrative system — the heart of interactive fiction.


What you just learned (naturally).

Without studying a textbook, you picked up:

  • Classes & objects: Your first custom data structure.
  • Lists of scenes: A simple but powerful content system.
  • Input handling: Reading and validating user choices.
  • State: Tracking what the player has done.
  • Branching logic: The foundation of every narrative engine.
You’re in C# Book · Chapter 4 of 6
Play‑First Programming · playfirstprogramming.com A clubhouse for curious builders