-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain Game.cpp
1787 lines (1723 loc) · 102 KB
/
Main Game.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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <fstream>
#include <cstdlib>
#include "Map.h"
#include "User.h"
#include "LogBook.h"
#include "Crew.h"
#include "Planet.h"
using namespace std;
int split(string userString, char theDelimeter, string storageArr[], int capacity){ // this function return the amount of substring between seperators
int lengthStr =userString.length();
int counter = 0;
int j=0;
string container ="";
if (userString == ""){
return 0;
}
else{
for (int i= 0; i<lengthStr; i++){
if (counter < capacity){
if (userString[i] != theDelimeter ){
container = container + userString[i];
if (i == lengthStr-1 ){
storageArr[j] = container;
counter++;
}
}
else {
storageArr[j] = container;
container = "";
j++;
counter++;
}
}
else {
return -1;
}
}
if (counter == 0){
storageArr[0] = container;
return 1;
}
else{
return counter;
}
}
}
int main() {
//Phase 1:
bool test = true;
User person;
crew crewlist;
string username;
string ready;
string line;
int choice;
int money;
int mn;
int numWep;
int numHealth;
int diff;
int num;
string questions[86];
string split1[2];
string split2[4];
vector<string> aliens;
int left;
int death; // 0 = give up, 1 = No Health, 2 = No Fuel, 3 = All Humans Left
bool repeat = true;
bool rep;
int count = 0;
string wep;
logbook first;
first.setPageNumber(count+1);
vector<logbook> fullLog = {first};
ifstream fin("crewmates.txt");
if(fin.fail()) {
cout << "File not found" << endl;
} else {
char delimeter = ';';
string arraySplit[2];
int j = 0;
while(getline(fin, line)) {
split (line, delimeter,arraySplit, 2);
crewlist.setName(j, arraySplit[0]);
crewlist.setPerk(j, arraySplit[1]);
j++;
}
}
ifstream fin2("questions.txt");
if(fin2.fail()) {
cout << "Questions file not found" << endl;
}
int k = 0;
while(getline(fin2, line)) {
questions[k] = line;
k++;
}
ifstream alien("alien_names.txt");
if(alien.fail()) {
cout << "Alien names file not found" << endl;
}
while(getline(alien, line)) {
aliens.push_back(line);
}
cout << "Welcome to Space Exploration Game(tbd)! Enter your name to get started." << endl;
cin >> username;
person.setName(username);
cout << "Welcome " << person.getName() << "!" << endl;
cout << "Now pick a cremate to help you with your journey!" << endl;
cout << endl;
cout << "1. " << crewlist.getName(0) << endl;
cout << "Ability: " << crewlist.getPerk(0) << endl;
cout << "2. " << crewlist.getName(1) << endl;
cout << "Ability: " << crewlist.getPerk(1) << endl;
cout << "3. " << crewlist.getName(2) << endl;
cout << "Ability: " << crewlist.getPerk(2) << endl;
cout << "4. " << crewlist.getName(3) << endl;
cout << "Ability: " << crewlist.getPerk(3) << endl;
cout << endl;
cin >> choice;
while(cin.fail()) {
cout << "Insert a number as opposed to letters!"<<endl;
cin.clear();
cin.ignore();
cin >> choice;
} /// stops here
while(repeat == true) {
switch(choice) {
case 1:
person.setCrew(0, 1);
repeat = false;
break;
case 2:
person.setCrew(0, 2);
repeat = false;
break;
case 3:
person.setCrew(0, 3);
repeat = false;
break;
case 4:
person.setCrew(0, 4);
repeat = false;
break;
default:
cout << "Invalid Input. Please re-enter a valid option" << endl;
cin >> choice;
repeat = true;
break;
}
}
repeat = true;
cout << "Great choice! " << crewlist.getName(person.getCrew(0)-1) << " will bring a lot to your team. Pick another crewmate." << endl;
cout << endl;
if(choice != 1) {
cout << "1. " << crewlist.getName(0) << endl;
cout << "Ability: " << crewlist.getPerk(0) << endl;
}
if(choice != 2) {
cout << "2. " << crewlist.getName(1) << endl;
cout << "Ability: " << crewlist.getPerk(1) << endl;
}
if(choice != 3) {
cout << "3. " << crewlist.getName(2) << endl;
cout << "Ability: " << crewlist.getPerk(2) << endl;
}
if(choice != 4) {
cout << "4. " << crewlist.getName(3) << endl;
cout << "Ability: " << crewlist.getPerk(3) << endl;
}
cout << endl;
cin >> choice;
while(repeat == true) {
switch(choice) {
case 1:
person.setCrew(1, 1);
repeat = false;
break;
case 2:
person.setCrew(1, 2);
repeat = false;
break;
case 3:
person.setCrew(1, 3);
repeat = false;
break;
case 4:
person.setCrew(1, 4);
repeat = false;
break;
default:
cout << "Invalid Input. Please re-enter a valid option" << endl;
repeat = true;
break;
}
}
cout << "You have a very impressive crew. With your leadership, you will be sure to succeed!" << endl;
cout << endl;
cout << "WEAPONS. If your weapon breaks or if you lose your weapon during an event, you may need additional weapons to defend yourself!" << endl;
cout << "TRANSLATOR. Allows you to communicate with friendly aliens to get their assessment of the planet and increases odds of winning against a hostile alien." << endl;
cout << "SPACE SUIT. The better the spacesuit, the more durable and protective you will be during the mission and an alien attack." << endl;
cout << "MEDICAL KITS. The more kits you have, the more times you can revive your health by 40%." << endl;
cout << "FUEL. Fuel is an essential element for the spacecraft to travel to more planets." << endl;
cout << endl;
cout << "You can spend all of your money here before you start your journey, or you can save some to spend on different resources along the way. You will also gain money for each turn as you move through the game." << endl;
cout << endl;
cout << "Hit enter when you have understood" << endl;
cin.ignore();
string confirm;
do {
getline(cin, confirm);
} while(confirm.length()!= 0);
repeat = true;
while(repeat == true) {
cout << "Which item do you wish to buy?" << endl << "1. Weapon" << endl << "2. Space Suit" << endl;
cout << "3. Medical Kits" << endl << "4. Translator" << endl << "5. Fuel" << endl << "6. Purchase and Leave" << endl;
cout << endl;
cin >> choice;
while(cin.fail()) {
cout << "Insert a number as opposed to letters!"<<endl;
cin.clear();
cin.ignore();
cin >> choice;
} /// stops here
cout << endl;
switch(choice) {
case 1:
cout << "Which weapon type do you wish to buy?" << endl << "1. Light Saber" << endl;
cout << "2. Blaster" << endl << "3. Beam Gun" << endl << "4. Go back to menu" << endl;
cin >> choice;
while(repeat == true) {
switch(choice) {
case 1:
cout << "How many Light Sabres would you like ($1,000 each)?" << endl;
cin >> choice;
numWep = person.getWeapon(3);
while(repeat == true) {
if(choice<=(2 - numWep)) {
money = person.getMoney();
if(money < choice * 1000) {
cout << "You do not have enough funds to make this purchase. Your current balance is $" << money << endl;
} else {
person.setWeapon(0, to_string(choice));
person.setMoney(money-(1000*choice));
left = money-(1000*choice);
cout << "You have $"+ to_string(left) +" left."<< endl;
}
repeat = false;
} else if(choice < 1) {
cout << "Invalid Input. Please re-enter a valid quantity" << endl;
cin >> choice;
} else {
cout << "You cannot have more than two weapons at the same time" << endl;
repeat = false;
}
}
break;
case 2:
cout << "How many Blasters would you like ($2,000 each)?" << endl;
cin >> choice;
numWep = person.getWeapon(3);
while(repeat == true) {
if(choice<=(2-numWep)) {
money = person.getMoney();
if(money<(choice*2000)) {
cout << "You do not have enough funds to make this purchase. Your current balance is $" << money << endl;
} else {
person.setWeapon(1, to_string(choice));
person.setMoney(money-(2000*choice));
left = (money-(2000*choice));
cout<< "You have $"+to_string(left)+" left."<<endl;
}
repeat = false;
} else if(choice<1) {
cout << "Invalid Input. Please re-enter a valid quantity" << endl;
cin >> choice;
} else {
cout << "You cannot have more than two weapons at the same time" << endl;
repeat = false;
}
}
break;
case 3:
cout << "How many Beam Guns would you like ($5,000 each)?" << endl;
cin >> choice;
numWep = person.getWeapon(3);
while(repeat == true) {
if(choice<=(2-numWep)) {
money = person.getMoney();
if(money<(choice*5000)) {
cout << "You do not have enough funds to make this purchase. Your current balance is $" << money << endl;
} else {
person.setWeapon(2, to_string(choice));
person.setMoney(money-(5000*choice));
left = (money-(5000*choice));
cout<< "You have $"+to_string(left)+" left."<<endl;
}
repeat = false;
} else if(choice<1) {
cout << "Invalid Input. Please re-enter a valid quantity" << endl;
cin >> choice;
} else {
cout << "You cannot have more than two weapons at the same time" << endl;
repeat = false;
}
}
break;
case 4:
repeat = false;
break;
default:
cout << "Invalid Input. Please re-enter a valid option" << endl;
repeat = true;
break;
}
}
repeat = true;
break;
case 2:
cout << "Would you like to upgrade your spacesuit to any of these? The space suit health will be set to 100%." << endl;
cout << "1. Space Suit T2 is $5,000" << endl << "2. Space Suit T3 is $10,000" << endl;
cout << "3. Space Suit T4 is $15,000" << endl << "4. Space Suit T5 is $20,000" << endl << "5. Return to menu" << endl;
cin >> choice;
while(repeat == true) {
switch(choice) {
case 1:
money = person.getMoney();
if(money<5000) {
cout << "You do not have enough funds to make this purchase. Your current balance is $" << money << endl;
} else {
person.setSuitGrade(choice);
person.setMoney(money-5000);
person.setSuitHealth(100);
left = (money-5000);
cout<<"Your spacesuit is now a grade 2."<<endl;
cout<< "You have $ "+to_string(left)+" left."<<endl;
}
repeat = false;
break;
case 2:
money = person.getMoney();
if(money<10000) {
cout << "You do not have enough funds to make this purchase. Your current balance is $" << money << endl;
} else {
person.setSuitGrade(choice);
person.setSuitHealth(100);
person.setMoney(money-10000);
left = (money-10000);
cout<<"Your spacesuit is now a grade 3."<<endl;
cout<< "You have $ "+to_string(left)+" left."<<endl;
}
repeat = false;
break;
case 3:
money = person.getMoney();
if(money<15000) {
cout << "You do not have enough funds to make this purchase. Your current balance is $" << money << endl;
} else {
person.setSuitGrade(choice);
person.setSuitHealth(100);
person.setMoney(money-15000);
left = (money-15000);
cout<<"Your spacesuit is now a grade 4."<<endl;
cout<< "You have $ "+to_string(left)+" left."<<endl;
}
repeat = false;
break;
case 4:
money = person.getMoney();
if(money<20000) {
cout << "You do not have enough funds to make this purchase. Your current balance is $" << money << endl;
} else {
person.setSuitGrade(choice);
person.setSuitHealth(100);
person.setMoney(money-20000);
left = (money-20000);
cout<<"Your spacesuit is now a grade 5."<<endl;
cout<< "You have $ "+to_string(left)+" left."<<endl;
}
repeat = false;
break;
case 5:
repeat = false;
break;
}
}
repeat = true;
break;
case 3: {
cout << "How many medical kits would you like to purchase ($2,000)?" << endl;
cin >> choice;
numHealth = person.getHealthKits();
while(repeat == true) {
if(choice<=(5-numHealth)) {
money = person.getMoney();
if(money<2000*choice) {
cout << "You do not have enough funds to make this purchase. Your current balance is $" << money << endl;
} else {
person.setHealthKits(choice);
person.setMoney(money-(2000*choice));
left = (money-(2000*choice));
cout<< "You have $"<<to_string(left)<<" left."<<endl;
}
repeat = false;
} else if(choice<1) {
cout << "Invalid input. Please re-enter a valid quantity" << endl;
cin >> choice;
} else {
cout << "You cannot have more than 5 kits. Re-enter a valid quantity." << endl;
cin >> choice;
}
}
repeat = true;
break;
}
case 4:
if(!(person.getTranslator())) {
cout << "Would you like to purchase a translator device ($5,000)? 1 for yes, 0 for no." << endl;
cin >> choice;
while(repeat == true) {
if(choice == 1) {
money = person.getMoney();
if(money<5000) {
cout << "You do not have enough funds to make this purchase. Your current balance is $" << money << endl;
} else {
person.setTranslator(true);
person.setMoney(money-5000);
left = (money-5000);
cout<< "You have $"<<to_string(left)<<" left."<<endl;
}
repeat = false;
} else if(choice == 0) {
cout << "Okay, come back if you ever find yourself needing it!" << endl;
} else {
cout << "Invalid input. Please re-enter a valid quantity" << endl;
cin >> choice;
}
}
repeat = true;
} else {
cout << "You already have one" << endl;
cout << endl;
}
break;
case 5:
if(person.getCrew(0) == 3 || person.getCrew(1) == 3) {
person.setFuel(400000);
}
cout << "You have " << person.getFuel() << " gallons of fuel. Your spacecraft can hold 400k gallons of fuel.";
if(person.getFuel()==400000) {
cout << endl;
cout << "You already have the max amount of fuel." << endl;
break;
}
cout << " How many gallons would you like to purchase ($1,000 per 10,000 gallons)? Input must be in multiples of 10000s." << endl;
cin >> choice;
while(repeat == true) {
if(choice%10000!=0) {
cout << "Input must be in multiples of 10000s. Please re-enter a valid quantity" << endl;
cin >> choice;
} else if(choice<10000) {
cout << "Invalid Input. Please re-enter a valid multiple of 10000" << endl;
cin >> choice;
} else if(choice>400000-person.getFuel()) {
cout << "You cannot buy more fuel than the fuel tank's capacity, which is 400K. Please re-enter a valid input" << endl;
cin >> choice;
} else {
money = person.getMoney();
if(money<(choice/10)) {
cout << "You do not have enough funds to make this purchase. Your current balance is $" << money << endl;
cout << "Please re-enter a valid quantity" << endl;
cin >> choice;
} else {
int fuel = person.getFuel();
person.setFuel(choice+fuel);
person.setMoney(money-(choice/10));
left = (money-(choice/10));
cout<< "You have $"<<to_string(left)<<" left."<<endl;
repeat = false;
}
}
}
repeat = true;
break;
case 6:
cout << "Great purchases, Elon is sending a Cybertruck with your supplies to you right now" << endl;
repeat = false;
break;
default:
cout << "Invalid Input. Please re-enter a valid option" << endl;
choice = 0;
break;
}
}
cout << endl;
cout << "Hit enter when you are ready to go to your first planet" << endl;
cin.ignore();
do {
getline(cin, confirm);
} while(confirm.length()!= 0);
cout << "3... 2... 1... LIFTOFF! You are now in space. Press enter to start exploring your first planet" << endl;
cin.ignore();
do {
getline(cin, confirm);
} while(confirm.length()!= 0);
//getch();
//cin.get();
//Phase 2: ///////
//generate new planet and map
planet nextPlanet;
/// create map
/// spawn all the needed site,misfortune, npc on the map
Map currentMap; //
person.setFuel(person.getFuel()-50000);
int siteNum = rand()%6 + 1;
for(int i=0; i<siteNum; i++){
int newRow = rand()%12;
int newCol = rand()%12;
int typerand = rand()%6 + 1;
bool outcome = currentMap.spawnSite(newRow,newCol, typerand);
if(outcome == false){ // false means spot alredy taken
siteNum++;
}
}
int misfortuneNum = rand()%8 + 1;
for(int i=0; i<misfortuneNum; i++){
int newRow = rand()%12;
int newCol = rand()%12;
int typerand = rand()%4 + 1;
bool outcome = currentMap.spawnMisfortune(newRow,newCol,typerand);
if(outcome == false){ // false means spot alredy taken
misfortuneNum++;
}
}
int numNpc = 1;
for(int i=0; i<numNpc; i++){
int newRow = rand()%12;
int newCol = rand()%12;
bool outcome = currentMap.spawnNPC( newRow,newCol);
if(outcome == false){ // false means spot alredy taken
numNpc++;
}
}
repeat = true;
while(repeat == true) {
cout << endl;
cout << "Planet: " << fullLog[count].getPlanet().getName() << endl; // gets the planets name
currentMap.displayMap(); //Map print
cout << "Select one:" << endl << "1. Move" << endl << "2. View status" << endl << "3. View log book" << endl << "4. Resource center" << endl;
cout << "5. Report planet as habitable" << endl << "6. Enter wormhole to next planet" << endl << "7. Give up" << endl;
cin >> choice;// HEREREREERRERR
while(cin.fail()) {
cout << "Insert a number as opposed to letters!"<<endl;
cin.clear();
cin.ignore();
cin >> choice;
} /// stops here
switch(choice) {
case 1:
while(repeat == true) {
cout << endl;
cout << "Planet: " << fullLog[count].getPlanet().getName() << endl;
currentMap.displayMap(); //print map again
cout << "Select one: w. up s. down d. right a. left m. menu" << endl;
cin >> ready;
bool result;
if(ready == "w") {
result = currentMap.executeMove('w');
if(result == false){
cout<<"outside the range of the map!"<<endl;
}
} else if(ready == "s") {
bool result2 = currentMap.executeMove('s');
if(result2 == false){
cout<<"outside the range of the map!"<<endl;
}
} else if(ready == "d") {
bool result3 = currentMap.executeMove('d');
if(result3 == false){
cout<<"outside the range of the map!"<<endl;
}
} else if(ready == "a") {
bool result4 = currentMap.executeMove('a');
if(result4 == -1){
cout<<"outside the range of the map!"<<endl;
}
} else if(ready == "m") {
//repeat = false;
break;
} else {
cout << "Invalid Input. Please enter a valid option" << endl;
continue;
}
cout << endl;
mn = person.getMoney();
person.setMoney(mn+50);
repeat = true;
if(currentMap.isMisfortuneLocation() == true) {
int MisfortuneType = currentMap.getMisfortuneType();
if(MisfortuneType == 1){
money = person.getMoney();
int rd = rand()%aliens.size();
numWep = person.getWeapon(3);
string alienName = aliens[rd];
aliens.erase(aliens.begin()+rd-1);
cout << "You just ran into " << alienName << "! Think you can beat this dangerous alien to help save humanity?" << endl;
cout << "1. Attack" << endl;
cout << "2. Forefit" << endl;
cin >> choice;
while(repeat = true) {
switch(choice) {
case 1:
if(numWep<1) {
if(money<1000) {
cout << "You neither have a weapon nor enough money to buy a weapon. Consequently, the alien attacked and defeated you :(" << endl;
repeat = false;
break;
} else {
repeat = true;
while(repeat == true) {
cout << "You do not have a weapon to fight! Lets visit the resource center and buy a weapon!" << endl;
cout << "Which weapon type do you wish to buy?" << endl << "1. Light Saber" << endl;
cout << "2. Blaster" << endl << "3. Beam Gun" << endl;
cin >> choice;
switch(choice) {
case 1:
cout << "How many Light Sabres would you like ($1,000 each)?" << endl;
cin >> choice;
numWep = person.getWeapon(3);
while(repeat == true) {
if(choice<=(2 - numWep)) {
money = person.getMoney();
if(money < choice * 1000) {
cout << "You do not have enough funds to make this purchase. Your current balance is $" << money << endl;
} else {
person.setWeapon(0, to_string(choice));
person.setMoney(money-(1000*choice));
cout<< "You have $" << money-(1000*choice) << " left."<<endl;
repeat = false;
break;
}
repeat = false;
} else if(choice < 1) {
cout << "Invalid Input. Please re-enter a valid quantity" << endl;
cin >> choice;
} else {
cout << "You cannot have more than two weapons at the same time, re-enter a valid quantity." << endl;
cin >> choice;
}
}
break;
case 2:
cout << "How many Blasters would you like ($2,000 each)?" << endl;
cin >> choice;
numWep = person.getWeapon(3);
while(repeat = true) {
if(choice<=(2-numWep)) {
money = person.getMoney();
if(money<(choice*2000)) {
cout << "You do not have enough funds to make this purchase. Your current balance is $" << money << endl;
} else {
person.setWeapon(1, to_string(choice));
person.setMoney(money-(2000*choice));
cout<< "You have $" << (money-(2000*choice)) << " left."<<endl;
repeat = false;
break;
}
repeat = false;
} else if(choice<1) {
cout << "Invalid Input. Please re-enter a valid quantity" << endl;
cin >> choice;
} else {
cout << "You cannot have more than two weapons at the same time, re-enter a valid quantity." << endl;
cin >> choice;
}
}
break;
case 3:
cout << "How many Beam Guns would you like ($5,000 each)?" << endl;
cin >> choice;
numWep = person.getWeapon(3);
while(repeat = true) {
if(choice<=(2-numWep)) {
money = person.getMoney();
if(money<choice*5000) {
cout << "You do not have enough funds to make this purchase. Your current balance is $" << money << endl;
} else {
person.setWeapon(2, to_string(choice));
person.setMoney(money-(5000*choice));
cout<< "You have $" << (money-(5000*choice)) << " left."<<endl;
repeat = false;
break;
}
repeat = false;
} else if(choice<1) {
cout << "Invalid Input. Please re-enter a valid quantity" << endl;
cin >>choice;
} else {
cout << "You cannot have more than two weapons at the same time, re-enter a valid quantity." << endl;
cin >> choice;
}
}
break;
default:
cout << "Invalid Input. Please re-enter a valid option" << endl;
repeat = true;
break;
}
}
}
cout << "Let’s attack! Choose a weapon from your arsenal quickly and attack before the enemy advances!" << endl;
if(person.getWeapon(0)>0) {
cout << "1. Light Saber" << endl;
}
if(person.getWeapon(1)>0) {
cout << "2. Blaster" << endl;
}
if(person.getWeapon(2)>0) {
cout << "3. Beam Gun" << endl;
}
cin >> choice;
rep = true;
int r1 = 1+rand()%6;
int r2 = 1+rand()%6;
int fight;
while(rep == true) {
switch(choice) {
case 1:
if(person.getWeapon(0)>0) {
cout << "Invalid input, Please re-enter a valid option" <<endl;
cin >> choice;
} else {
if(person.getCrew(0) == 2||person.getCrew(1) == 2) {
fight = (r1 * 1)*(1 + 1) - (r2 * person.getNumExplored());
} else {
fight = (r1 * 1)*(1 + 0) - (r2 * person.getNumExplored());
}
rep = false;
}
break;
case 2:
if(person.getWeapon(1)>0) {
cout << "Invalid input, Please re-enter a valid option" <<endl;
cin >> choice;
} else {
if(person.getCrew(0) == 2||person.getCrew(1) == 2) {
fight = (r1 * 2)*(1 + 1) - (r2 * person.getNumExplored());
} else {
fight = (r1 * 2)*(1 + 0) - (r2 * person.getNumExplored());
}
rep = false;
}
break;
case 3:
if(person.getWeapon(2)>0) {
cout << "Invalid input, Please re-enter a valid option" <<endl;
cin >> choice;
} else {
if(person.getCrew(0) == 2||person.getCrew(1) == 2) {
fight = (r1 * 3)*(1 + 1) - (r2 * person.getNumExplored());
} else {
fight = (r1 * 3)*(1 + 0) - (r2 * person.getNumExplored());
}
rep = false;
}
break;
default:
cout << "Invalid input, Please re-enter a valid option" <<endl;
cin >> choice;
break;
}
}
numWep = person.getWeapon(3);
if(fight>0) {
if(numWep == 2) {
cout << "You defeated " << alienName << "! Great Job! You saw the enemy's weapon lying down but you cannot carry with you as you already have 2 weapons. Unfortunately, you lost 10% of space suit health while fighting." << endl;
int h = person.getHealth();
if(person.getCrew(0) == 2||person.getCrew(1) == 2) {
person.setHealth(h-5);
cout << "Thanks to your doctor Lola, you gained back 5% Health." << endl;
} else {
person.setHealth(h-10);
}
} else {
int r3 = rand()%3;
if(r3 == 0) {
wep = "Light Saber";
} else if(r3 == 1) {
wep = "Blaster";
} else {
wep = "Beam Gun";
}
cout << "You defeated " << alienName << "! Great Job! You won a " << wep<< ". But you lost 10% of space suit health while fighting." << endl;
int h = person.getHealth();
person.setHealth(h-10);
}
} else {
cout << "Aggh! You lost the battle! "<<alienName<<" seems to be hard for you! Tough times. Unfortunately, you experience the following due to this loss:" << endl;
cout << "1. Your health was decreased by 30%." << endl;
int h = person.getHealth();
if(person.getCrew(0) == 2||person.getCrew(1) == 2) {
person.setHealth(h-5);
cout << "Thanks to your doctor Lola, you gained back 5% Health." << endl;
} else {
person.setHealth(h-30);
}
int sh = 100-20*person.getSuitGrade();
cout << "2. Your suit health was decreased by " << sh << "%" << endl;
int suith = person.getSuitHealth();
person.setSuitHealth(suith-sh);
if(choice == 1) {
wep = "Light Saber";
num = person.getWeapon(0);
person.setWeapon(0, to_string(num-1));
} else if(choice == 2) {
wep = "Blaster";
num = person.getWeapon(1);
person.setWeapon(1, to_string(num-1));
} else if(choice == 3){
wep = "Beam Gun";
num = person.getWeapon(2);
person.setWeapon(2, to_string(num-1));
}
cout << "3. You lost " << wep << ", the weapon you used for attacking the alien." << endl;
}
if(person.getHealth()<=0||person.getSuitHealth()<=0) {
death = 1;
}
}
break;
case 2:
numWep = person.getWeapon(3);
if(numWep>0) {
cout << "Really?! You chose to forfeit the battle? This is disappointing! You lost a weapon due to this decision. Hopefully, you git gud before you encounter the next alien." << endl;
srand(time(NULL));
diff = rand()%3;
if(diff = 0) {
num = person.getWeapon(diff);
person.setWeapon(diff, to_string(num-1));
} else if(diff == 1) {
num = person.getWeapon(diff);
person.setWeapon(diff, to_string(num-1));
} else if(diff == 2) {
num = person.getWeapon(diff);
person.setWeapon(diff, to_string(num-1));
}
} else {
cout << "Really?! You chose to forfeit the battle? This is disappointing! Since you do not have a weapon, you just lost a huge chunk of money from your account. Hopefully, you git gud before you encounter the next alien." << endl;
if(money<=10000) {
person.setMoney(0);
} else {
person.setMoney(money-10000);
}
}
repeat = false;
break;
default:
cout << "Invalid input, Please re-enter a valid option" << endl;
cin >> choice;
break;
}
}
cout << endl << endl;
}
else if(MisfortuneType == 2){
int helathNow = person.getHealth();
int calculatedBody = helathNow-10; // the health of player after calculating
person.setHealth(helathNow-10); ///if event caused him death it should terminate program
int suitNow = person.getSuitHealth();
int calculatedHealth = suitNow - (50 - (10*person.getSuitGrade())) ;
person.setSuitHealth(calculatedHealth);
cout<<"Oh no! You encountered Weather storm. Your health decreased by 10%."<<endl;
if(calculatedHealth ==0||calculatedBody==0){ //check if either suit or body are 0 and end game
repeat = true;
death = 1;
}
cout << endl << endl;
}
else if(MisfortuneType == 3){
int helathyou = person.getHealth();
person.setHealth(helathyou-50);
int calculatedBody = helathyou-50;
int calculatedHealth = person.getSuitHealth() - (50 - (10*person.getSuitGrade())) ;
person.setSuitHealth(calculatedHealth);
cout<<"Oh no! You Fell into a crater. Your health decreased by 50%."<<endl;
if(calculatedHealth ==0||calculatedBody==0){ //check if either suit or body are 0 and end game
repeat = true;
death = 1;
}
cout << endl << endl;
}
else if(MisfortuneType == 4){
int healthy = person.getHealth();
person.setHealth(healthy-30);
int calculatedBody = healthy-30;
cout<<"Oh no! You have space sickness. Your health decreased by 30%."<<endl;
if(calculatedBody==0){ //check if either suit or body are 0 and end game
repeat = true;
death = 1;
}
}
currentMap.revealMisfortune(currentMap.getPlayerRowPosition(),currentMap.getPlayerColPosition()); //might need to use getPlayerColPosition() as parameter
if(death == 1) {
repeat = false;
break;
}
} else if (currentMap.isNPCLocation()) {
cout<<"You have run into a friendly alien!"<<endl;
if(person.getTranslator()==false){
cout<<"You do not have a translator and cannot communicate with this alien. This alien may have useful information for you or money to offer, you can purchase a translator from the store if you would like to talk to them."<<endl;
repeat = true;
break;
}
else{
bool rep = true;
while(rep){
char order;
cout<<"You can communicate with this alien. You can defeat them in rock, paper, scissors three times and gain $200 (c) or you can ask them about the habitability of this planet (a). The chance of the alien telling the truth is 70%. You can only pick one option."<<endl;
cin>>order;
if(order == 'c'){
char play;
char toolsPlay[3]= {'r','p','s'};
string toolsNames[3]= {"rock","paper","scissors"};
int keepScore = 0;
for(int i =0; i<3;i++){
cout<<"Choose: rock(r), paper(p) or scissors(s)"<<endl;
cin>>play;
if(play == 'r' ||play=='p'||play=='s'){
srand(time(NULL));
int nums = rand()%3; // the random number to choose from array of r,p,s for alien
cout<<"The alien chose "+toolsNames[nums]<<endl;
if(toolsPlay[nums] == 's' && play=='p' ){
cout<<"You lose this round"<<endl;
keepScore--;
}
else if(toolsPlay[nums] == 'p' && play=='r' ){
cout<<"You lose this round"<<endl;
keepScore--;
}
else if(toolsPlay[nums] == 'r' && play=='s' ){
cout<<"You lose this round"<<endl;
keepScore--;
}
else if(toolsPlay[nums] == 'r' && play=='p' ){
cout<<"You win this round"<<endl;
keepScore++;
}
else if(toolsPlay[nums] == 'p' && play=='s' ){
cout<<"You win this round"<<endl;
keepScore++;
}
else if(toolsPlay[nums] == 's' && play=='r' ){
cout<<"You win this round"<<endl;
keepScore++;
}
else if (toolsPlay[nums] ==play){
cout<<"You tied this round"<<endl;
i--;
}
}
else{
cout<<"Invalid input"<<endl;