Every project / Games

🏰 Castle Escape

A text adventure: explore the castle, find the crown, and get out. Type commands to play.

Castle Escape running
Language
Python
Level
Beginner
Category
Games
▶ Try it & remix

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).

SettingStarts atFileWhat it does
START"hall"world.pythe room you begin in

Files

FileLines
main.py91where the program starts
world.py40The 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.

  1. Add a new room to world.py and connect it to the map.
  2. Add a "drop" command to leave items behind.
  3. Count the player's moves and show them when they win.
  4. Add a monster that blocks a room until you find a sword.
  5. Save the game: write the current room and inventory to a file.