Making Choices RPG

Heya, guys. Once again, I'm in need of help. I've been thinking, and thinking, and thinking of a solution to this problem, and here it is:

I want to create a Text-Based RPG game that changes the story depending on the choices you make. The first conflict you have is with your cruel, unfair uncle.

I give the user four choices to choose from, and I have an idea of the consequences by each action. However, I don't know how I can play out the entire story if they choose an option.

Will I have to write several different stories because of each choice they make? If so, that's fine, but will I have to create several IF statements, and write the rest of the story in that IF statement?

Sorry if this is confusing, but let's say I decide to hit my Uncle with a scythe. The guards will come, and apprehend you, and you will be taken away. Then you have the choice of trying to escape, and so on, and so on.
Now, how will I do this with four or five different choices each time?

Thanks so much for any help.
Last edited on
Here's a minimalistic example of what you could do:
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
#include <iostream>

const char* story[] = {
   "Evil hamsters attack! What do you do?\na-run\tb-defend",
   "You've packed up your stuff. Where you you want to go?\na-south\tb-west",
   "The hamsters are almost here! What weapon do you want to use?\na-sword\tb-pistol",
   "The hamsters like warmth as much as you do. They follow you to the south and eat you.",
   "You live the rest of your life in a safe house by the sea.",
   "You slice through the hamsters and save the day!",
   "The hamsters are too small and too fast. You miss your every shot and get eaten"
};

int main() {
   char choice;
   std::cout << story[0] << '\n';
   for( int i = 0; i < 3; ) {
      do std::cin.get(choice).ignore();
      while( choice != 'a' && choice != 'b' );
      if( choice == 'a' ) i = i*2+1;
      else i = i*2+2;
      std::cout << story[i] << '\n';
   }
   std::cout << "The End!";
   std::cin.get();
   return 0;
}

Notice that my "story" array works like a binary tree. The idea is to have some sort of tree (unless you want to write ifs). When you write this yourself, you can have a tree with any number of choices. Also you could have your program read the story from a file, so that you don't have to recompile it every time you want to change something.
Not a constructive post, but I had to commend hamsterman on that story :P
hamsterman, I hate to be a pest, but could you possibly explain that code? I think it's great you're helping me out, but I think it'd be even more fantastic if I understood how that code worked.

Thanks so much. :)
Even though it doesn't look like one, "story" is a binary tree. See http://en.wikipedia.org/wiki/Binary_tree#Arrays . When you enter 'a' program goes to the left child of the current node and when you enter 'b', it goes to the right child.

Such tree is very restricted though (every question can only have two answers, all stories must be of the same length, you can't add any special events such as receiving an item or etc.)

How much experience do you have with programming? Would you be able to write a tree?
I haven't got much experience, but I can learn about it. I'll definitely check it out. Thanks so much! :)
Topic archived. No new replies allowed.