A map in C++ has a different meaning from a map use for navigation. I suppose I should have used a different name. Here is a more fleshed out idea.
Code:
#include <string>
#include <iostream>
using namespace std;
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
struct PlaceMapElement
{
char* roomName;
char* description;
int northIndex;
int southIndex;
int eastIndex;
int westIndex;
};
PlaceMapElement placeMap[] = {
/* n s e w */
{ "Grue room", "You are in a dark room.",
-1, 1, -1, -1},
{ "Kitchen", "You are in a bright room.",
0, -1, -1, -1},
};
class Place
{
public:
Place()
{
}
void Initialize(const PlaceMapElement& pme)
{
roomName = pme.roomName;
description = pme.description;
northIndex = pme.northIndex;
southIndex = pme.southIndex;
eastIndex = pme.eastIndex;
westIndex = pme.westIndex;
}
void Describe()
{
cout << "You are in " << roomName << endl;
cout << description << endl;
if (northIndex >= 0) cout << "You can go North";
if (southIndex >= 0) cout << "You can go South";
if (eastIndex >= 0) cout << "You can go East";
if (westIndex >= 0) cout << "You can go West";
}
private:
std::string roomName;
std::string description;
int northIndex;
int southIndex;
int eastIndex;
int westIndex;
};
Place* places;
void initializePlaces()
{
places = new Place[ARRAY_SIZE(placeMap)];
for(int ix = 0; ix < ARRAY_SIZE(placeMap); ++ix)
{
places[ix].Initialize(placeMap[ix]);
}
}
int main(void)
{
initializePlaces();
return 0;
}