C++ Text based RPG

SO i though of doing a Text RPG with ascii art, and i had a few questions.

1: for getting commands (eg. go south) how can i get the input of "go" to tell the game that the user wants to go somewhere, then the direction? My thought was something like this:

if (input == "go" && "south" or "north" or "east" or "west"){
so on
}

Something else is how can i store both parts of input as different var, so I can use them later?
1
2
3
4
5
6
7
8
9
10
11
12
if (input == go)
{
    if (input2 == north)
    {
       ...
     }
    if (input2 == west)
    {
      ...
     }
     ...
}

I'd use a switch statement, but it's strings, sooooo, yea

2. Getline has some interesting properties for what you want. Search it up on google
Last edited on
thanks for getting back so quickly and yeah switch statements are going to be used alot!
just fyi, switch statements won't work with strings. you might be using if, else statements a lot.

EDIT: Maybe use a function?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

std::string  go(std::string input2)
{

if (input2 == north)
{
return ...
}

else
{
...
}

}


int main()
{
std::string input1;
std::string input2;

if (input1 == go)
{
   ... go(input2) ...
}

}


Hope this helps
Last edited on
You could also consider a while loop for your "go" since how I'd think of it is, you don't contemplate every step you take. You only think about something like an event, once you actually reach it.

It's like driving a car. In perfect conditions (and by that, I mean absolutely no traffic, just you and the beautiful road), you don't stop every time you step on the gas pedal. The only times you do stop or do something is when you meet up with an event, such as...a stop sign. Or a red light. Or deer running across the road. Maybe a cow is running straight at you. Stuff like that.

1
2
3
4
while ( input == "go" )
{
// input2, etc...
}
Last edited on
Remember to put a break; somewhere in the while loop, other wise it will never continue
Following @YFGHNG post. I would have a boolean that decides when the game is over.

1
2
3
4
5
6
7
8
9
10
bool continueGame = true;

while (continueGame)
{
...
if (...)
{
continueGame = false;
}
}
Topic archived. No new replies allowed.