Projects · 15 / 19 Exercise Hard

Text adventure

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, contains key. kitchen: west → hall, east → garden. garden: west → kitchen, contains treasure. You start in the hall.
  • The first line has the number n of commands: look, go direction (north, south, east or west), take item or inventory. To enter the garden you must carry the key. Taking the treasure ends the game with You 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 are hall, library, kitchen and garden; when there is nothing, show none or empty.
Input
6
look
go north
take key
go south
go east
go east
Output
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