I would try something simpler to begin with, just to test how things are working. I would keep the Rooms class, and I would rewrite the main function.
1. Implement the constructor for the Rooms class. You need to set the name, and set all neighbors to NULL. Finish implementing all functions in that class.
2. Write a member function for rooms, to give you the name. That way, when you move to a room, it will tell you where you are.
3. Write a function, with two arguments: a Rooms pointer, and a direction, that returns a Rooms pointer, and call it say Move
Rooms* Move(Rooms*current, int direction)
You need to get the pointer to the next room. So you use a switch, like you have in main, and you assign the next room to be the output of current->GetNorth().
1 2 3 4 5 6 7 8 9
|
Rooms *next;
switch(direction)
{
case 1:
next=current->GetNorth();
break
....//other cases
}
|
Then you need to check if there is a room like that
1 2 3 4 5 6 7 8 9 10
|
if(next==NULL)
{
cout<<"cannot go in that direction"<<endl;
return current; //You do not go to a next room if one does not exists.
}
else
{
cout<<"I can move to room "<<next->getName()<<endl;
return next;
}
|
4. Set up your rooms in the main function, similar to what you have currently in Map
5. Try to traverse a few rooms:
1 2 3 4 5
|
cout<<"I am in room "<<pNewRoom->getName()<<endl;
Rooms * next;
next=Move(pNewRoom, 1);//move north
next=Move(next, 2);
...
|
Here is also a very important point: whenever you have pointers, make sure you delete them. Otherwise your program will leak memory