Pebellslearn by building
0%
RoadmapMatrixCatalogSandboxSign in
Fundamental's Follow up Projects  ›  Capstone Project

Project 4 — Text Adventure

Capstone Project 40 minA command-driven state machine: parse, move, collect
Your task
Build play(commands): start at [0,0] on a 5x5 grid, empty inventory. "go <dir>" moves (clamped), "take <item>" picks it up (no duplicates). Return {"position": [x, y], "inventory": [...]}.

Project 4 — Text Adventure

The classic first game — and a great state machine. Parse typed commands, walk a grid, and collect items, updating the world one turn at a time.

Build the four steps, then assemble play(commands) — a reducer that folds a list of commands into a final {"position", "inventory"}.

  • Step 1 — parse_command: text → normalised words.
  • Step 2 — move: walk the grid, clamped to the edges.
  • Step 3 — take: pick up an item (no duplicates).
  • Step 4 — describe: render a room to a sentence.

Skills: string parsing, conditionals/dispatch, clamping, lists + membership, f-strings — a real loop-over-input program.

Practice — level up

0/4 solved

Solve each in its own editor — Run to try, Check to grade. Stuck? Reveal a Hint, or the full Solution + walkthrough.

BuildStep 1 — Parse a command

Write parse_command(text) returning the lowercased words as a list. "Go North"["go", "north"], " "[].

string-methods
BuildStep 2 — Move on the grid

Write move(position, direction, grid_size). position is [x, y]. north y+1, south y-1, east x+1, west x-1, each clamped to 0 .. grid_size-1. Return the new [x, y].

conditionalsclamp
BossStep 3 — Pick up an item

Write take(inventory, item) returning a new inventory with item added — but never a duplicate. Order preserved.

listmembership
BossStep 4 — Describe a room

A room is {"name", "exits": [...], "items": [...]}. Write describe(room)"You are in the <name>. Exits: <a, b>. Items: <x>". Empty exits/items show none.

f-stringsjoinconditionals
play.py
Call the function you wrote — just like your app's frontend would. Edit the inputs and hit Call.
play(commands) → dictA command-driven state machine: parse, move, collect
try:
returned
No app map for this section yet.
Press Run to execute your code.
Press Check to run the tests for this lesson.