need help with text based game making choices

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 672 Views - Last Post: 15 January 2013 - 07:06 AM Rate Topic: -----

#1 ajrodelo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 14-January 13

need help with text based game making choices

Posted 14 January 2013 - 10:00 PM

i know this prob looks dumb but this is my first time trying this and im stuck i cant find anything online that could help me well my question is how do i keep adding choices in the game i can do one but then after that i cant figure out how to add another choice from one of the previous choices

#include <iostream>

using namespace std;

main(int argc, char *argv[])
{
         int choice;
     cout  << "WELCOME CRIMINALS\n\n";
     cout  << "Are u ready to comit some crimes and make some MULAH\n";
     cout  << "1. HELL YES\n";
     cout  << "2. Naw im cool\n";
     cout  << "Your Choice";
     cin   >> choice;
     
     
     if(choice == 1 ) {
     cout << "\n\n\n Were do u want to go to to rob \n\n"; 
     cout << "1. Wallmart \n";
     cout << "2. Big 5 \n";
     cout << "3. Target \n";
     }
               
     
     else {
     cout  << "\n\n\n FUCKING PUSSY!!";
     }          
     
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

thatnk you

This post has been edited by macosxnerd101: 14 January 2013 - 10:04 PM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: need help with text based game making choices

#2 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: need help with text based game making choices

Posted 14 January 2013 - 10:09 PM

Well, this could be the time for using switch control

Something like this.

1.Wallmart
2.Big
3.target
Enter choice
cin>> choice;

switch(choice)
{
    case 1: //code
    break;
    case 2: //code
    break;
    case 3: //code
    break;
    default: //code
}


regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#3 ajrodelo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 14-January 13

Re: need help with text based game making choices

Posted 14 January 2013 - 10:10 PM

what is a switch control
Was This Post Helpful? 0
  • +
  • -

#4 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1046
  • View blog
  • Posts: 4,449
  • Joined: 09-June 09

Re: need help with text based game making choices

Posted 14 January 2013 - 10:17 PM

The easiest way for someone that is beginning programming is to create a nested if structure.

i.e.
   if(choice == 1 ) {
      cout << "\n\n\n Were do u want to go to to rob \n\n"; 
      cout << "1. Wallmart \n";
      cout << "2. Big 5 \n";
      cout << "3. Target \n";

      cout << "What do you want to take? \n";
      std::cin>>choice; //get input again

      if(choice == /*whatever*/) {
         //do this
      }
      else if(choice == /* whatever */) {
         // do that
      }
   }


This post has been edited by jjl: 14 January 2013 - 10:18 PM

Was This Post Helpful? 0
  • +
  • -

#5 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: need help with text based game making choices

Posted 14 January 2013 - 10:19 PM

Ok...switch control is a control statement which will allow you to select conditions based on certain cases.

The syntax is as follows.

Enter option:
cin>>option;
switch(option)
{
    case 1://code
    break;

    case 2://code
    break;
    
    default://code
}


Say, you have something like this. Choosing a color from the rainbow.

1.Violet
2.Indigo
3.Blue
4.Green
5.Yellow
6.Orange
7.Red
Choose color:
cin>>choice;

switch(choice)
{

    case 1:cout<<"You chose violet";
    break;

    case 2:cout<<"You chose indigo";
    break;
 
    case 3:cout<<"You chose blue";
    break;
 
    case 4:cout<<"You chose green";
    break;

    case 5:cout<<"You chose yellow";
    break;

    case 6:cout<<"You chose orange";
    break;

    case 7:cout<<"You chose red";
    break;
  
    default:cout<<"please choose a valid option";
}


So, what the switch control does is according to your option chosen, it sends control to the cases and the statements in the case are executed.

Note:Always remember to use a break; in your switch statements.

regards,
Raghav

This post has been edited by raghav.naganathan: 14 January 2013 - 10:21 PM

Was This Post Helpful? 0
  • +
  • -

#6 ajrodelo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 14-January 13

Re: need help with text based game making choices

Posted 14 January 2013 - 10:49 PM

sitll cant figure this out this is what i got so far
   if(choice == 1 ) {
     cout << "\n\n\n Were do u want to go to to rob \n\n"; 
     cout << "1. Wallmart \n";
     cout << "2. Big 5 \n";
     cout << "3. Target \n";
     
     std :: cin>>choice;
     
     if(choice == 2) {
     cout << "\n\n\n How do u want to do this \n\n";
     cout << "1. wait for midnight and go hit up the store \n";
     cout << "2. go early and scope out the place \n";               
     
     }
     }
     if(choice == 1) {
     cout << "1. \n\n\n fg";
     
     }
     else {
     cout  << "\n\n\n FUCKING PUSSY!!";
     }          
     
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}


Was This Post Helpful? 0
  • +
  • -

#7 ajrodelo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 14-January 13

Re: need help with text based game making choices

Posted 14 January 2013 - 10:55 PM

dang i got this thing all jacked up now
Was This Post Helpful? 0
  • +
  • -

#8 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: need help with text based game making choices

Posted 14 January 2013 - 10:56 PM

Well, your code is pretty confusing.

You need to provide some variable for the user to input his choice in line 13...a 'cin' would do fine.

Next, since you want the condition to execute in the same if block, you should not close the braces on line 14 and 15.

Please update your code with the above changes and post it here. We can continue further from there.

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#9 ajrodelo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 14-January 13

Re: need help with text based game making choices

Posted 14 January 2013 - 11:02 PM

on 14 and 15 if i mess with those it gives me errors and should i just start over or something its pretty confusing for me too i dont really know what im doin here
Was This Post Helpful? 0
  • +
  • -

#10 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: need help with text based game making choices

Posted 14 January 2013 - 11:07 PM

exactly...it will give you errors...we shall clear it as we progress...can you please post the updated code here?

regards,
Raghav

This post has been edited by raghav.naganathan: 14 January 2013 - 11:07 PM

Was This Post Helpful? 0
  • +
  • -

#11 ajrodelo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 14-January 13

Re: need help with text based game making choices

Posted 14 January 2013 - 11:10 PM

         int choice;
     cout  << "WELCOME CRIMINALS\n\n";
     cout  << "Are u ready to comit some crimes and make some MULAH\n";
     cout  << "1. HELL YES\n";
     cout  << "2. Naw im cool\n";
     cout  << "Your Choice";
     cin   >> choice;
     
     
     if(choice == 1 ) {
     cout << "\n\n\n Were do u want to go to to rob \n\n"; 
     cout << "1. Wallmart \n";
     cout << "2. Big 5 \n";
     cout << "3. Target \n";
     cout << "Your Choice";
     std :: cin>>choice;
     
     if(choice == 2) {
     cout << "\n\n\n How do u want to do this \n\n";
     cout << "1. wait for midnight and go hit up the store \n";
     cout << "2. go early and scope out the place \n";               
     cin >> choice;

     if(choice == 1) {
     cout << "1. \n\n\n fg";
     
     }
     else {
     cout  << "\n\n\n FUCKING PUSSY!!";
     }          
     
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}


Was This Post Helpful? 0
  • +
  • -

#12 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: need help with text based game making choices

Posted 14 January 2013 - 11:19 PM

Well, I have commented out some important things of your code. Do take a look

  
     int choice;
     cout  << "WELCOME CRIMINALS\n\n";
     cout  << "Are u ready to comit some crimes and make some MULAH\n";
     cout  << "1. HELL YES\n";
     cout  << "2. Naw im cool\n";
     cout  << "Your Choice";
     cin   >> choice;

  $   if(choice == 1 ) { //first condition i.e. HELL YES
     cout << "\n\n\n Were do u want to go to to rob \n\n"; 
     cout << "1. Wallmart \n";
     cout << "2. Big 5 \n";
     cout << "3. Target \n";
     cout << "Your Choice";
     std :: cin>>choice;
     
 *    if(choice == 2) { //2nd condition i.e Big 5
     cout << "\n\n\n How do u want to do this \n\n";
     cout << "1. wait for midnight and go hit up the store \n";
     cout << "2. go early and scope out the place \n";               
     cin >> choice;

     if(choice == 1) { //First condition i.e wait for midnight
     cout << "1. \n\n\n fg";
          }
     if(choice == 2) {
     cout<<"Something";
          }
     else {
     cout  << "\n\n\n FUCKING PUSSY!!";
     }     
     //Now you need to close the braces accordingly

  }//Closes braces for *

 }//closes braces for $    

    system("PAUSE");
    return EXIT_SUCCESS;
}//closes the main()


This post has been edited by raghav.naganathan: 14 January 2013 - 11:20 PM

Was This Post Helpful? 0
  • +
  • -

#13 ajrodelo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 14-January 13

Re: need help with text based game making choices

Posted 15 January 2013 - 01:10 AM

cool wel my question is how do i keep goin on with scenarios
Was This Post Helpful? 0
  • +
  • -

#14 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: need help with text based game making choices

Posted 15 January 2013 - 01:16 AM

Well, could you please elaborate on what you mean by that?

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#15 ajrodelo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 14-January 13

Re: need help with text based game making choices

Posted 15 January 2013 - 01:34 AM

how do i keep adding choices and branching off of those choices without getting any errors
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2