Martijn wrote:...I want to be able to say for each map exits = north, west
so you can only leave the map to the north and west! Anyone got an idea how to do that?
I'm not going to pull any punches here :) Normally I don't post solutions, but I don't feel creative enough to make you think.
So, yes. Make a Room class and a Direction enum.
Code: Select all
enum Direction {
NORTH,
EAST,
SOUTH,
WEST,
NUM_DIRECTIONS
};
class Room {
/* ... */
int index;
Room* exits[NUM_DIRECTIONS]; //contains pointers to Rooms
int exitNums[NUM_DIRECTIONS]; //contains index #s of Rooms
/* ... */
};
In the constructor for Room, initialize all
exits to NULL and all
exitNums to -1. Load all the Rooms, leave the contents of
exits as NULL but store the
index of each exit to in the appropriate entry in
exitNums. Once all the Rooms are loaded, go through every Room and search for the
index of the Room that matches this Room's
exitNums entry that we were searching for, skipping any
exitNums entries that are -1. Assign
exits[appropriateDirection] to the Room we found that has the
index that matches
exitNums[appropriateDirection]. When outputting
exits, loop through Directions on
exits. If exits[appropriateDirection] == NULL, don't output the direction as a possible exit, and prohibit movement in that direction. If not NULL, set Player's
currentRoom to exits[appropriateDirection].
Obviously, I've done this before.