Every project / Games
🏰 Castle Escape
A text adventure: explore the castle, find the crown, and get out. Type commands to play.
- Language
- Python
- Level
- Beginner
- Category
- Games
What you'll learn
- input() and loops
- Dictionaries
- Lists
- if / elif
- Splitting code across files
How it works
- The castle lives in world.py as a dictionary of rooms, each with its exits and maybe an item.
- A loop reads your command with input(), splits it into words, and acts on the first one.
- The cellar is dark: without the lantern you can't see or pick up anything there.
- The gate needs the key, and you win by walking out with the crown.
Knobs to turn
These settings are near the top of the code. Remix it, change one, and watch what happens. The preview updates as you type (press ▶ Run for Python).
| Setting | Starts at | File | What it does |
|---|---|---|---|
START | "hall" | world.py | the room you begin in |
Files
| File | Lines | |
|---|---|---|
main.py | 91 | where the program starts |
world.py | 40 | The castle map. Each room has a name, a description, exits (direction -> room), |
Challenges
Each one is a bit harder than the last. Teachers: these make good assignment instructions.
- Add a new room to world.py and connect it to the map.
- Add a "drop" command to leave items behind.
- Count the player's moves and show them when they win.
- Add a monster that blocks a room until you find a sword.
- Save the game: write the current room and inventory to a file.