Capstone: Tiny Text Adventure
Lesson 5 of 5 · View course roadmap
Learn the idea
Time to ship a game. Every text adventure — from 1977's Zork to modern interactive fiction — is built on one idea: the world is a dictionary.
- Keys are room names:
"hall","library","vault" - Values are what the player sees there
- The player's journey is just a list of keys to visit
Walk the path with a loop, look each room up with rooms[name], and narrate. That's the whole engine. Want more rooms, items, or monsters? Add keys. The data grows; the code stays the same — that separation of data from logic is one of the biggest ideas in software, and you're about to use it.
Where you'll use this
Data-driven design — world as data, engine as code — is how real games ship: level editors write data files, the engine stays unchanged. It's also how CMSs, chatbots and workflow tools scale content without new code.
Common mistakes
- A typo between a path entry and a room key → KeyError. Keys must match exactly, including case.
- Putting story text in the loop instead of the dict — then every new room needs new code, defeating the design.
- Printing the final message inside the loop (indented) so it repeats after every room.
Pro tip
Give each room a dict of exits — "hall": {"desc": ..., "exits": {"north": "library"}} — and your walk can become a real free-roaming game with about ten more lines.
Try it yourself
The lesson example is loaded and ready — press Run, then change something and run it again. Breaking it is part of learning. Want a clean slate? Tap “New blank”.
Output appears here…
Pass the challenge +40 XP
Using the rooms and path in the starter, print You enter the {room}. followed by the room's description for each stop on the path — then print Quest complete! at the end.
You enter the hall. A dusty hall. Doors lead north and east. You enter the library. Shelves of ancient Python books. You enter the vault. The vault! Treasure: 100 XP. Quest complete!
for name in path: print the f-string, then print(rooms[name]). The final print goes after the loop (unindented).
rooms = {
"hall": "A dusty hall. Doors lead north and east.",
"library": "Shelves of ancient Python books.",
"vault": "The vault! Treasure: 100 XP.",
}
path = ["hall", "library", "vault"]
for name in path:
print(f"You enter the {name}.")
print(rooms[name])
print("Quest complete!")
Run your code to check it…
Check your understanding
Your notes (saved on this device)
Tip: use ← and → to move between lessons, ⌘K to search everything.