Hey everyone. I've got this project I am doing for class and have run into an issue. I'm trying to make my own, relatively basic text adventure.
As of right now I have the body of the game set up simply just giving the user some choices to make.
You run through the forest when before you know it you come face to face with a bear.
You:
1. Sneak around the bear
2. Play dead
3. Karate chop the bear and he kills you
and each choice obviously has a different outcome, at least that's the plan.
One main issue I've run into is how can I slowly delve each choice made into a slightly different outcome?
For instance if I choose any of the options above "1, 2 or 3" the next part of the story would be read the same exact way. If I choose "1" the outcome can be "You Win". If I choose "3" the outcome will still be "You Win".
I apologize if it's still a bit foggy to understand what I'm attempting to explain. I'd like story branching in my basic text adventure and am unsure of how to go about doing so.
Here's what I have so far so you can see.
- Code:
-
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout <<"\tWelcome to my text based game!\n";
char userName[100];
cout <<"\nPlease enter your character name: ";
cin >>userName;
cout <<"Hello, "<<userName<<"!\n\n";
cout <<"Please pick your race: \n";
cout <<"1 - Human\n";
cout <<"2 - Orc\n";
cout <<"3 - Elf\n";
int pickRace;
cout <<"Pick your race: ";
cin >>pickRace;
switch (pickRace)
{
case 1:
cout <<"\nYou picked the Human race.\n";
break;
case 2:
cout <<"\nYou picked the Orc race.\n";
break;
case 3:
cout <<"\nYou picked the Elf race.\n";
break;
default:
cout <<"Error - Invalid input; only 1, 2 or 3 allowed.\n";
}
int pickClass;
cout <<"\nPick your class: \n";
cout <<"1 - Wizard\n";
cout <<"2 - Warrior\n";
cout <<"3 - Assassin\n";
cout <<"Pick your class: ";
cin >> pickClass;
switch (pickClass)
{
case 1:
cout <<"\nYou chose to be a Wizard.\n\n";
break;
case 2:
cout <<"\nYou chose to be a Warrior.\n\n";
break;
case 3:
cout <<"\nYou chose to be a Assassin.\n\n";
break;
default:
cout <<"Error - Invalid input; only 1, 2 or 3 allowed.\n";
}
{
cout<<"You awake from a deep sleep and slowly become aware of your surroundings. "<<endl;
cout<<"You try to move your arms and legs, but it's useless as you realize you've been chained to a wall inside what appears to be a dungeon. "<<endl;
cout<<"Everything is dark, until you see a distant light source slowly getting bigger \n and bigger as it comes towards you."<<endl;
cout<<"You begin to panic, but regain your composure and:\n"<<endl;
cout<<"1. You close your eyes and focus your mind as you transform into a rat."<<endl;
cout<<"2. You try using brute strength to bust loose."<<endl;
cout<<"3. You're intrigued by the light and patiently wait until it reaches you.\n"<<endl;
string answer;
cout << "Selection: ";
cin >> answer;
if (answer == "1")
{
cout<<"\nYou carefully scamper away unharmed, avoiding the light source as you find the \nentrance and escape"<<endl;
}
else
{
if (answer == "2")
{
cout<<"\nYou've managed to break free, but you're exhausted and the light source is \ncoming at you even faster now"<<endl;
}
else
{
if (answer == "3")
{
cout<<"\nYou notice a rather large figure covered in a black robe carrying a sconce \napproaching you. "<<endl;
cout<<"The unworldly creature lets out a maniacle laugh as it lifts a necklace over \nyour head and places it around your neck. "<<endl;
cout<<"The creature vanishes into thin air. The necklace immediately begins to glow, \nand you feel empowered as the chains become loose. "<<endl;
cin.get();
cin.ignore();
}
else
{
cout<<"That wasn't a choice."<<endl;
}