🛠
Practice Projects · ★★★
OOP · State machine · JSON maps · Parser
Project 12 — Text Adventure Game
Build a text adventure game with rooms, items, NPCs, and a simple command parser. Load the world map from a JSON file.
OOPgameparserstate machineJSON
Duration
⏱ 3 hours
Level
📊 Intermediate-Advanced Applied
Prerequisite
🎯 Intermediate Weeks 7–8
OUTCOME
A playable text adventure game loaded from a JSON world file
What you'll learn
- 1Model the game world as a graph of Room objects
- 2Implement Player state (inventory, health, location)
- 3Parse two-word commands: go north, take sword, use key
- 4Load the entire world map from world.json
Commands
- go <north|south|east|west> — move between rooms
- look — describe current room
- take <item> / drop <item>
- use <item> [on <target>]
- inventory — show carried items
- talk <npc> — NPC dialogue
- save / load — save and restore game state
Sample Session
text
You are in a dark dungeon entrance.
Exits: north, east
Items: torch, rusty key
> take torch
You pick up the torch.
> go north
You enter a locked iron door room.
The door is locked.
> use rusty key on door
The door opens with a creak!
> go north
You enter the treasure room. You win!📝 Exercises
Try them yourself first, then open the solution to compare.
Exercise 1
Build the text adventure
Goal: Implement a playable 5-room adventure with items and a win condition.
Requirements
- 5+ rooms with connections
- 3+ items with use actions
- JSON world file
- Save/load game state
Example code / lecture materials
All lecture materials and example code are openly available on GitHub.
View on GitHub ↗