Well, here's a slightly fancier version, which actually links the areas. It may not be the best way to do things, but it's relatively simple:
Code:
#include <iostream.h>
#include <string.h>
enum dir
{
north = 1,
west = 2,
south = 3,
east = 4
};
class area
{
private:
char thedescription[20];
area *thenorth;
area *thewest;
area *thesouth;
area *theeast;
public:
area(char * description);
void link(area *n, area *w, area *s, area *e);
void describe() {cout << thedescription;};
void go(area **currentarea, dir direction);
};
area::area(char * description)
{
strcpy(thedescription, description);
}
void area::link(area *n, area *w, area *s, area *e)
{
thenorth = n;
thewest = w;
thesouth = s;
theeast = e;
}
void area::go(area **currentarea, dir direction)
{
if ((direction == north) && thenorth) *currentarea = thenorth;
if ((direction == west) && thewest) *currentarea = thewest;
if ((direction == south) && thesouth) *currentarea = thesouth;
if ((direction == east) && theeast) *currentarea = theeast;
}
int main(void)
{
area house("Your house.");
area pond("A pond.");
area river("A gentle river.");
area forest("A shady forest.");
area field("A grassy field.");
area mill("An old mill.");
house.link(&pond, &river, &forest, &field);
pond.link(0, 0, &house, 0);
river.link(0, 0, 0, &house);
forest.link(&house, 0, 0, 0);
field.link(0, &house, 0, &mill);
mill.link(0, &field, 0, 0);
area * currentarea;
char command[20];
currentarea = &house;
while (strcmp(command, "exit"))
{
currentarea->describe();
cout << endl << "Enter command: ";
scanf("%s", &command);
if (!strcmp(command, "north")) currentarea->go(¤tarea, north);
if (!strcmp(command, "west")) currentarea->go(¤tarea, west);
if (!strcmp(command, "south")) currentarea->go(¤tarea, south);
if (!strcmp(command, "east")) currentarea->go(¤tarea, east);
}
return 0;
}