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.
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.
Stories and chance
Read the player, branch the story, and let dice decide.
| Lesson | Time | What 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 |
|
| 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 |
|
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".
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 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 |
|
| 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 |
|
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".
A world to explore
Make the station data, then fill it with enemies that follow rules.
| Lesson | Time | What 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 |
|
| 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 |
|
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".
Boss
Every system in one game: the Tycho-9 station crawler.
| Lesson | Time | What 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 |
|
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".
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.