SHOW:
|
|
- or go back to the newest paste.
1 | [Code=cpp] | |
2 | #include <iostream> | |
3 | #include <fstream> | |
4 | #include <string> | |
5 | #include <vector> | |
6 | #include <cstdlib> | |
7 | #include <ctime> | |
8 | ||
9 | #include "player.h" | |
10 | #include "Dinosaur.h" | |
11 | ||
12 | - | void save(); |
12 | + | |
13 | - | void load(); |
13 | + | |
14 | - | void shop(); |
14 | + | |
15 | - | void arena(); |
15 | + | |
16 | - | void backpack(); |
16 | + | |
17 | - | void flags(); |
17 | + | std::cout << "Build 1.2.0" << std::endl; |
18 | - | void dinoSelect(); |
18 | + | |
19 | - | void stats(); |
19 | + | |
20 | - | void trex(); |
20 | + | |
21 | - | void velociraptor(); |
21 | + | |
22 | std::cout << "1) Load Game" << std::endl; | |
23 | std::cout << "2) New Game" << std::endl; | |
24 | std::cout << "3) Quit Game" << std::endl; | |
25 | std::cin >> choice; | |
26 | ||
27 | if(choice == 1) | |
28 | - | std::cout << "Build 1.0.0" << std::endl; |
28 | + | |
29 | pc.load(); | |
30 | } | |
31 | else if(choice == 2) | |
32 | { | |
33 | pc.MainGame(); | |
34 | } | |
35 | else if(choice == 3) | |
36 | { | |
37 | return 0; | |
38 | } | |
39 | } | |
40 | ||
41 | ||
42 | ||
43 | ||
44 | ||
45 | /* | |
46 | =============| | |
47 | Save function| | |
48 | =============| | |
49 | */ | |
50 | ||
51 | void player::save() | |
52 | { | |
53 | std::ofstream fileOut; | |
54 | ||
55 | fileOut.open("DASave.txt"); | |
56 | ||
57 | fileOut << get_playerHealth() << std::endl; | |
58 | fileOut << get_pistolAmmo() << std::endl; | |
59 | fileOut << get_shotgunAmmo() << std::endl; | |
60 | fileOut << get_rifleAmmo() << std::endl; | |
61 | fileOut << get_score() << std::endl; | |
62 | fileOut << get_money() << std::endl; | |
63 | fileOut << get_healthPacks() << std::endl; | |
64 | ||
65 | MainGame(); | |
66 | } | |
67 | ||
68 | ||
69 | ||
70 | ||
71 | ||
72 | /* | |
73 | =============| | |
74 | Load function| | |
75 | =============| | |
76 | */ | |
77 | ||
78 | void player::load() | |
79 | { | |
80 | std::ifstream fileIn; | |
81 | ||
82 | fileIn.open("DASave.txt"); | |
83 | ||
84 | fileIn >> playerHealth; | |
85 | fileIn >> pistolAmmo; | |
86 | fileIn >> shotgunAmmo; | |
87 | fileIn >> rifleAmmo; | |
88 | fileIn >> score; | |
89 | fileIn >> money; | |
90 | fileIn >> healthPacks; | |
91 | ||
92 | std::cout << "Health: " << playerHealth << std::endl; | |
93 | std::cout << "Pistol Ammo: " << pistolAmmo << std::endl; | |
94 | std::cout << "Shotgun Ammo: " << shotgunAmmo << std::endl; | |
95 | std::cout << "Rifle Ammo: " << rifleAmmo << std::endl; | |
96 | std::cout << "Score: " << score << std::endl; | |
97 | std::cout << "Money: " << money << std::endl; | |
98 | std::cout << "Health Packs: " << healthPacks << std::endl; | |
99 | std::cout << "\n"; | |
100 | ||
101 | MainGame(); | |
102 | } | |
103 | ||
104 | ||
105 | ||
106 | ||
107 | ||
108 | /* | |
109 | =============| | |
110 | Shop function| | |
111 | =============| | |
112 | */ | |
113 | ||
114 | void player::shop() | |
115 | { | |
116 | int menuChoice; | |
117 | int amountChoice = 0; | |
118 | std::string inv; | |
119 | ||
120 | items[0] = 0; | |
121 | items[1] = 0; | |
122 | items[2] = 0; | |
123 | items[3] = 0; | |
124 | ||
125 | std::cout << "\n"; | |
126 | std::cout << "GENERAL STORE\n" << std::endl; | |
127 | ||
128 | std::cout << "Type in -1 to quit" << std::endl; | |
129 | std::cout << "1) Health Pack - $5" << std::endl; | |
130 | std::cout << "2) Pistol Ammo - $2" << std::endl; | |
131 | std::cout << "3) Shotgun Ammo - $5" << std::endl; | |
132 | std::cout << "4) Rifle Ammo - $18" << std::endl; | |
133 | std::cin >> menuChoice; | |
134 | ||
135 | while((amountChoice != -1) || (menuChoice != -1)) | |
136 | { | |
137 | if((amountChoice == -1) || (menuChoice == -1)) | |
138 | { | |
139 | std::cout << "Thank you for shopping at the store\n" << std::endl; | |
140 | MainGame(); | |
141 | break; | |
142 | } | |
143 | else | |
144 | { | |
145 | ||
146 | switch(menuChoice) | |
147 | { | |
148 | case 1: | |
149 | { | |
150 | std::cout << "How many Health Packs do you want to buy?" << std::endl; | |
151 | std::cout << "$5 per health pack" << std::endl; | |
152 | ||
153 | while(amountChoice != -1) | |
154 | { | |
155 | std::cin >> amountChoice; | |
156 | ||
157 | items[0] = amountChoice; | |
158 | ||
159 | if(money >= items[0] * 5) | |
160 | { | |
161 | money -= items[0] * 5; | |
162 | healthPacks += amountChoice; | |
163 | std::cout << "Current money equals $" << money << std::endl; | |
164 | std::cout << "Current Health Packs: " << healthPacks << std::endl; | |
165 | std::cout << "\n"; | |
166 | amountChoice = 0; | |
167 | ||
168 | save(); | |
169 | shop(); | |
170 | } | |
171 | else | |
172 | { | |
173 | std::cout << "You do not have enough money" << std::endl; | |
174 | } | |
175 | } | |
176 | ||
177 | }break; | |
178 | ||
179 | case 2: | |
180 | { | |
181 | std::cout << "How much Pistol Ammo do you want to buy?" << std::endl; | |
182 | std::cin >> amountChoice; | |
183 | ||
184 | items[1] = amountChoice; | |
185 | ||
186 | if(money >= items[1] * 2) | |
187 | { | |
188 | money -= items[1] * 2; | |
189 | pistolAmmo += amountChoice; | |
190 | std::cout << "Current money equals $" << money << std::endl; | |
191 | std::cout << "Current Pistol Ammo: " << pistolAmmo << std::endl; | |
192 | std::cout << "\n"; | |
193 | amountChoice = 0; | |
194 | ||
195 | save(); | |
196 | shop(); | |
197 | } | |
198 | else | |
199 | { | |
200 | std::cout << "You do not have enough money" << std::endl; | |
201 | } | |
202 | ||
203 | }break; | |
204 | ||
205 | case 3: | |
206 | { | |
207 | std::cout << "How much Shotgun Ammo do you want to buy?" << std::endl; | |
208 | std::cin >> amountChoice; | |
209 | ||
210 | items[2] = amountChoice; | |
211 | ||
212 | if(money >= items[2] * 5) | |
213 | { | |
214 | money -= items[2] * 5; | |
215 | shotgunAmmo += amountChoice; | |
216 | std::cout << "Current money equals $" << money << std::endl; | |
217 | std::cout << "Current Shotgun Ammo: " << shotgunAmmo << std::endl; | |
218 | std::cout << "\n"; | |
219 | amountChoice = 0; | |
220 | ||
221 | save(); | |
222 | shop(); | |
223 | } | |
224 | else | |
225 | { | |
226 | std::cout << "You do not have enough money" << std::endl; | |
227 | } | |
228 | ||
229 | }break; | |
230 | ||
231 | case 4: | |
232 | { | |
233 | std::cout << "How much Rifle Ammo do you want to buy?" << std::endl; | |
234 | std::cin >> amountChoice; | |
235 | ||
236 | items[3] = amountChoice; | |
237 | ||
238 | if(money >= items[3] * 18) | |
239 | { | |
240 | money -= items[3] * 18; | |
241 | rifleAmmo += amountChoice; | |
242 | std::cout << "Current money equals $" << money << std::endl; | |
243 | std::cout << "Current Rifle Ammo: " << rifleAmmo << std::endl; | |
244 | std::cout << "\n"; | |
245 | amountChoice = 0; | |
246 | ||
247 | save(); | |
248 | shop(); | |
249 | } | |
250 | else | |
251 | { | |
252 | std::cout << "You do not have enough money" << std::endl; | |
253 | } | |
254 | ||
255 | }break; | |
256 | }//End of switch statement | |
257 | } | |
258 | }//End of while loop | |
259 | } | |
260 | ||
261 | ||
262 | ||
263 | ||
264 | ||
265 | /* | |
266 | =================| | |
267 | Backpack function| | |
268 | =================| | |
269 | */ | |
270 | ||
271 | void player::backpack() | |
272 | { | |
273 | std::cout << "ITEMS\n" << std::endl; | |
274 | ||
275 | std::cout << "Money $" << money << std::endl; | |
276 | std::cout << "Health Packs: " << healthPacks << std::endl; | |
277 | std::cout << "Pistol Ammo: " << pistolAmmo << std::endl; | |
278 | std::cout << "Shotgun Ammo: " << shotgunAmmo << std::endl; | |
279 | std::cout << "Rifle Ammo: " << rifleAmmo << std::endl; | |
280 | ||
281 | std::cout << "\n"; | |
282 | ||
283 | std::cout << "WEAPONS\n" << std::endl; | |
284 | ||
285 | std::cout << "Pistol - Does 3 points of damage against enemies" << std::endl; | |
286 | std::cout << "Shotgun - Does 9 points of damage against enemies" << std::endl; | |
287 | std::cout << "Rifle - Does 13 points of damage against enemies" << std::endl; | |
288 | } | |
289 | ||
290 | ||
291 | ||
292 | ||
293 | ||
294 | void player::stats() | |
295 | { | |
296 | std::cout << "STATS\n" << std::endl; | |
297 | ||
298 | ||
299 | } | |
300 | ||
301 | ||
302 | ||
303 | ||
304 | ||
305 | /* | |
306 | ==================| | |
307 | Main Game function| | |
308 | ==================| | |
309 | */ | |
310 | ||
311 | void player::MainGame() | |
312 | { | |
313 | int choice; | |
314 | ||
315 | std::cout << "1) Start Battle" << std::endl; | |
316 | std::cout << "2) View Stats" << std::endl; | |
317 | std::cout << "3) General Store" << std::endl; | |
318 | std::cout << "4) View Backpack" << std::endl; | |
319 | std::cout << "5) Save Game" << std::endl; | |
320 | std::cin >> choice; | |
321 | ||
322 | ||
323 | if(choice == 1) | |
324 | { | |
325 | dinoSelect(); | |
326 | } | |
327 | else if(choice == 2) | |
328 | { | |
329 | stats(); | |
330 | } | |
331 | else if(choice == 3) | |
332 | { | |
333 | shop(); | |
334 | } | |
335 | else if(choice == 4) | |
336 | { | |
337 | backpack(); | |
338 | } | |
339 | else if(choice == 5) | |
340 | { | |
341 | save(); | |
342 | } | |
343 | } | |
344 | ||
345 | ||
346 | ||
347 | ||
348 | ||
349 | /* | |
350 | ========================| | |
351 | Dinosaur select function| | |
352 | ========================| | |
353 | */ | |
354 | ||
355 | void player::dinoSelect() | |
356 | { | |
357 | time_t T; | |
358 | time(&T); | |
359 | srand(T); | |
360 | int Time; | |
361 | ||
362 | dinosaur D; | |
363 | ||
364 | Time = rand() % 2; | |
365 | ||
366 | switch(Time) | |
367 | { | |
368 | case 0: | |
369 | { | |
370 | std::cout << "Your opponent is the T-Rex!!\n" << std::endl; | |
371 | do | |
372 | { | |
373 | D.arena(); | |
374 | D.trex(); | |
375 | } | |
376 | while(playerHealth >= 1); | |
377 | }break; | |
378 | case 1: | |
379 | { | |
380 | std::cout << "Your opponent is the Raptor!!\n" << std::endl; | |
381 | do | |
382 | { | |
383 | D.arena(); | |
384 | D.velociraptor(); | |
385 | } | |
386 | while(playerHealth >= 1); | |
387 | }break; | |
388 | } | |
389 | } | |
390 | ||
391 | ||
392 | ||
393 | ||
394 | ||
395 | /* | |
396 | ==============| | |
397 | Arena function| | |
398 | ==============| | |
399 | */ | |
400 | ||
401 | void dinosaur::arena() | |
402 | { | |
403 | int choice; | |
404 | int miss; | |
405 | int useHealth; | |
406 | time_t T; | |
407 | time(&T); | |
408 | srand(T); | |
409 | ||
410 | for(int i = 0; i < 5; i++) | |
411 | { | |
412 | miss = rand() % 5; | |
413 | } | |
414 | ||
415 | flags(); | |
416 | ||
417 | std::cout << "==========================" << std::endl; | |
418 | std::cout << "----------TURN " << turns << "----------"<< std::endl; | |
419 | std::cout << "==========================\n" << std::endl; | |
420 | ||
421 | turns++; | |
422 | ||
423 | std::cout << "Make your move\n" << std::endl; | |
424 | ||
425 | std::cout << "Your health " << get_playerHealth() << std::endl; | |
426 | std::cout << "Dinosaur health " << get_dinosaurHealth() << std::endl; | |
427 | std::cout << "\n"; | |
428 | std::cout << "ITEMS\n"; | |
429 | std::cout << "Pistol Ammo " << get_pistolAmmo() << std::endl; | |
430 | std::cout << "Shotgun Ammo " << get_shotgunAmmo() << std::endl; | |
431 | std::cout << "Rifle Ammo " << get_rifleAmmo() << std::endl; | |
432 | std::cout << "\n"; | |
433 | ||
434 | std::cout << "What do you want to use?" << std::endl; | |
435 | std::cout << "1) Pistol" << std::endl; | |
436 | std::cout << "\t Damage: 3" << std::endl; | |
437 | - | switch(miss) |
437 | + | |
438 | ||
439 | - | case 0: |
439 | + | |
440 | std::cout << "\t Damage: 9" << std::endl; | |
441 | - | std::cout << "Your attack missed!!\n" << std::endl; |
441 | + | |
442 | ||
443 | std::cout << "3) Rifle" << std::endl; | |
444 | - | }break; |
444 | + | |
445 | - | case 4: |
445 | + | |
446 | ||
447 | - | std::cout << "Double Damage Bonus!!\n" << std::endl; |
447 | + | |
448 | - | if(pistolAmmo >= 17) |
448 | + | |
449 | - | { |
449 | + | |
450 | - | std::cout << "Enough ammo" << std::endl; |
450 | + | |
451 | - | pistolAmmo -= 17; |
451 | + | |
452 | - | dinosaurHealth -= 6; |
452 | + | |
453 | - | } |
453 | + | |
454 | - | if((pistolAmmo < 17) && (pistolAmmo >= 1)) |
454 | + | |
455 | - | { |
455 | + | |
456 | - | std::cout << "But you dont have enough Ammo, you only did regular damage!" << std::endl; |
456 | + | if(miss = 0) |
457 | - | std::cout << "Used " << pistolAmmo << " Pistol rounds" << std::endl; |
457 | + | |
458 | - | pistolAmmo -= pistolAmmo; |
458 | + | std::cout << "Your attack missed!!\n" << std::endl; |
459 | - | dinosaurHealth -= 3; |
459 | + | dinosaurHealth -= 0; |
460 | - | } |
460 | + | pistolAmmo -= 0; |
461 | - | else if(pistolAmmo == 0) |
461 | + | |
462 | - | { |
462 | + | if(miss = 4) |
463 | - | std::cout << "No ammo left for the Pistol!!" << std::endl; |
463 | + | |
464 | - | pistolAmmo -= 0; |
464 | + | std::cout << "Double Damage Bonus!!\n" << std::endl; |
465 | - | dinosaurHealth -= 0; |
465 | + | if(pistolAmmo >= 17) |
466 | - | } |
466 | + | |
467 | - | }break; |
467 | + | std::cout << "Enough ammo" << std::endl; |
468 | - | default: |
468 | + | pistolAmmo -= 17; |
469 | dinosaurHealth -= 6; | |
470 | - | std::cout << "You hit the enemy\n" << std::endl; |
470 | + | |
471 | - | if(pistolAmmo >= 17) |
471 | + | if((pistolAmmo < 17) && (pistolAmmo >= 1)) |
472 | - | { |
472 | + | |
473 | - | std::cout << "Enough ammo" << std::endl; |
473 | + | std::cout << "But you dont have enough Ammo, you only did regular damage!" << std::endl; |
474 | - | pistolAmmo -= 17; |
474 | + | std::cout << "Used " << pistolAmmo << " Pistol rounds" << std::endl; |
475 | - | dinosaurHealth -= 3; |
475 | + | pistolAmmo -= pistolAmmo; |
476 | - | } |
476 | + | dinosaurHealth -= 3; |
477 | - | if((pistolAmmo < 17) && (pistolAmmo >= 1)) |
477 | + | |
478 | - | { |
478 | + | if(pistolAmmo = 0) |
479 | - | std::cout << "Not enough Ammo" << std::endl; |
479 | + | |
480 | - | std::cout << "Used " << pistolAmmo << " Pistol rounds" << std::endl; |
480 | + | std::cout << "No ammo left for the Pistol!!" << std::endl; |
481 | - | pistolAmmo -= pistolAmmo; |
481 | + | pistolAmmo -= 0; |
482 | - | dinosaurHealth -= 2; |
482 | + | dinosaurHealth -= 0; |
483 | - | } |
483 | + | |
484 | - | else if(pistolAmmo == 0) |
484 | + | |
485 | - | { |
485 | + | else if((miss != 0) &&(miss != 4))//If none of the above applies then execute this else statement |
486 | - | std::cout << "No ammo left for the Pistol!!" << std::endl; |
486 | + | |
487 | - | pistolAmmo -= 0; |
487 | + | std::cout << "You hit the enemy\n" << std::endl; |
488 | - | dinosaurHealth -= 0; |
488 | + | if(pistolAmmo >= 17) |
489 | - | } |
489 | + | |
490 | std::cout << "Enough ammo" << std::endl; | |
491 | - | }//Miss Switch one |
491 | + | pistolAmmo -= 17; |
492 | dinosaurHealth -= 3; | |
493 | } | |
494 | if((pistolAmmo < 17) && (pistolAmmo >= 1)) | |
495 | { | |
496 | std::cout << "Not enough Ammo" << std::endl; | |
497 | std::cout << "Used " << pistolAmmo << " Pistol rounds" << std::endl; | |
498 | - | switch(miss) |
498 | + | pistolAmmo -= pistolAmmo; |
499 | dinosaurHealth -= 2; | |
500 | - | case 0: |
500 | + | |
501 | if(pistolAmmo = 0) | |
502 | - | std::cout << "Your attack missed!!\n" << std::endl; |
502 | + | |
503 | std::cout << "No ammo left for the Pistol!!" << std::endl; | |
504 | pistolAmmo -= 0; | |
505 | - | }break; |
505 | + | |
506 | - | case 4: |
506 | + | |
507 | }//End of else statement | |
508 | - | std::cout << "Double Damage Bonus!!\n" << std::endl; |
508 | + | }//end of else if |
509 | - | if(shotgunAmmo >= 8) |
509 | + | |
510 | - | { |
510 | + | }break;//End of Case 1 |
511 | - | std::cout << "Enough ammo" << std::endl; |
511 | + | |
512 | - | shotgunAmmo -= 8; |
512 | + | |
513 | - | dinosaurHealth -= 16; |
513 | + | |
514 | - | } |
514 | + | |
515 | - | if((shotgunAmmo < 8) && (shotgunAmmo >= 1)) |
515 | + | if(miss = 0) |
516 | - | { |
516 | + | |
517 | - | std::cout << "But you dont have enough Ammo, you only did regular damage!" << std::endl; |
517 | + | std::cout << "Your attack missed!!\n" << std::endl; |
518 | - | std::cout << "Used " << shotgunAmmo << " Shotgun rounds" << std::endl; |
518 | + | dinosaurHealth -= 0; |
519 | - | shotgunAmmo -= shotgunAmmo; |
519 | + | shotgunAmmo -= 0; |
520 | - | dinosaurHealth -= 8; |
520 | + | |
521 | - | } |
521 | + | if(miss = 4) |
522 | - | else if(shotgunAmmo == 0) |
522 | + | |
523 | - | { |
523 | + | std::cout << "Double Damage Bonus!!\n" << std::endl; |
524 | - | std::cout << "No ammo left for the Shotgun!!" << std::endl; |
524 | + | if(shotgunAmmo >= 9) |
525 | - | shotgunAmmo -= 0; |
525 | + | |
526 | - | dinosaurHealth -= 0; |
526 | + | std::cout << "Enough ammo" << std::endl; |
527 | - | } |
527 | + | shotgunAmmo -= 8; |
528 | - | }break; |
528 | + | dinosaurHealth -= 6; |
529 | - | default: |
529 | + | |
530 | if((shotgunAmmo < 9) && (shotgunAmmo >= 1)) | |
531 | - | std::cout << "You hit the enemy\n" << std::endl; |
531 | + | |
532 | - | if(shotgunAmmo >= 17) |
532 | + | std::cout << "But you dont have enough Ammo, you only did regular damage!" << std::endl; |
533 | - | { |
533 | + | std::cout << "Used " << shotgunAmmo << " Shotgun rounds" << std::endl; |
534 | - | std::cout << "Enough ammo" << std::endl; |
534 | + | shotgunAmmo -= shotgunAmmo; |
535 | - | shotgunAmmo -= 17; |
535 | + | dinosaurHealth -= 3; |
536 | - | dinosaurHealth -= 3; |
536 | + | |
537 | - | } |
537 | + | if(shotgunAmmo = 0) |
538 | - | if((shotgunAmmo < 8) && (shotgunAmmo >= 1)) |
538 | + | |
539 | - | { |
539 | + | std::cout << "No ammo left for the Shotgun!!" << std::endl; |
540 | - | std::cout << "Not enough Ammo" << std::endl; |
540 | + | shotgunAmmo -= 0; |
541 | - | std::cout << "Used " << shotgunAmmo << " Shotgun rounds" << std::endl; |
541 | + | dinosaurHealth -= 0; |
542 | - | shotgunAmmo -= shotgunAmmo; |
542 | + | |
543 | - | dinosaurHealth -= 3; |
543 | + | |
544 | - | } |
544 | + | else if((miss != 0) &&(miss != 4))//If none of the above applies then execute this else statement |
545 | - | else if(shotgunAmmo == 0) |
545 | + | |
546 | - | { |
546 | + | std::cout << "You hit the enemy\n" << std::endl; |
547 | - | std::cout << "No ammo left for the Shotgun!!" << std::endl; |
547 | + | if(shotgunAmmo >= 9) |
548 | - | shotgunAmmo -= 0; |
548 | + | |
549 | - | dinosaurHealth -= 0; |
549 | + | std::cout << "Enough ammo" << std::endl; |
550 | - | } |
550 | + | shotgunAmmo -= 8; |
551 | dinosaurHealth -= 3; | |
552 | - | }//Miss Switch one |
552 | + | |
553 | if((shotgunAmmo < 9) && (shotgunAmmo >= 1)) | |
554 | { | |
555 | std::cout << "Not enough Ammo" << std::endl; | |
556 | std::cout << "You used " << shotgunAmmo << " Shotgun rounds" << std::endl; | |
557 | shotgunAmmo -= shotgunAmmo; | |
558 | - | switch(miss) |
558 | + | dinosaurHealth -= 2; |
559 | } | |
560 | - | case 0: |
560 | + | if(shotgunAmmo == 0) |
561 | { | |
562 | - | std::cout << "Your attack missed!!\n" << std::endl; |
562 | + | std::cout << "No ammo left for the Shotgun!!" << std::endl; |
563 | shotgunAmmo -= 0; | |
564 | dinosaurHealth -= 0; | |
565 | - | }break; |
565 | + | |
566 | - | case 4: |
566 | + | }//End of else statement |
567 | }//end of else if | |
568 | - | std::cout << "Double Damage Bonus!!\n" << std::endl; |
568 | + | |
569 | - | if(rifleAmmo >= 32) |
569 | + | }break;//End of Case 2 |
570 | - | { |
570 | + | |
571 | - | std::cout << "Enough ammo" << std::endl; |
571 | + | |
572 | - | rifleAmmo -= 32; |
572 | + | |
573 | - | dinosaurHealth -= 26; |
573 | + | |
574 | - | } |
574 | + | if(miss = 0) |
575 | - | if((rifleAmmo < 32) && (rifleAmmo >= 1)) |
575 | + | |
576 | - | { |
576 | + | std::cout << "Your attack missed!!\n" << std::endl; |
577 | - | std::cout << "But you dont have enough Ammo, you only did regular damage!" << std::endl; |
577 | + | dinosaurHealth -= 0; |
578 | - | std::cout << "Used " << rifleAmmo << " Rifle rounds" << std::endl; |
578 | + | rifleAmmo -= 0; |
579 | - | rifleAmmo -= rifleAmmo; |
579 | + | |
580 | - | dinosaurHealth -= 13; |
580 | + | if(miss = 4) |
581 | - | } |
581 | + | |
582 | - | else if(rifleAmmo == 0) |
582 | + | std::cout << "Double Damage Bonus!!\n" << std::endl; |
583 | - | { |
583 | + | if(rifleAmmo >= 17) |
584 | - | std::cout << "No ammo left for the Rifle!!" << std::endl; |
584 | + | |
585 | - | rifleAmmo -= 0; |
585 | + | std::cout << "Enough ammo" << std::endl; |
586 | - | dinosaurHealth -= 0; |
586 | + | rifleAmmo -= 17; |
587 | - | } |
587 | + | dinosaurHealth -= 6; |
588 | - | }break; |
588 | + | |
589 | - | default: |
589 | + | if((rifleAmmo < 17) && (rifleAmmo >= 1)) |
590 | { | |
591 | - | std::cout << "You hit the enemy\n" << std::endl; |
591 | + | std::cout << "But you dont have enough Ammo, you only did regular damage!" << std::endl; |
592 | - | if(rifleAmmo >= 32) |
592 | + | std::cout << "Used " << rifleAmmo << " Rifle rounds" << std::endl; |
593 | - | { |
593 | + | rifleAmmo -= rifleAmmo; |
594 | - | std::cout << "Enough ammo" << std::endl; |
594 | + | dinosaurHealth -= 3; |
595 | - | rifleAmmo -= 32; |
595 | + | |
596 | - | dinosaurHealth -= 13; |
596 | + | if(rifleAmmo = 0) |
597 | - | } |
597 | + | |
598 | - | if((rifleAmmo < 32) && (rifleAmmo >= 1)) |
598 | + | std::cout << "No ammo left for the Rifle!!" << std::endl; |
599 | - | { |
599 | + | rifleAmmo -= 0; |
600 | - | std::cout << "Not enough Ammo" << std::endl; |
600 | + | dinosaurHealth -= 0; |
601 | - | std::cout << "Used " << rifleAmmo << " Rifle rounds" << std::endl; |
601 | + | |
602 | - | rifleAmmo -= rifleAmmo; |
602 | + | |
603 | - | dinosaurHealth -= 8; |
603 | + | else if((miss != 0) &&(miss != 4))//If none of the above applies then execute this else statement |
604 | - | } |
604 | + | |
605 | - | else if(rifleAmmo == 0) |
605 | + | std::cout << "You hit the enemy\n" << std::endl; |
606 | - | { |
606 | + | if(rifleAmmo >= 17) |
607 | - | std::cout << "No ammo left for the Rifle!!" << std::endl; |
607 | + | |
608 | - | rifleAmmo -= 0; |
608 | + | std::cout << "Enough ammo" << std::endl; |
609 | - | dinosaurHealth -= 0; |
609 | + | rifleAmmo -= 17; |
610 | - | } |
610 | + | dinosaurHealth -= 3; |
611 | } | |
612 | - | }//Miss Switch one |
612 | + | if((rifleAmmo < 17) && (rifleAmmo >= 1)) |
613 | { | |
614 | std::cout << "Not enough Ammo" << std::endl; | |
615 | std::cout << "Used " << rifleAmmo << " Rifle rounds" << std::endl; | |
616 | - | case 4://Choice case |
616 | + | rifleAmmo -= rifleAmmo; |
617 | dinosaurHealth -= 2; | |
618 | } | |
619 | if(rifleAmmo = 0) | |
620 | { | |
621 | std::cout << "No ammo left for the Rifle!!" << std::endl; | |
622 | - | std::cout << "\n"; |
622 | + | |
623 | - | std::cout << "Health pack used +15 health reshopd\n" << std::endl; |
623 | + | |
624 | - | playerHealth += 50; |
624 | + | |
625 | - | healthPacks -= 1; |
625 | + | }//End of else statement |
626 | }//end of else if | |
627 | }break; | |
628 | ||
629 | ||
630 | case 4://Health pack choice | |
631 | { | |
632 | std::cout << "Use health pack?" << std::endl; | |
633 | std::cout << "1) Use" << std::endl; | |
634 | std::cout << "2) Don't Use" << std::endl; | |
635 | std::cin >> useHealth; | |
636 | ||
637 | if(useHealth == 1) | |
638 | { | |
639 | - | //int attacks[5] = {5,9,13,19,23}; |
639 | + | std::cout << "\n"; |
640 | std::cout << "Health pack used +50 health restored\n" << std::endl; | |
641 | playerHealth += 50; | |
642 | healthPacks -= 1; | |
643 | } | |
644 | if(useHealth == 2) | |
645 | { | |
646 | std::cout << "Did not use a health pack" << std::endl; | |
647 | } | |
648 | }break; | |
649 | } | |
650 | } | |
651 | ||
652 | ||
653 | ||
654 | ||
655 | ||
656 | /* | |
657 | ==============| | |
658 | T-Rex function| | |
659 | ==============| | |
660 | */ | |
661 | ||
662 | void dinosaur::trex() | |
663 | { | |
664 | int TrexHealth = 0; | |
665 | time_t T; | |
666 | time(&T); | |
667 | srand(T); | |
668 | int Time; | |
669 | ||
670 | Time = rand() % 6; | |
671 | ||
672 | TrexHealth = dinosaurHealth; | |
673 | ||
674 | flags(); | |
675 | ||
676 | switch(Time) | |
677 | { | |
678 | case 0: | |
679 | { | |
680 | std::cout << "T-Rex used Bite!!\n" << std::endl; | |
681 | playerHealth -= 5; | |
682 | }break; | |
683 | case 1: | |
684 | { | |
685 | std::cout << "T-Rex used Stomp!!\n" << std::endl; | |
686 | playerHealth -= 9; | |
687 | }break; | |
688 | case 2: | |
689 | { | |
690 | std::cout << "T-Rex used Crunch\n" << std::endl; | |
691 | playerHealth -= 13; | |
692 | }break; | |
693 | case 3: | |
694 | { | |
695 | - | //int attacks[5] = {5,9,13,19,23}; |
695 | + | |
696 | playerHealth -= 19; | |
697 | }break; | |
698 | case 4: | |
699 | { | |
700 | std::cout << "T-Rex used Pulverize\n" << std::endl; | |
701 | playerHealth -= 23; | |
702 | }break; | |
703 | default: | |
704 | { | |
705 | std::cout << "T-Rex attack missed!!\n" << std::endl; | |
706 | playerHealth -= 0; | |
707 | } | |
708 | } | |
709 | } | |
710 | ||
711 | ||
712 | ||
713 | ||
714 | ||
715 | /* | |
716 | ===============| | |
717 | Raptor function| | |
718 | ===============| | |
719 | */ | |
720 | ||
721 | void dinosaur::velociraptor() | |
722 | { | |
723 | int RaptorHealth = 0; | |
724 | time_t T; | |
725 | time(&T); | |
726 | srand(T); | |
727 | int Time; | |
728 | ||
729 | Time = rand() % 6; | |
730 | ||
731 | RaptorHealth = dinosaurHealth; | |
732 | ||
733 | flags(); | |
734 | ||
735 | switch(Time) | |
736 | { | |
737 | case 0: | |
738 | { | |
739 | std::cout << "Raptor used Bite!!\n" << std::endl; | |
740 | playerHealth -= 5; | |
741 | }break; | |
742 | case 1: | |
743 | { | |
744 | std::cout << "Raptor used Slash!!\n" << std::endl; | |
745 | playerHealth -= 9; | |
746 | }break; | |
747 | case 2: | |
748 | { | |
749 | std::cout << "Raptor used Leap Attack\n" << std::endl; | |
750 | playerHealth -= 13; | |
751 | }break; | |
752 | case 3: | |
753 | { | |
754 | std::cout << "Raptor used Slam\n" << std::endl; | |
755 | playerHealth -= 19; | |
756 | }break; | |
757 | case 4: | |
758 | { | |
759 | std::cout << "Raptor used Shred\n" << std::endl; | |
760 | playerHealth -= 23; | |
761 | }break; | |
762 | default: | |
763 | { | |
764 | std::cout << "Raptors attack missed!!\n" << std::endl; | |
765 | playerHealth -= 0; | |
766 | } | |
767 | } | |
768 | } | |
769 | ||
770 | - | [/Code] |
770 | + | |
771 | ||
772 | ||
773 | ||
774 | /* | |
775 | ==========================| | |
776 | Conditional flags function| | |
777 | ==========================| | |
778 | */ | |
779 | ||
780 | void dinosaur::flags() | |
781 | { | |
782 | if(playerHealth <= 0) | |
783 | { | |
784 | std::cout << "\n"; | |
785 | std::cout << "->You died game over<-\n" << std::endl; | |
786 | turns == 0; | |
787 | MainGame(); | |
788 | } | |
789 | ||
790 | if((playerHealth >= 1) && (dinosaurHealth <= 0)) | |
791 | { | |
792 | money += 250; | |
793 | score++; | |
794 | ||
795 | std::cout << "\n"; | |
796 | std::cout << "->You have won!!!<-\n" << std::endl; | |
797 | std::cout << "Score " << score << std::endl; | |
798 | std::cout << "Money+ $" << money << std::endl; | |
799 | std::cout << "\n"; | |
800 | turns == 0; | |
801 | MainGame(); | |
802 | } | |
803 | } | |
804 | [/Code] | |
805 | ||
806 | player.h | |
807 | ||
808 | #ifndef PLAYER_H | |
809 | #define PLAYER_H | |
810 | ||
811 | #include <vector> | |
812 | #include <string> | |
813 | ||
814 | /* | |
815 | ============| | |
816 | Player Class| | |
817 | ============| | |
818 | */ | |
819 | ||
820 | class player | |
821 | { | |
822 | protected: | |
823 | int playerHealth; | |
824 | int pistolAmmo; | |
825 | int shotgunAmmo; | |
826 | int rifleAmmo; | |
827 | int score; | |
828 | int money; | |
829 | int healthPacks; | |
830 | int turns; | |
831 | int *items; | |
832 | ||
833 | public: | |
834 | void save(); | |
835 | void load(); | |
836 | void MainGame(); | |
837 | void shop(); | |
838 | void backpack(); | |
839 | void stats(); | |
840 | void dinoSelect(); | |
841 | player(); | |
842 | ~player(); | |
843 | ||
844 | void set_health(int H); | |
845 | void set_pistolAmmo(int PA); | |
846 | void set_shotgunAmmo(int SA); | |
847 | void set_rifleAmmo(int RA); | |
848 | void set_score(int S); | |
849 | void set_money(int M); | |
850 | void set_items(int *I); | |
851 | void set_healthPacks(int HP); | |
852 | void set_turns(int T); | |
853 | ||
854 | int get_playerHealth(); | |
855 | int get_pistolAmmo(); | |
856 | int get_shotgunAmmo(); | |
857 | int get_rifleAmmo(); | |
858 | int get_score(); | |
859 | int get_money(); | |
860 | int *get_items(); | |
861 | int get_healthPacks(); | |
862 | int get_turns(); | |
863 | }; | |
864 | ||
865 | player::player(): playerHealth(100), pistolAmmo(9), shotgunAmmo(15), | |
866 | rifleAmmo(25), score(0), money(100), healthPacks(1), | |
867 | items(new int[4]), turns(1) | |
868 | { | |
869 | for(int i = 0; i < 4; ++i) | |
870 | { | |
871 | items[i] = 0; | |
872 | } | |
873 | } | |
874 | ||
875 | player::~player() | |
876 | { | |
877 | if(items) | |
878 | { | |
879 | delete[] items; | |
880 | } | |
881 | } | |
882 | ||
883 | void player::set_health(int H) | |
884 | { | |
885 | playerHealth = H; | |
886 | } | |
887 | ||
888 | void player::set_pistolAmmo(int PA) | |
889 | { | |
890 | pistolAmmo = PA; | |
891 | } | |
892 | ||
893 | void player::set_shotgunAmmo(int SA) | |
894 | { | |
895 | shotgunAmmo = SA; | |
896 | } | |
897 | ||
898 | void player::set_rifleAmmo(int RA) | |
899 | { | |
900 | rifleAmmo = RA; | |
901 | } | |
902 | ||
903 | void player::set_score(int S) | |
904 | { | |
905 | score = S; | |
906 | } | |
907 | ||
908 | void player::set_money(int M) | |
909 | { | |
910 | money = M; | |
911 | } | |
912 | ||
913 | void player::set_items(int *I) | |
914 | { | |
915 | items = I; | |
916 | } | |
917 | ||
918 | void player::set_healthPacks(int HP) | |
919 | { | |
920 | healthPacks = HP; | |
921 | } | |
922 | ||
923 | void player::set_turns(int T) | |
924 | { | |
925 | turns = T; | |
926 | } | |
927 | ||
928 | ||
929 | ||
930 | int player::get_playerHealth() | |
931 | { | |
932 | return playerHealth; | |
933 | } | |
934 | ||
935 | int player::get_pistolAmmo() | |
936 | { | |
937 | return pistolAmmo; | |
938 | } | |
939 | ||
940 | int player::get_shotgunAmmo() | |
941 | { | |
942 | return shotgunAmmo; | |
943 | } | |
944 | ||
945 | int player::get_rifleAmmo() | |
946 | { | |
947 | return rifleAmmo; | |
948 | } | |
949 | ||
950 | int player::get_score() | |
951 | { | |
952 | return score; | |
953 | } | |
954 | ||
955 | int player::get_money() | |
956 | { | |
957 | return money; | |
958 | } | |
959 | ||
960 | int *player::get_items() | |
961 | { | |
962 | return items; | |
963 | } | |
964 | ||
965 | int player::get_healthPacks() | |
966 | { | |
967 | return healthPacks; | |
968 | } | |
969 | ||
970 | int player::get_turns() | |
971 | { | |
972 | return turns; | |
973 | } | |
974 | ||
975 | #endif // PLAYER_H | |
976 | ||
977 | ||
978 | dinosaur.h | |
979 | ||
980 | #ifndef DINOSAUR_H_INCLUDED | |
981 | #define DINOSAUR_H_INCLUDED | |
982 | ||
983 | #include "player.h" | |
984 | ||
985 | /* | |
986 | ==============| | |
987 | Dinosaur Class| | |
988 | ==============| | |
989 | */ | |
990 | ||
991 | class dinosaur : public player | |
992 | { | |
993 | protected: | |
994 | int dinosaurHealth; | |
995 | int *attacks; | |
996 | ||
997 | public: | |
998 | void trex(); | |
999 | void velociraptor(); | |
1000 | void flags(); | |
1001 | void arena(); | |
1002 | dinosaur(); | |
1003 | ~dinosaur(); | |
1004 | ||
1005 | void set_dinosaurHealth(int DH); | |
1006 | void set_attacks(int *A); | |
1007 | ||
1008 | int get_dinosaurHealth(); | |
1009 | int *get_attacks(); | |
1010 | ||
1011 | }; | |
1012 | ||
1013 | dinosaur::dinosaur(): dinosaurHealth(100), attacks(new int[0]) | |
1014 | { | |
1015 | ||
1016 | } | |
1017 | ||
1018 | dinosaur::~dinosaur() | |
1019 | { | |
1020 | if(attacks) | |
1021 | delete[] attacks; | |
1022 | } | |
1023 | ||
1024 | void dinosaur::set_dinosaurHealth(int DH) | |
1025 | { | |
1026 | dinosaurHealth = DH; | |
1027 | } | |
1028 | ||
1029 | void dinosaur::set_attacks(int *A) | |
1030 | { | |
1031 | if(attacks) | |
1032 | delete[] attacks; | |
1033 | attacks = A; | |
1034 | } | |
1035 | ||
1036 | //-------------------------------------------- | |
1037 | ||
1038 | int dinosaur::get_dinosaurHealth() | |
1039 | { | |
1040 | return dinosaurHealth; | |
1041 | } | |
1042 | ||
1043 | int *dinosaur::get_attacks() | |
1044 | { | |
1045 | return attacks; | |
1046 | } | |
1047 | ||
1048 | #endif // DINOSAUR_H_INCLUDED |