Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,185 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,389 people online right now. Registration is fast and FREE... Join Now!




Need help with simple C++ text game

 
Reply to this topicStart new topic

Need help with simple C++ text game

C++ Programmer
9 Jul, 2008 - 06:59 PM
Post #1

New D.I.C Head
*

Joined: 12 Jun, 2008
Posts: 29


My Contributions
Can someone make it so that instead of typing in 1 and 2 that they actually type in the answer like yes or no? here is the code.

CODE
#include<iostream>
using namespace std;

int main(void)
{
    beginning:
    system("TITLE The Amazing Adventure");
    double dfirstquestion;
    double dsecondquestion;
    double dthirdquestion;
    double dfourthquestion;
    double dfifthquestion;
    double dsixthquestion;
    double dseventhquestion;
    cout << "You are about to embark on a very dangerous adventure." << endl;
    cout << "Would you like to go? (1 is for yes, 2 is for no)" << endl;
    cin >> dfirstquestion;
    if(dfirstquestion == 1){
        system("CLS");
        cout << "You sail to the king of the land to get the permission." << endl;
        system("PAUSE");
        goto question2;
    }else{
        system("CLS");
        cout << "That's too bad, we are going to have to kill you." << endl;
        system("PAUSE");
        goto exit;
    }
    exit:
    system("CLS");
    cout << "You get your head chopped off." << endl;
    system("PAUSE");
    return 0;
    question2:
    system("CLS");
    cout << "Congradulations, you got the permission." << endl;
    system("PAUSE");
    system("CLS");
    cout << "The king tells you to go to the hidden tunnel and find the lost golden treasure." << endl;
    system("PAUSE");
    system("CLS");
    cout << "Do you want to go now or wait for tommorow to come?" << endl;
    cout << "(1 is for wait, 2 is for go now)" << endl;
    cin >> dsecondquestion;
    if(dsecondquestion == 1){
        system("CLS");
        cout << "you wait for morning to arrive." << endl;
        system("PAUSE");
        system("CLS");
        cout << "You wake up bright and early and get going." << endl;
        system("PAUSE");
        goto question3;
    }else{
        system("CLS");
        cout << "You get going right then to get an early start." << endl;
        system("PAUSE");
        goto question3;
    }
    question3:
    system("CLS");
    cout << "You arrive at your destination, the island of no return." << endl;
    system("PAUSE");
    system("CLS");
    cout << "It was a very long trip, do you want to take a break and wait for morning?" << endl;
    cout<< "(1 is for wait, 2 is for go now)" << endl;
    cin >> dthirdquestion;
    if(dthirdquestion == 1){
        system("CLS");
        cout << "You find a very dry tree and go to sleep" << endl;
        system("PAUSE");
        system("CLS");
        cout << "You wake up to find that, oh no! Something has stolen some of your food while you were alseep." << endl;
        system("PAUSE");
        system("CLS");
        cout << "You continue even though you are low on food." << endl;
        system("PAUSE");
        goto question4;
    }else{
        system("CLS");
        cout << "You start walking toward the cave." << endl;
        system("PAUSE");
        goto question4;
    }
    question4:
    system("CLS");
    cout << "You find the cave, would you like to wait for morning?" << endl;
    cout << "(1 is for wait, 2 is for go now)" << endl;
    cin >> dfourthquestion;
    if(dfourthquestion == 1){
        system("CLS");
        cout << "You fall asleep by the torch, that should keep all the bugs away." << endl;
        system("PAUSE");
        system("CLS");
        cout << "You wake up, grab the torch, and get ready to go into the cave." << endl;
        system("PAUSE");
        goto question5;
    }else{
        system("CLS");
        cout << "You grab the torch and get ready to go into the cave." << endl;
        system("PAUSE");
        goto question5;
    }
    question5:
    system("CLS");
    cout << "You see some bats ahead, do you want to abandon the quest or fight your fear?" << endl;
    cout << "(1 is for go home, 2 is for fight your fear)" << endl;
    cin >> dfifthquestion;
    if(dfifthquestion == 1){
        system("CLS");
        cout << "I wonder if the king is going to be mad." << endl;
        system("PAUSE");
        goto badanswer;
    }else{
        system("CLS");
        cout << "Good, we will continue.  You are the bravest in the land." << endl;
        system("PAUSE");
        goto question6;
    }
    badanswer:
    system("CLS");
    cout << "You dare defy my orders becuase of bats!" << endl;
    cout << "Off with his head!" << endl;
    goto exit;
    question6:
    system("CLS");
    cout << "You brave the bats and then find the treasure." << endl;
    system("PAUSE");
    system("CLS");
    cout << "Do you want to grab it or do you think it is a trap?" << endl;
    cout << "(1 is for grab it, 2 is for you think it is a trap)" << endl;
    cin >> dsixthquestion;
    if(dsixthquestion == 1){
        system("CLS");
        cout << "You grab the treasure anxiously and get chopped in half." << endl;
        system("PAUSE");
        system("CLS");
        cout << "GAME OVER!" << endl;
        return 0;
    }else{
        system("CLS");
        cout << "You throw a stick at the treasure, knocking it over." << endl;
        system("PAUSE");
        system("CLS");
        cout << "A giant saw comes out and misses you." << endl;
        system("PAUSE");
        system("CLS");
        cout << "YAY!!! You got the treasure." << endl;
        system("PAUSE");
        goto question7;
    }
    question7:
    system("CLS");
    cout << "You sail back to the king and give him the treasure." << endl;
    cout << "He is very pleased with you and offers you money." << endl;
    system("PAUSE");
    system("CLS");
    cout << "Would you like to take the money?" << endl;
    cout << "(1 is for yes, 2 is for no)" << endl;
    cin >> dseventhquestion;
    if(dseventhquestion == 1){
        system("CLS");
        cout << "You are rich! Good job!" << endl;
        system("PAUSE");
        system("CLS");
        cout << "If you would like to go on another adventure, try out The Amazing Adventure 2." << endl;
        system("PAUSE");
        return 0;
    }else{
        system("CLS");
        cout << "You tell him no, and he thanks you." << endl;
        system("PAUSE");
        system("CLS");
        cout << "If you would like to go on another adventure, try out The Amazing Adventure 2." << endl;
        system("PAUSE");
        return 0;
    }
}


Thank You in advance
User is offlineProfile CardPM
+Quote Post

Jostol
RE: Need Help With Simple C++ Text Game
9 Jul, 2008 - 09:08 PM
Post #2

New D.I.C Head
*

Joined: 9 Jul, 2008
Posts: 9



Thanked: 1 times
My Contributions
CODE
#include <iostream>
#include <string>
using namespace std;

int main(void)
{
    beginning:
    system("TITLE The Amazing Adventure");
    string dfirstquestion;
    string dsecondquestion;
    string dthirdquestion;
    string dfourthquestion;
    string dfifthquestion;
    string dsixthquestion;
    string dseventhquestion;
    
    //QUESTION #1
    cout << "You are about to embark on a very dangerous adventure." << endl;
    cout << "Would you like to go? (Yes or No)" << endl;
    cin >> dfirstquestion;
    
    if(dfirstquestion == "Yes" || dfirstquestion == "yes" || dfirstquestion == "YES"){
        system("CLS");
        cout << "You sail to the king of the land to get the permission." << endl;
        system("PAUSE");
        goto question2;
    }else{
        system("CLS");
        cout << "That's too bad, we are going to have to kill you." << endl;
        system("PAUSE");
        goto exit;
    }
    exit:
    system("CLS");
    cout << "You get your head chopped off." << endl;
    system("PAUSE");
    return 0;
    
    //QUESTION #2
    question2:
    system("CLS");
    cout << "Congradulations, you got the permission." << endl;
    system("PAUSE");
    system("CLS");
    cout << "The king tells you to go to the hidden tunnel and find the lost golden treasure." << endl;
    system("PAUSE");
    system("CLS");
    cout << "Do you want to go now or wait for tommorow to come?" << endl;
    cout << "(Wait or Go)" << endl;
    cin >> dsecondquestion;
    
    if(dsecondquestion == "Wait" || dsecondquestion == "wait" || dsecondquestion == "WAIT"){
        system("CLS");
        cout << "You wait for morning to arrive." << endl;
        system("PAUSE");
        system("CLS");
        cout << "You wake up bright and early and get going." << endl;
        system("PAUSE");
        goto question3;
    }else{
        system("CLS");
        cout << "You get going right then to get an early start." << endl;
        system("PAUSE");
        goto question3;
    }
    
    //QUESTION #3
    question3:
    system("CLS");
    cout << "You arrive at your destination, the island of no return." << endl;
    system("PAUSE");
    system("CLS");
    cout << "It was a very long trip, do you want to take a break and wait for morning?" << endl;
    cout<< "(Wait or Go)" << endl;
    cin >> dthirdquestion;
    
    if(dthirdquestion == "Wait" || dthirdquestion == "wait" || dthirdquestion == "WAIT"){
        system("CLS");
        cout << "You find a very dry tree and go to sleep" << endl;
        system("PAUSE");
        system("CLS");
        cout << "You wake up to find that, oh no! Something has stolen some of your food while you were alseep." << endl;
        system("PAUSE");
        system("CLS");
        cout << "You continue even though you are low on food." << endl;
        system("PAUSE");
        goto question4;
    }else{
        system("CLS");
        cout << "You start walking toward the cave." << endl;
        system("PAUSE");
        goto question4;
    }
    
    //QUESTION #4
    question4:
    system("CLS");
    cout << "You find the cave, would you like to wait for morning?" << endl;
    cout << "(Wait or Go)" << endl;
    cin >> dfourthquestion;
    
    if(dfourthquestion == "Wait" || dfourthquestion == "wait" || dfourthquestion == "WAIT"){
        system("CLS");
        cout << "You fall asleep by the torch, that should keep all the bugs away." << endl;
        system("PAUSE");
        system("CLS");
        cout << "You wake up, grab the torch, and get ready to go into the cave." << endl;
        system("PAUSE");
        goto question5;
    }else{
        system("CLS");
        cout << "You grab the torch and get ready to go into the cave." << endl;
        system("PAUSE");
        goto question5;
    }
    
    //QUESTION #5
    question5:
    system("CLS");
    cout << "You see some bats ahead, do you want to abandon the quest or fight your fear??" << endl;
    cout << "(Flee or Fight)" << endl;
    cin >> dfifthquestion;
    
    if(dfifthquestion == "Flee" || dfifthquestion == "flee" || dfifthquestion == "FLEE"){
        system("CLS");
        cout << "I wonder if the king is going to be mad." << endl;
        system("PAUSE");
        goto badanswer;
    }else{
        system("CLS");
        cout << "Good, we will continue.  You are the bravest in the land." << endl;
        system("PAUSE");
        goto question6;
    }
    badanswer:
    system("CLS");
    cout << "You dare defy my orders becuase of bats!" << endl;
    cout << "Off with his head!" << endl;
    goto exit;
    
    //QUESTION #6
    question6:
    system("CLS");
    cout << "You brave the bats and then find the treasure." << endl;
    system("PAUSE");
    system("CLS");
    cout << "Do you want to grab it or do you think it is a trap?" << endl;
    cout << "(Grab or Think)" << endl;
    cin >> dsixthquestion;
    
    if(dsixthquestion == "Grab" || dsixthquestion == "grab" || dsixthquestion == "GRAB"){
        system("CLS");
        cout << "You grab the treasure anxiously and get chopped in half." << endl;
        system("PAUSE");
        system("CLS");
        cout << "GAME OVER!" << endl;
        return 0;
    }else{
        system("CLS");
        cout << "You throw a stick at the treasure, knocking it over." << endl;
        system("PAUSE");
        system("CLS");
        cout << "A giant saw comes out and misses you." << endl;
        system("PAUSE");
        system("CLS");
        cout << "YAY!!! You got the treasure." << endl;
        system("PAUSE");
        goto question7;
    }
    
    //QUESTION #7
    question7:
    system("CLS");
    cout << "You sail back to the king and give him the treasure." << endl;
    cout << "He is very pleased with you and offers you money." << endl;
    system("PAUSE");
    system("CLS");
    cout << "Would you like to take the money?" << endl;
    cout << "(Yes or No)" << endl;
    cin >> dseventhquestion;
    
    if(dseventhquestion == "Yes" || dseventhquestion == "yes" || dseventhquestion == "YES"){
        system("CLS");
        cout << "You are rich! Good job!" << endl;
        system("PAUSE");
        system("CLS");
        cout << "If you would like to go on another adventure, try out The Amazing Adventure 2." << endl;
        system("PAUSE");
        return 0;
    }else{
        system("CLS");
        cout << "You tell him no, and he thanks you." << endl;
        system("PAUSE");
        system("CLS");
        cout << "If you would like to go on another adventure, try out The Amazing Adventure 2." << endl;
        system("PAUSE");
        return 0;
    }
}


You might want to make it so you have to type in one or the other option. Right now the program only checks for one answer so you can type in something random and the program will take the else path.

Hope that helps smile.gif
User is offlineProfile CardPM
+Quote Post

C++ Programmer
RE: Need Help With Simple C++ Text Game
10 Jul, 2008 - 08:08 AM
Post #3

New D.I.C Head
*

Joined: 12 Jun, 2008
Posts: 29


My Contributions
Thank You, i'm kinda new and i didnt know how to do that. thank you again
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 11:27AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month