Source: https://mokxi.com/teachers/plans/python-text-adventures
Updated: 2026-11-19

Lesson plan

# Python games in the terminal lesson plan

Build a text adventure on a derelict space station, one real game system at a time: branching stories, dice, state, saves, a map of rooms, enemies with rules, and a boss crawler with alarms on the Pi.

4 chapters, 7 lessons, about 5 hours, on the Raspberry Pi 4 Model B. Every lesson runs in the browser, with nothing to install.

Start a class from this course

The unit

## Objectives and materials

### By the end, students can

- Read the player, branch the story, and let dice decide.
- Keep the game in a dict, then save it to a file and load it back.
- Make the station data, then fill it with enemies that follow rules.
- Every system in one game: the Tycho-9 station crawler.

### Materials for the whole unit

- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 1 h 30 min

## Stories and chance

Read the player, branch the story, and let dice decide.

Lesson | Time | What students do

A story that branches Start a text adventure on a derelict space station: read the player's answer with input(), clean it so " NORTH " still works, branch with if, elif and else, nest choices into a story tree, loop until the answer makes sense, and light a red alarm. | 45 min

- Run it: wake up on Tycho-9
- Players type sloppily
- Three ways forward
- A story is a tree
- Ask until it makes sense
- A real alarm

Random and dice Let chance into the game: random.randint for dice, a seed that makes the same rolls every run, a roll() function for 2d6 skill checks, the odds counted out of 36 and then measured over 3600 rolls, random.choice for loot, and a yellow light for a critical success. | 45 min

- Run it: roll a die
- A seed makes it repeatable
- A skill check: 2d6
- What are the odds?
- Loot
- Critical success

### Materials

- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2

### Check for understanding

Each student finishes "Random and dice" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Critical success".

Chapter 2. About 1 h 20 min

## State that lasts

Keep the game in a dict, then save it to a file and load it back.

Lesson | Time | What students do

Game state in a dict Keep everything the game knows in one dict: a status line built from it, functions that change it, an inventory list inside it, a command loop that drives it, an oxygen alarm on the red LED, and a game over when the air runs out. | 45 min

- Run it: the player as a dict
- Functions that change state
- An inventory
- Commands drive the state
- An oxygen alarm
- Game over

Save and load Turn the game state into text with json, write it to a file and read it back, handle the first run when there is no save yet, add save and load commands that work as a time machine, and autosave every third turn with the % operator. | 35 min

- Run it: state as text
- Write it, read it back
- The first run has no save
- A time machine
- Autosave

### Materials

- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2

### Check for understanding

Each student finishes "Save and load" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Autosave".

Chapter 3. About 1 h 30 min

## A world to explore

Make the station data, then fill it with enemies that follow rules.

Lesson | Time | What students do

A map of rooms Stop writing the story as nested ifs and make the station data: a dict of rooms, each with a description and a dict of exits. Describe a room with sorted exits, walk between rooms in a loop, add a room without touching the code, lock a door behind a keycard, and count the rooms explored with a set. | 45 min

- Run it: the station as data
- Describe any room
- Walk around
- Add a room, not code
- A locked door
- Rooms explored

Enemies with simple rules Put things in the dark that fight back: an enemy as a dict, a fight loop that takes turns, a coward that flees when hurt, a table of enemies whose behavior comes from a rule name, a fight where you choose each move, and a red danger light when your hp gets low. | 45 min

- Run it: one hit
- Take turns
- A rule: cowards run
- A table of enemies
- Your move
- A danger light

### Materials

- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2

### Check for understanding

Each student finishes "Enemies with simple rules" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "A danger light".

Chapter 4. About 45 min

## Boss

Every system in one game: the Tycho-9 station crawler.

Lesson | Time | What students do

Boss: a station crawler The finale: one game with everything. A map of six rooms, guards that fight by their rules, oxygen that runs down with a red alarm, a keycard door and a fuse that restarts the reactor and lights the yellow LED, and a save that stores the whole world, not just the player. | 45 min

- Run it: the skeleton
- Guards
- Air and alarms
- Restart the reactor
- Save the world
- Make it yours

### Materials

- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2

### Check for understanding

Each student finishes "Boss: a station crawler" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Make it yours".

Your class

## Teach this unit as a class

Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.

Start a class from this course See the demo class

More units

## Other lesson plans

Electronics basics 20 lessons, about 10 h. Embedded on the Arduino Uno 16 lessons, about 12 h. Embedded on the ESP32-C3 13 lessons, about 11 h. Embedded on the Raspberry Pi Pico 7 lessons, about 6 h. Build your own fight stick 5 lessons, about 4 h. Embedded on the STM32F411 6 lessons, about 6 h. C++ on a board 13 lessons, about 10 h. Digital logic and memory 4 lessons, about 4 h. Interactive devices on the Uno 9 lessons, about 8 h. From gates to a computer 23 lessons, about 16 h. Build a claw machine 8 lessons, about 6 h. Every unit All the courses as ready-made units, on the teachers page.
