I'm working on a school work to create a simple text-based dungeon game. In this game, a player goes from one room to another room. Each room may have an item to be taken. Commands used are like: go south, go north, take sword, drop sword, look (to get the description of current room), etc.
To implement this in C++, I've come across some ideas and therefore I've created some classes. They are:
- Item class - item has a name, weight, and value.
- Room class - a room has a name, description, and treasure (Item-data type)
- Action class - action class captures the command typed by the user. This will store each word typed (max. 5 words as command). Usually only the first 2 words will be taken as command (e.g. go west, take box)
- Player class - this class will organize the flow of the game. It has a function play() that will be called from main function to start the game. A player contains a currentRoom and actions (Action-data type)
In the main function, I create the objects needed for the game, such as the items and the rooms by hardcoding the name and description for each room and item. Each item will be put into a Room. So I will have an array of rooms. I will pass this array of rooms into the play() function.
Well, now I'm kinda confused about the idea. First, what would an Action class exactly do? If it captures the command typed by user, then how am I going to connect the command to particular action? Does it have to be hardcoded in someway, such as: if command == "go" then do this, etc ?
Secondly, I don't have any idea on how I am going to interconnect all the rooms into a map. The player should go from the starting point. Let's say, it goes north. Then when player goes south, he will come back to previous room. Each room should be connected to other rooms and there may be some direction that cannot be taken, e.g. from room A you can only go east, going west is not allowed.
Can I have some solutions or suggestions to my problems? Thanks in advance.