Multiple commands?

So, Im working on an rpg and now pwople cant buy muiltiple things from the shop.

Heres the code
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <string>
#include <ctime>
using namespace std;
char name[50];
int menu;
char comm[10];
int hp;
int manhp;
int yourhp;
int money;
int attack;
int xp;

int bosshp;
int boss;
int level;
int rdm; // Random event when == to 10

int main(int argc, char *argv[])
{
    string cho;
    string shopitm1;
    string inv;
    string bossop;
    string inv3;
    string dev;
    string inv2;
    inv = "You havent got anything :P";
    yourhp = 100;
    srand(time(NULL)); // Timer for the HP random number.
    hp = rand() % 10 + 1; // Timer defined as Int hp
    attack = rand() % 10 + 1;//timer for killing
    boss = rand() % 10 + 1;//timer for bossattck
    string command;
    menu = -1;
    cout << "Moradica v0.01 alpha" << endl;
    cout << "Please enter your name" << endl;
    cin >> name;
    cout << "Welcome to moradica" << endl;

  while(menu < 1 )
{
     cout << "Please enter a command or type 'help' " << endl;
     cin >> command;
     if (command == "help")
     {
            cout << "commands; \n \n\n\n Kill : To kill an enemy\n\n\n Money : To see how mutch money you have\n\n\n Shop : buy things\n\n\nChange log: Current updates \n\n\n inv : To see what you have" << endl; 
           
      }
      else if(command == "kill")
      {
                 cout << "You walk to to a monster he has ";
                 cout << hp <<endl;
                 cout << " Do you attack or run? \n\n" << endl;
                 cin >> cho;
                 if (cho == "attack"){
                         if (xp > 50){
                         cout << "You just leveled up!";
                                   
                         cout << "The monster attacks you for ";
                         cout << attack ;
                         yourhp = yourhp - attack + 2;
                         cout << " hp. You attack back with";
                         cout << attack;
                         cout << "The monster dies droping 3 moneys"<<endl;
                         money = money + 100;
                         xp = xp + 1;}
                         else if (rdm == 10){ 
                              cout << "A leprocon comes and takes 15 of your moneyz";
                              money = money - 10;
                              
                              }
                         else{
                         cout << "The monster attacks you for ";
                         cout << attack ;
                         yourhp = yourhp - attack;
                         cout << " hp. You attack back with";
                         cout << attack;
                         cout << "The monster dies droping 3 moneys"<<endl;
                         money = money + 3;
                         xp = xp + 1;}
                         }
                         if (cho == "potion" && inv == "potion"){
                         cout <<" You used a potion!!! Killing the monster. He droped 20 money";
                         money = money + 20;
                         xp = xp + 5;
                         rdm = rdm + 3;// More use of potion = more change of random event!
                         inv = "Nothing";
                         }
                         
                         
                 
                 
                 }
      
       if (command == "money")
      {
      cout << "You have ";
      cout << money;
      cout << "\n";
           }
                  
      if(command == "shop"){
           cout << "Hello there!!! I am the store clerk. I can sell you over 9000 things!\n\n";
           cout << "Potion = 100 money\n\n\n";
           cout << "Drug \n\n\n";
           cout << "hp boost";
           cin >> shopitm1;
           if (shopitm1 == "potion" || "Potion" && money > 5){
                        cout << "You just got a potion, be warned! It attracts lepercons! You can use it in your next battle\n\n";
                        inv = "potion";
                        money = money - 5; // Taking money 
                        }
          else if (shopitm1 == "Hp boost" || "hp boost"){
                        cout << "You got an HP boost! Use it in the main menu for boosting your overall HP! (boost)";
                        inv2 = "hp";
                        money = money - 5;
                         
                        } 
          else if (shopitm1 == "Drugs" || "drugs"){
                        cout << "This will make you high, At the expence of HP";
                        inv2 = "hp";
                        money = money - 5;}
                         
                                    
                        }
                        
      if (command == "about"){
       cout << "Made by bijan\n\nCompile from 6/1/10\n\n Alpha 0.01\n\n All of this code/program are an experiment \n \n";}
           if (command == "changelog"){
        cout << "Nothing here yet :(";}
      if(command == "dev"){
                 cout << "Developer mode";
            cin >> dev;
       if (dev == "xp"){
               cin >> xp;
               }
       if (dev == "money"){
               cin >> money;
               } }
       if (command == "boost"){
                   if (inv2 == "hp"){
                   cout << "You just boosted your hp by 10 \n\n\n";
                   hp = hp + 10;}
                   else {
                   cout << "You have no hp booster!!!\n\n";
                   }}
       if (command == "stats"){
                   cout << "You have ";
                   cout << xp;
                   cout << "Xp and ";
                   cout << money ;
                   cout << "money \n\n\n";
                   }
               
        if (command == "about"){
       cout << "Made by bijan\n\nCompile from 6/1/10\n\n Alpha 0.01\n\n All of this code/program are an experiment";}
  
       if (command == "code")
       {
                   cout << "This is your save code, Wright it down!\n\n\n"; 
                   cout << money <<"\n"<< xp <<"\n"<< level <<"\n"<< hp <<"\n"<< name<<"\n";
                   cout << "Please take note of it, Include the order of the lines.\n\n";
                   
                   }
    if (command == "enter"){//Crude form of saving, Will continue to use untill i get the hang on I/O
                cout << "Please enter the code in the order you receved it in";
                cin >> money;
                cin >> xp;
                cin >> level;
                cin >> hp;
                cin >> name;}
    if (command == "boss") {
                cout << "You walk uo to the 1st main boss, He hits you for "<< boss << " Damage!\n\n You hit him back with "<< attack <<" damage!\n\n Do you use a potion?";
                cin >> bossop;
                if (bossop == "yes" || "Yes")
                hp = hp + 10;
                
                cout << "He hits you again with" << boss << "Damage, You hit him with" << attack << "\n";
                cout << "The boss falls to the ground in agony\n";
                menu = 3;
                
                
                }
        
        
    if(hp < 0){
           cout << "YOU LOOSE!" << endl;
           }
       if (money > 1000){
           
           cout << "Youve won!";}
           
       else if(command == "inv"){
            cout << "\n\n\n";
            cout << inv;
            string man;
 
    
            
            }
            


           }
           
          string man; 
       while (menu > 2)  {
          cout << "Welcome to level 2! \n As you see the boss dieing you notice a man in the back ground do you walk up to him?";
          cin >> man;
          }
           

                 }
                                  
                 
           

    
Because the shop command should be a loop with an option to escape. Not a bad start for a beginner certainly better then my first attempt.

EDIT: Acctually all of these commands should be a loop of some sort. I like the leprocan, you should put something it that says: "Give chase?" "He got away :( "
Last edited on
Topic archived. No new replies allowed.