Easy A
Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

Share
 

 C++ Text Adventure assistance?

View previous topic View next topic Go down 
AuthorMessage
Yola
Member
Member
avatar

Posts : 12
Join date : 2011-03-09

C++ Text Adventure assistance? Empty
PostSubject: C++ Text Adventure assistance?   C++ Text Adventure assistance? EmptySun May 15, 2011 2:11 am

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;
}
Back to top Go down
Stronger
Member
Member
avatar

Posts : 17
Join date : 2011-03-09

C++ Text Adventure assistance? Empty
PostSubject: Re: C++ Text Adventure assistance?   C++ Text Adventure assistance? EmptySun May 15, 2011 2:12 am

Interesting how your description of the game has absolutely nothing to do with the code you posted. Why would that be?
Back to top Go down
Yola
Member
Member
avatar

Posts : 12
Join date : 2011-03-09

C++ Text Adventure assistance? Empty
PostSubject: Re: C++ Text Adventure assistance?   C++ Text Adventure assistance? EmptySun May 15, 2011 2:13 am

I wasn't originally going to include the code but figured it may worth it if anyone didn't understand what I was trying to say. Does it matter? The same idea is there in both examples.
Back to top Go down
CaptainCop
Member
Member
avatar

Posts : 14
Join date : 2011-03-09

C++ Text Adventure assistance? Empty
PostSubject: Re: C++ Text Adventure assistance?   C++ Text Adventure assistance? EmptySun May 15, 2011 2:19 am

You really should use elseif instead of new if statements inside of the else case.
e.g.
Code:

if (answer == "1")
{
cout<<"\nYou carefully scamper away unharmed, avoiding the light source as you find the \nentrance and escape"<<endl;

}
elseif (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;
}
elseif (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;
}

It is faster that way and a whole lot easier to follow.

Back to top Go down
Yola
Member
Member
avatar

Posts : 12
Join date : 2011-03-09

C++ Text Adventure assistance? Empty
PostSubject: Re: C++ Text Adventure assistance?   C++ Text Adventure assistance? EmptySun May 15, 2011 2:20 am

CaptainCop wrote:
You really should use elseif instead of new if statements inside of the else case.
e.g.
Code:

if (answer == "1")
{
cout<<"\nYou carefully scamper away unharmed, avoiding the light source as you find the \nentrance and escape"<<endl;

}
elseif (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;
}
elseif (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;
}

It is faster that way and a whole lot easier to follow.


I appreciate the tip.
Back to top Go down
Sponsored content




C++ Text Adventure assistance? Empty
PostSubject: Re: C++ Text Adventure assistance?   C++ Text Adventure assistance? Empty

Back to top Go down
 

C++ Text Adventure assistance?

View previous topic View next topic Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Easy A :: C++ Text Adventure assistance? Edit-trash Useless :: Trash-