Hi, I am currently learning C++ and thought it would be a good idea to join a forum as you guys can probably explain things a lot better than a book can!
So straight to the point, I decided to make a simple linear text based game to practice all of the basic features I'm learning but cant seem to find a way around one mechanic.
My game involves simply rolling a random number, and that number relates to a certain game event/location, for example "you have been ambushed and lose 2 hp", some may give hp, but you continue to roll until you are dead.
I figured the best way to manage locations would be with a class for them, So i could give them a description and show if they had been visited already with simple code
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
class location
{
public:
bool searched;
string description;
};
int main()
{
location hospital;
hospital.searched = false;
hospital.description = (" a run down hospital \n");
}
|
Now the problem arises when I try to refer to a location randomly, I have tried creating a string called "currentlocation" and giving it the value "hospital" when its random number is called, but if i write
|
cout << currentlocation.description;
|
it will not work, it does not use the value of the string "hospital" as an identifier.
Is there any way to get around this?
PS. I apologise if I am missing something obvious but I have only been learning for a few months! thanks!