Text Adventure - Building your world

Hi guys,

Is there a good way to build a map in C++ for a text based adventure? A room should obviously have some sort of unique identifier (probably an integer) and an identifier that links the room to its exits, but I'm not sure the best way to implement that.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Room
{
public:
	Room();
	~Room();
	
	string getRoomDescription();
	int getRoomNumber();
	int getNorthRoom();
	int getSouthRoom();
	int getEastRoom();
	int getWestRoom();

	void setRoomDescription(string &suppliedDescription);
	void setRoomNumber(int suppliedRoomNumber);
	void setNorthRoom(int suppliedRoomNumber);
	void setSouthRoom(int suppliedRoomNumber);
	void setEastRoom(int suppliedRoomNumber);
	void setWestRoom(int suppliedRoomNumber);

private:
	string roomDescription;

	int roomNumber;
	
	int northRoom;
	int southRoom;
	int eastRoom;
	int westRoom;
};


I was thinking I could just use unique room numbers as integers and "northRoom", "southRoom" . . . would hold the unique integers to the rooms that they exit to. If it held a -1 then there would be no exit there. But then I was also thinking you could use pointers. . . I just don't know the "right" way to do it. Any suggestions on how to implement an "Area" or small map in C++ for a text game?

Also, does anyone have any resources/books they could recommend to building text games??

Thanks!
Last edited on
You could learn about text only games by looking at how some of the more popular ones are implemented. Many of these games have their source code available (e.g. http://rephial.org/release/ and http://www.nethack.org/v343/download-src.html).

Although, I question why you are making text based games? They don't look as good as graphical ones and in the end are not particularly easier. =/
Topic archived. No new replies allowed.