A text adventure
The problem
Build a small game in which the player moves between rooms, picks up items and has to solve a simple goal, all through typed commands.
Requirements
- Rooms are stored as data, with descriptions, exits and items
- Commands include go, take, look and inventory
- A Player class holds the current room and the items carried
- Unknown commands and impossible moves give a helpful reply
- The game can be won, and it says so when that happens
- A new room can be added by changing only the data
Technologies
- Python
- Classes
- Dictionaries
- Text processing
- Exceptions
Step by step
- Draw a map of four or five rooms on paper.
- Write the rooms as a dictionary, from room name to its details.
- Write a Player class with methods for moving and taking items.
- Write a function that splits a typed line into a verb and a noun.
- Use a dictionary from verbs to functions to handle each command.
- Add the winning condition, and check it after each command.
- Test every exit, and try impossible commands on purpose.
Expected result
A complete small game that a friend can play, in which the world is described by data rather than by code.
How it is evaluated
- Every exit leads where the data says it should
- The game can be completed
- Bad input never crashes the game
- Adding a room needs no change to the code
Ways to improve it
- Add locked doors that need a key
- Add a save and load feature using json
- Add a score based on the number of moves