C
Caleb
I've just learned the basics of C++, and as my first real project I am
attempting to construct a text adventure, like back in the good old
days of Commodore 64 BASIC. This is my code so far:
#include <iostream>
#include <string>
using namespace std;
struct room {
int number;
int numofexits;
int special;
string description;
room (int a, int b, int c, string d);
};
room::room (int a, int b, int c, string d) {
number=a;
numofexits=b;
special=c;
description=d;
}
room Foyer(1,3,0,"You are in the foyer of the cathedral.\nIt's hard to
believe you've just entered for any purpose other than worship
or\nsacrifice.\n");
room* allrooms[50]={&Foyer};
int location=0;
int main () {
cout << "****************\n";
cout << "** The Depths **\n";
cout << "****************\n\n\n";
cout << allrooms[location]->description;
}
Pretty straightforward, I think. My problem is this: Each room is
going to have a number of exits (defined by "numofexits"). Obviously,
those exits will lead to different rooms based on which room you are
standing in. I've tried to make a dynamic array with different sizes
for different objects of the "room" class, but that didn't work out.
What would be the best way to do this? Sorry if I've been confusing in
any way; just point it out and I'll clarify. Thanks in advance for any
help.
attempting to construct a text adventure, like back in the good old
days of Commodore 64 BASIC. This is my code so far:
#include <iostream>
#include <string>
using namespace std;
struct room {
int number;
int numofexits;
int special;
string description;
room (int a, int b, int c, string d);
};
room::room (int a, int b, int c, string d) {
number=a;
numofexits=b;
special=c;
description=d;
}
room Foyer(1,3,0,"You are in the foyer of the cathedral.\nIt's hard to
believe you've just entered for any purpose other than worship
or\nsacrifice.\n");
room* allrooms[50]={&Foyer};
int location=0;
int main () {
cout << "****************\n";
cout << "** The Depths **\n";
cout << "****************\n\n\n";
cout << allrooms[location]->description;
}
Pretty straightforward, I think. My problem is this: Each room is
going to have a number of exits (defined by "numofexits"). Obviously,
those exits will lead to different rooms based on which room you are
standing in. I've tried to make a dynamic array with different sizes
for different objects of the "room" class, but that didn't work out.
What would be the best way to do this? Sorry if I've been confusing in
any way; just point it out and I'll clarify. Thanks in advance for any
help.