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.

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.

LessonTimeWhat students do
A story that branchesStart 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
  1. Run it: wake up on Tycho-9
  2. Players type sloppily
  3. Three ways forward
  4. A story is a tree
  5. Ask until it makes sense
  6. A real alarm
Random and diceLet 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
  1. Run it: roll a die
  2. A seed makes it repeatable
  3. A skill check: 2d6
  4. What are the odds?
  5. Loot
  6. 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.

LessonTimeWhat students do
Game state in a dictKeep 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
  1. Run it: the player as a dict
  2. Functions that change state
  3. An inventory
  4. Commands drive the state
  5. An oxygen alarm
  6. Game over
Save and loadTurn 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
  1. Run it: state as text
  2. Write it, read it back
  3. The first run has no save
  4. A time machine
  5. 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.

LessonTimeWhat students do
A map of roomsStop 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
  1. Run it: the station as data
  2. Describe any room
  3. Walk around
  4. Add a room, not code
  5. A locked door
  6. Rooms explored
Enemies with simple rulesPut 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
  1. Run it: one hit
  2. Take turns
  3. A rule: cowards run
  4. A table of enemies
  5. Your move
  6. 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.

LessonTimeWhat students do
Boss: a station crawlerThe 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
  1. Run it: the skeleton
  2. Guards
  3. Air and alarms
  4. Restart the reactor
  5. Save the world
  6. 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.