-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
396 lines (376 loc) · 11.8 KB
/
main.cpp
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
#include <windows.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
unsigned int medicine = 0;
unsigned int pet_feed = 0;
unsigned int toy = 0;
unsigned int books = 0;
void loop(string name, string species); //Loops program
float store(float money); //Allow users to buy items
string name(); //Prompt user for name
string species(); //Prompt user for species
string end(char end, string name); //Tells user fate of critter when it ends
int main()
{
loop(name(), species());
cout << "GAME OVER!" << endl;
}
void loop(string name, string species)
{
float health = 10; //All stats start at 10
float nutrition = 10;
float happiness = 10;
float intelligence = 10;
float money = 0;
string pet = name + " the " + species;
while(true)
{
cout << "Here is your inventory: " << endl
<< "Medicine: " << medicine << endl
<< "Food: " << pet_feed << endl
<< "Toys: " << toy << endl
<< "Books: " << books << endl
<< "Gumnuts: " << money << endl;
cout << endl;
if (health < 05) cout << pet << " is sickly." << endl;
if (health > 15) cout << pet << " is healthy looking." << endl;
if (nutrition < 05) cout << pet << " is looking undernurished." << endl;
if (nutrition > 15) cout << pet << " is getting fat." << endl;
if (happiness < 05) cout << pet << " seems depressed." << endl;
if (happiness > 15) cout << pet << " seems happy." << endl;
if (intelligence < 05) cout << pet << " is stupid." << endl;
if (intelligence > 15) cout << pet << " is unnervingly intelligent." << endl;
cout << endl;
cout << "a) Medicate your pet" << endl
<< "b) Feed your pet" << endl
<< "c) Entertain your pet" << endl
<< "d) Educate your pet" << endl
<< "e) Work in the salt mines" << endl
<< "f) Go to the store" << endl;
char answer;
cin >> answer;
cout << endl;
switch(answer)
{
case 'a':
if (medicine == 0) //Medicine is necessary
{
cout << "Sorry, you have no medicine." << endl;
continue;
}
else
{
if (health >= 20) //Health has a cap
{
cout << "Sorry, your pet is already healthy.";
continue;
}
else
{
medicine--;
health += 2; //Increase by 2
}
}
break;
case 'b':
if (pet_feed == 0)
{
cout << "Sorry, you have no food." << endl;
continue;
}
else
{
pet_feed--;
nutrition += 2;
}
break;
case 'c':
if (toy == 0)
{
cout << "Sorry, you have no toys." << endl; //You can't play with a pet without a toy
continue;
}
else
{
if (happiness >= 20)
{
cout << "Sorry, your pet is happy enough already.";
continue;
}
else
{
toy--; //Toy is destroyed in process of playing
happiness += 2;
}
}
break;
case 'd':
if (books == 0)
{
cout << "Sorry, you have no books." << endl;
continue;
}
else
{
books--; //Book is destroyed in process of reading
intelligence += 2;
}
break;
case 'e':
money++;
break;
case 'f':
money = store(money);
}
health *= 0.95;
nutrition *= 0.95;
happiness *= 0.95;
intelligence *= 0.95;
string msg;
if (health < 2) msg = end('g', pet);
if (nutrition < 2) msg = end('f', pet);
if (nutrition > 20) msg= end('d', pet);
if (happiness < 2) msg = end('r', pet);
if (intelligence < 2) msg = end('l', pet);
if (intelligence > 20) msg = end('t', pet);
if (msg != "")
{
cout << msg << endl;
break;
}
}
}
float store(float money)
{
string item;
unsigned int amount_of_item;
string action;
cout<<"Howd'y there!"<<endl;
cout<<"You have now entered the store."<<endl;
cout<<endl;
cout<<"Commands include \"buy\", \"sell\", or \"exit\"."<<endl;
cout<<endl;
do
{
cin.ignore(256, '\n');
cout<<"Would you like to buy or sell? "<<endl;
cout<<endl;
getline(cin, action);
transform(action.begin(), action.end(), action.begin(), ::tolower);
if(action=="sell")
{
float cost;
float pancake=0.75;
float apples=0.25;
float medicines=2.00;
float book = 4.50;
float toys = 2.00;
string item;
cout<<"Please select an item from the list below"<<endl;
cout<<endl;
cout<<" * Apples"<<endl;
cout<<" * Books"<<endl;
cout<<" * Medicine"<<endl;
cout<<" * Pancakes"<<endl;
cout<<" * Toy"<<endl;
cout<<endl;
cout<<"What item would you like to sell? ";
getline(cin, item);
transform(item.begin(), item.end(), item.begin(), ::tolower); //make lowercase
if(item=="pancakes")
{
cout<<"How many pancakes would you like to sell? ";
cin>>amount_of_item;
if (pet_feed < amount_of_item)
{
cout << "Sorry, you don't have enough." << endl;
continue;
}
cost=pancake*amount_of_item;
money += cost;
pet_feed-=3*amount_of_item;
}
if(item=="apples")
{
cout<<"How many apples would you like to sell? ";
cin>>amount_of_item;
if (pet_feed < amount_of_item)
{
cout << "Sorry, you don't have enough." << endl;
continue;
}
cost=apples*amount_of_item;
money += cost;
pet_feed-=1*amount_of_item;
}
if(item=="medicine")
{
cout<<"How many vials of your medication would you like to sell? "<<endl;
cin>>amount_of_item;
if (medicines < amount_of_item)
{
cout << "Sorry, you don't have enough." << endl;
continue;
}
cost=medicines*amount_of_item;
money += cost;
medicine-=1*amount_of_item;
}
if(item=="toy")
{
cout<<"How many toys would you like to sell? "<<endl;
cin>>amount_of_item;
if (toy < amount_of_item)
{
cout << "Sorry, you don't have enough." << endl;
continue;
}
cost=medicine*amount_of_item;
money += cost;
toy-=1*amount_of_item;
}
if(item=="books")
{
cout<<"How many toys would you like to sell? "<<endl;
cin>>amount_of_item;
if (book < amount_of_item)
{
cout << "Sorry, you don't have enough." << endl;
continue;
}
cost=books*amount_of_item;
money += cost;
book-=1*amount_of_item;
}
cout<<endl;
cout<<endl;
}
if(action=="buy")
{
float cost;
float profit;
float pancake=1.25;
float apples=.50;
float medicines=3.50;
float books=5.00;
float toys = 2.50;
string item;
cout<<"Please select an item from the list below"<<endl;
cout<<endl;
cout<<" * Apples"<<endl;
cout<<" * Books"<<endl;
cout<<" * Medicine"<<endl;
cout<<" * Pancakes"<<endl;
cout<<" * Toy"<<endl;
cout<<endl;
cout<<"What item would you like to buy? ";
getline(cin, item);
transform(item.begin(), item.end(), item.begin(), ::tolower);
if(item=="pancakes")
{
cout<<"How many pancakes would you like to buy? ";
cin>>amount_of_item;
cost=pancake*amount_of_item;
if (cost > money)
{
cout << "Sorry, insufficient funds." << endl;
continue;
}
money -= cost;
pet_feed+=3*amount_of_item; //Pancakes equals 3 foods
}
if(item=="apples")
{
cout<<"How many apples would you like to buy? ";
cin>>amount_of_item;
cost=apples*amount_of_item;
if (cost > money)
{
cout << "Sorry, insufficient funds." << endl;
continue;
}
money -= cost;
pet_feed+=1*amount_of_item;
}
if(item=="medicine")
{
cout<<"How many vials of your medication would you like to buy? "<<endl;
cin>>amount_of_item;
cost=medicines*amount_of_item;
if (cost > money)
{
cout << "Sorry, insufficient funds." << endl;
continue;
}
money -= cost;
medicine+=1*amount_of_item;
}
if(item=="books")
{
cout<<"How many books would you like to buy? "<<endl;
cin>>amount_of_item;
cost=books*amount_of_item;
if (cost > money)
{
cout << "Sorry, insufficient funds." << endl;
continue;
}
money -= cost;
books+=1*amount_of_item;
}
if(item=="toy")
{
cout<<"How many toys would you like to buy? "<<endl;
cin>>amount_of_item;
cost=medicine*amount_of_item;
if (cost > money)
{
cout << "Sorry, insufficient funds." << endl;
continue;
}
money -= cost;
toy+=1*amount_of_item;
}
cout<<endl;
cout<<endl;
}
}
while(action!="exit");
return money;
}
string name()
{
string n;
cout << "What shall you name your critter? ";
getline(cin, n);
return n;
}
string species()
{
string n;
cout << "What kind of Critter have you? ";
getline(cin, n);
return n;
}
string end(char ending, string name)
{
switch(ending)
{
case 'g':
return name + " fades away.";
case 'f':
return name + " faints.";
case 'd':
return name + " is institutionalized due to diabetes.";
case 'r':
return name + " runs away.";
case 'l':
return name + " gets lost.";
case 't':
return name + " takes over the world.";
default :
return "";
}
}