Objective
An adventure game is represented with data: a dictionary of rooms with their exits and another with the objects of each room. The main loop only interprets commands and consults that data.
Instructions
- The map is fixed:
hall(hall): north →library, east →kitchen.library: south → hall, containskey.kitchen: west → hall, east →garden.garden: west → kitchen, containstreasure. You start in the hall. - The first line has the number
nof commands:look,go direction(north,south,eastorwest),take itemorinventory. To enter the garden you must carry the key. Taking the treasure ends the game withYou won!. - Messages:
You are in: room,Items: a, b,Exits: a, b,You go to: room,Taken: item,You cannot go that way,The garden door is locked,There is no item here,Backpack: a, b. In the room line, rooms arehall,library,kitchenandgarden; when there is nothing, shownoneorempty.
6
look
go north
take key
go south
go east
go east
You are in: hall
Items: none
Exits: east, north
You go to: library
Taken: key
You go to: hall
You go to: kitchen
You go to: garden
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise