writing 'goto' function for text-RPG

BACKGROUND and SYSTEM:
I am using DEV-C++ on Windows XP to create an old-styled text-RPG as a console application. I am soley self-studying from the "C++ All-In-One Desk Reference For Dummies."

PROBLEM:
I can't find any clear reference to searching an array, or a vector.
I want to determine if a string is present, and if so return the array location as an int.

PURPOSE:
I am trying to compare user input to a list of strings representing plausible exits from the player's "room" and then move to the corresponding location in a "matching" vector of classes. This process would later be placed in a function.

SAMPLE CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Room{
public:
    string PossibleExits[5]; //For string comparison
    Room *Exit[5]; //for room transfer
};

Room *YouAreHere;
string Action;

cout << "Go where?" << endl;
cin >> Action;

if (Action == PossibleExits[0]){
    YouAreHere = (*YouAreHere).Exit[0]
};
else if (Action == PossibleExits[1]){
    YouAreHere = (*YouAreHere).Exit[1]
};
else if (etc, etc, etc ...)


///This is roughly what it looks like now. I have to compare Action to each possible exit one at a time, so I have an if/else if for every potential exit, which feels sloppy.
Last edited on
What I would do is instead make a vector of rooms, and simply have an array of exits that have the room number. Then you can just set the players "current room #" to whatever room they are in, and then look in that room for the desc, etc.
That is a good idea, I may end up doing that, but I still think I'm gonna want to know how to search through array values.
Topic archived. No new replies allowed.