-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriver.cpp
More file actions
1260 lines (1027 loc) · 41.8 KB
/
driver.cpp
File metadata and controls
1260 lines (1027 loc) · 41.8 KB
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 "player.h"
#include "monster.h"
#include "weapon.h"
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <cstdlib>
#include <time.h>
#include <unistd.h>
using namespace std;
// This function takes user input(from choices) and returns a monster
Monster chooseMonster(int choice)
{
//defiene monsters' details
Monster Rathian = Monster("Rathian", "throat", 100, 4, 20, 340);
Monster Cavesnake = Monster("Cavesnake", "head", 120, 9, 30, 450);
Monster Grieveling = Monster("Grieveling", "legs", 140, 9, 40, 550);
Monster Mistclaw = Monster("Mistclaw", "eyes", 250, 10, 50, 740);
Monster Steammorph = Monster("Steammorph", "stomach", 290, 11, 60, 880);
Monster Abyssbrood = Monster("Abyssbrood", "arms", 340, 12, 100, 930);
Monster Cavernghoul = Monster("Cavernghoul", "head", 480, 15, 120, 1500);
Monster Phasetaur = Monster("Phasetaur", "legs", 550, 17, 150, 2200);
Monster Netherflayer = Monster("Netherflayer", "eyes", 600, 18, 200, 3300);
Monster Phantomcreep = Monster("Phantomcreep", "legs", 1400, 30, 500, 4500);
Monster ret; // return value
if(choice == 11) // if user choses random, then set choice to a random number between 1-10
{
srand(time(NULL));
choice = rand() % 10 + 1;
}
if(choice == 1)
ret = Rathian;
else if(choice == 2)
ret = Cavesnake;
else if(choice == 3)
ret = Grieveling;
else if(choice == 4)
ret = Mistclaw;
else if(choice == 5)
ret = Steammorph;
else if(choice == 6)
ret = Abyssbrood;
else if(choice == 7)
ret = Cavernghoul;
else if(choice == 8)
ret = Phasetaur;
else if(choice == 9)
ret = Netherflayer;
else if(choice == 10)
ret = Phantomcreep;
return ret;
}
//This function prints the details of monsters.
void printMonsterDetails()
{
int choice = 0;
bool loop = true;
while(loop)
{
cout << endl;
cout << "[*] Enter a number of monster you'd like to check\n" << endl;
cout << "[0] Exit" << endl;
cout << "[1] Rathian" << endl;
cout << "[2] Cavesnake" << endl;
cout << "[3] Grieveling" << endl;
cout << "[4] Mistclaw" << endl;
cout << "[5] Steammorph" << endl;
cout << "[6] Abyssbrood" << endl;
cout << "[7] Cavernghoul" << endl;
cout << "[8] Phasetaur" << endl;
cout << "[9] Netherflayer" << endl;
cout << "[10] Phantomcreep" << endl;
cout << "\n>> ";
cin >> choice;
cout << "\n";
if(choice == 0)
{
loop = false;
break;
}
if(choice < 0 || choice > 10)
cout << "[-] Invalid input" << endl;
else if(choice == 1)
{
cout << "==================" << endl;
cout << "Name: Rathian" << endl;
cout << "Weakness: Throat" << endl;
cout << "Reward: $20" << endl;
cout << "==================" << endl;
}
else if(choice == 2)
{
cout << "==================" << endl;
cout << "Name: Cavesnake" << endl;
cout << "Weakness: head" << endl;
cout << "Reward: $30" << endl;
cout << "==================" << endl;
}
else if(choice == 3)
{
cout << "==================" << endl;
cout << "Name: Grieveling" << endl;
cout << "Weakness: legs" << endl;
cout << "Reward: $40" << endl;
cout << "==================" << endl;
}
else if(choice == 4)
{
cout << "==================" << endl;
cout << "Name: Mistclaw" << endl;
cout << "Weakness: eyes " << endl;
cout << "Reward: $50" << endl;
cout << "==================" << endl;
}
else if(choice == 5)
{
cout << "==================" << endl;
cout << "Name: Steammorph" << endl;
cout << "Weakness: stomach " << endl;
cout << "Reward: $60" << endl;
cout << "==================" << endl;
}
else if(choice == 6)
{
cout << "==================" << endl;
cout << "Name: Abyssbrood" << endl;
cout << "Weakness: arms" << endl;
cout << "Reward: $100" << endl;
cout << "==================" << endl;
}
else if(choice == 7)
{
cout << "==================" << endl;
cout << "Name: Cavernghoul" << endl;
cout << "Weakness: head" << endl;
cout << "Reward: $120" << endl;
cout << "==================" << endl;
}
else if(choice == 8)
{
cout << "==================" << endl;
cout << "Name: Phasetaur" << endl;
cout << "Weakness: legs" << endl;
cout << "Reward: $150" << endl;
cout << "==================" << endl;
}
else if(choice == 9)
{
cout << "==================" << endl;
cout << "Name: Netherflayer" << endl;
cout << "Weakness: eyes" << endl;
cout << "Reward: $200" << endl;
cout << "==================" << endl;
}
else if(choice == 10)
{
cout << "==================" << endl;
cout << "Name: Phantomcreep" << endl;
cout << "Weakness: legs" << endl;
cout << "Reward: $500" << endl;
cout << "==================" << endl;
}
}
}
Player weaponShop(Player player)
{
// works under a loop which keeps looping until user choses to quit
/* option 1
1) prints all the weapon along with the current money balance using getMoney().
2) takes input from user to choose which weapon to buy if balance is not enough, then user won't be able to buy it
3) subtract the amount of money cost from the balance
4) set the purchased weapon to the Weapons using setWeapon()
*/
Weapon greatSword("GreatSword", 200, 12);
Weapon longSword("LongSword", 450, 30);
Weapon axe("Axe", 600, 42);
Weapon bow("Bow", 900, 53);
Weapon bowgun("Bowgun", 1200, 90);
Weapon dualBlades("DualBlades", 2800, 120);
Weapon hammer("Hammer", 4500, 390);
Weapon lance("Lance", 6800, 970);
int choice = 0;
int choice1 = 0;
int choice2 = 0;
int choice3 = 0;
bool sell = true;
while(choice != 5)
{
choice = 0;
choice1 = 0;
choice2 = 0;
choice3 = 0;
cout << "\n===========================" << endl;
cout << "Welcome to the weapon shop!" << endl;
cout << "===========================" << endl;
cout << "[*] Money Balance: $" << player.getMoney() << endl << endl;
cout << "[1] See weapons" << endl;
cout << "[2] Sell weapons" << endl;
cout << "[3] Buy a weapon/potion" << endl;
cout << "[4] Get a box" << endl;
cout << "[5] Exit shop" << endl;
cout << "\n>> ";
cin >> choice;
cout << endl;
if(choice > 5 || choice < 0)
cout << "[-] Invalid option" << endl;
if(choice == 1) // see weapons
{
while(choice1 != 9)
{
cout << "\n[*] Enter a number to see details\n" << endl;
cout << "[1] GreatSword" << endl;
cout << "[2] LongSword" << endl;
cout << "[3] Axe" << endl;
cout << "[4] Bow" << endl;
cout << "[5] Bowgun" << endl;
cout << "[6] DualBlades" << endl;
cout << "[7] Hammer" << endl;
cout << "[8] Lance" << endl;
cout << "[9] Healing Potion" << endl;
cout << "[10] Shop menu" << endl;
cout << "\n>> ";
cin >> choice1;
if(choice1 < 0 || choice1 > 10 || choice == 0)
cout << "\n[-] Invalid input" << endl;
if(choice1 == 10)
break;
else
{
switch(choice1) // weapon details
{
case 1:
cout << "==========" << endl;
cout << "GreatSword\nPrice: $200\nPower: 12 " << endl;
cout << "==========" << endl;
break;
case 2:
cout << "==========" << endl;
cout << "LongSword\nPrice: $450\nPower: 30" << endl;
cout << "==========" << endl;
break;
case 3:
cout << "==========" << endl;
cout << "Axe\nPrice: $600\nPower: 42" << endl;
cout << "==========" << endl;
break;
case 4:
cout << "==========" << endl;
cout << "Bow\nPrice: $900\nPower: 53" << endl;
cout << "==========" << endl;
break;
case 5:
cout << "==========" << endl;
cout << "Bowgun\nPrice: $1200\nPower: 90" << endl;
cout << "==========" << endl;
break;
case 6:
cout << "==========" << endl;
cout << "DualBlades\nPrice: $2800\nPower: 120" << endl;
cout << "==========" << endl;
break;
case 7:
cout << "==========" << endl;
cout << "Hammer\nPrice: $4500\nPower: 390" << endl;
cout << "==========" << endl;
break;
case 8:
cout << "==========" << endl;
cout << "Lance\nPrice: $6800\nPower: 970" << endl;
cout << "==========" << endl;
break;
case 9:
cout << "==========" << endl;
cout << "Potion\nPrice: $20\nHeal: 20HP" << endl;
cout << "==========" << endl;
break;
}
}
} // end of loop
} // end of option 1
else if(choice == 2) // sell weapons
{
while(sell)
{
int num = 0;
Weapon weapon;
int numWeapons = player.getWeaponCount(); //the num of weapons player has
cout << "=======================" << endl;
cout << "Inventory - Name: Price" << endl;
cout << "=======================" << endl;
cout << "[*] Enter a number to sell a weapon" << endl;
if(numWeapons == 0)
cout << "[-] You don't have any weapons" << endl;
cout << "\n[0] Menu" << endl;
for (int i = 0; i < numWeapons; i++) // display all the weapons player has
{
weapon = player.getWeapon(i);
cout << "[" << i+1 << "] " << weapon.getName() << ": $" << weapon.getPrice() << endl;
}
cout << "\n>> ";
cin >> num;
if(num == 0)
break;
if(num > numWeapons || num < 0) // checks that user input is correct
{
cout << "\n[-] Invalid input\n" << endl;
}
else // if user enters a correct number
{
// if the number of weapons user has is just 1, then it doesn't let user sell it
string choice = "";
weapon = player.getWeapon(num -1);
int price = weapon.getPrice();
Weapon swap;
cout << "\n[*] Are you sure you want to sell " << weapon.getName() << " for $" << price << "? (y/n)" << endl << endl;
cout << ">> ";
cin >> choice;
if(choice == "y" || choice == "Y")
{
if(numWeapons != 1) // prevents from selling all weapons, so use will have at least 1 weapon in the inventory
{
int loop = numWeapons - num; // the number of times it loops
for (int i = 0; i < loop; i++)
{
swap = player.getWeapon(num + i); // set the weapon that's stored at the next index to the swap
player.setWeaponSell(swap, num+i-1); //delete the weapon user chose
}
player.decreaseWeaponsCount(1); // decrease it by 1
player.setMoney(player.getMoney() + price); //give money back to user
cout << "\n[+] Success, You earned $" << price << endl << endl;
}
else
{
cout << "\n[-] You need to have at least 1 weapon\n" << endl;
}
}
else if(choice == "n" || choice == "N")
{
// do nothing
}
else
cout << "Invalid input" << endl;
}
}// end of the loop
}
else if(choice == 3) // buy a weapon
{
while(choice2 != 9)
{
cout << "======================" << endl;
cout << "[1] Great Sword: $200" << endl;
cout << "[2] Long Sword: $450" << endl;
cout << "[3] Axe: $600" << endl;
cout << "[4] Bow: $900" << endl;
cout << "[5] Bowgun: $1200" << endl;
cout << "[6] Dual Blades: $2800" << endl;
cout << "[7] Hammer: $4500" << endl;
cout << "[8] Lance: $6800" << endl;
cout << "[9] Healing Potion $20" << endl;
cout << "[10] Shop menu" << endl;
cout << "======================" << endl;
cout << "\n[*] Money Balance: $" << player.getMoney() << endl;
cout << "[*] Enter the number of the item you'd like to purchase" << endl;
cout << "\n>> ";
cin >> choice2;
if(choice2 == 1 && player.getMoney() >= 200) //checks that player has enough money
{
player.setWeapon(greatSword); //sets weapon
player.setMoney(player.getMoney() - 200); // subtract the price from player's balance
cout << "\n[+] Success, GreatSword has been added to your inventory" << endl;
break;
}
else if(choice2 == 2 && player.getMoney() >= 450)
{
player.setWeapon(longSword);
player.setMoney(player.getMoney() - 450);
cout << "\n[+] Success, LongSword has been added to your inventory" << endl;
break;
}
else if(choice2 == 3 && player.getMoney() >= 600)
{
player.setWeapon(axe);
player.setMoney(player.getMoney() - 600);
cout << "\n[+] Success, Axe has been added to your inventory" << endl;
break;
}
else if(choice2 == 4 && player.getMoney() >= 900)
{
player.setWeapon(bow);
player.setMoney(player.getMoney() - 900);
cout << "\n[+] Success, Bow has been added to your inventory" << endl;
break;
}
else if(choice2 == 5 && player.getMoney() >= 1200)
{
player.setWeapon(bowgun);
player.setMoney(player.getMoney() - 1200);
cout << "\n[+] Success, Bowgun has been added to your inventory" << endl;
break;
}
else if(choice2 == 6 && player.getMoney() >= 2800)
{
player.setWeapon(dualBlades);
player.setMoney(player.getMoney() - 2800);
cout << "\n[+] Success, DualBlades has been added to your inventory" << endl;
break;
}
else if(choice2 == 7 && player.getMoney() >= 4500)
{
player.setWeapon(hammer);
player.setMoney(player.getMoney() - 4500);
cout << "\n[+] Success, Hammer has been added to your inventory" << endl;
break;
}
else if(choice2 == 8 && player.getMoney() >= 6800)
{
player.setWeapon(lance);
player.setMoney(player.getMoney() - 6800);
cout << "\n[+] Success, Lance has been added to your inventory" << endl;
break;
}
else if(choice2 == 9)
{
int poNum = 0;
string poY;
cout << "\n[*] How many potions would you like to purchase? (Enter a number)" << endl;
cout << ">> ";
cin >> poNum;
cout << "[*] Total will be $" << poNum*20 << ". Would you like to purchase? (y/n)" << endl;
cout << ">> ";
cin >> poY;
if(poY == "Y" || poY == "y") // if user confirms the purchase
{
if(poNum > 0)
{
if(player.getMoney() >= poNum*20)
{
player.setPotion(poNum); // add Potion(s)
player.setMoney(player.getMoney() - poNum*20);
if(poNum == 1)
cout << "\n[+] Success, " << poNum << " potion has been added to your inventory" << endl;
if(poNum >= 2)
cout << "\n[+] Success, " << poNum << " potions have been added to your inventory" << endl;
}
else
{
cout << "[-] Not enough money" << endl;
}
}
else if(poNum <= 0)
cout << "[-] Invalud input" << endl;
}//
else if(poY == "N" || poY == "n")
{
// do nothing
}
break;
}
else if(10 < choice2 || choice2 < 0)
cout << "\n[-] Invalid option" << endl;
else
{
if(choice2 != 10)
cout << "[-] Not enough money" << endl;
}
if(choice2 == 10)
break;
}
}
else if(choice == 4) // random box
{
/* option 4, -random weapon box- (costs $1200)
1) prints the current money balance using getMoney().
2) if balance is enough, subtract 1200 from the balance
3) generate a random number and set a random weapon
4) display which weapon player got
*/
while(choice3 != 2)
{
int choice3 = 0;
cout << "[*] Get a random weapon box" << endl;
cout << "[*] Money Balance: $" << player.getMoney() << endl << endl;
cout << "[1] Purchase: $1200" << endl;
cout << "[2] Shop menu" << endl;
cout << "\n>> ";
cin >> choice3;
cout << endl;
if(player.getMoney() < 1200 && choice3 == 1) // if balance is < 1200, and player choses 1(buy a box)
cout << "\n[-] Not enough money\n" << endl;
if(choice3 == 1 && player.getMoney() >= 1200)
{
srand(time(NULL));
int num = rand() % 8 + 1; //generates a number between 1-8
if(num == 1)
{
player.setWeapon(greatSword);
cout << "[+] You got GreatSword and it has been added to your inventory" << endl;
player.setMoney(player.getMoney() - 1200); // subtract the price from player's balance
}
else if(num == 2)
{
player.setWeapon(longSword);
cout << "[+] You got LongSword and it has been added to your inventory" << endl;
player.setMoney(player.getMoney() - 1200);
}
else if(num == 3)
{
player.setWeapon(axe);
cout << "[+] You got Axe and it has been added to your inventory" << endl;
player.setMoney(player.getMoney() - 1200);
}
else if(num == 4)
{
player.setWeapon(bow);
cout << "[+] You got Bow and it has been added to your inventory" << endl;
player.setMoney(player.getMoney() - 1200);
}
else if(num == 5)
{
player.setWeapon(bowgun);
cout << "[+] You got Bowgun and it has been added to your inventory" << endl;
player.setMoney(player.getMoney() - 1200);
}
else if(num == 6)
{
player.setWeapon(dualBlades);
cout << "[+] You got DualBlades and it has been added to your inventory" << endl;
player.setMoney(player.getMoney() - 1200);
}
else if(num == 7)
{
player.setWeapon(hammer);
cout << "[+] You got Hammer and it has been added to your inventory" << endl;
player.setMoney(player.getMoney() - 1200);
}
else if(num == 8)
{
player.setWeapon(lance);
cout << "[+] You got Lance and it has been added to your inventory" << endl;
player.setMoney(player.getMoney() - 1200);
}
cout << endl;
}
else if(choice3 == 2)
break;
}
}
else if(choice == 5)
break;
} // end of loop
return player;
}
void savedata(Player player)
{
//output the content of Player to a txt file named "data.txt" which includes: weapon count, money, number of portions, and weapons.
string choice = "";
ofstream out;
cout << "[*] Do you want to save data? (y/n)" << endl;
cout << ">> ";
cin >> choice;
if(choice == "n" || choice == "N")
{
// do nothing
return;
}
else if(choice == "Y" || choice == "y") //output 3 types of data
{
int loop = player.getWeaponCount();
out.open("data.txt");
out << player.getWeaponCount() << endl; // 1) weapon count
out << player.getMoney() << endl; // 2) money
out << player.getPotion() << endl; // 3) number of portions
out << player.getExp() << endl; // 4) EXP
out << player.getName() << endl; // 5) name
for (int i = 0; i < loop; i++) // 6) weapon names
{
Weapon weapon = player.getWeapon(i);
out << weapon.getName() << endl;
}
cout << "\n[+] Success, progress has been saved\n" << endl;
}
else
{
cout << "Invalid input" << endl;
}
}
Player loadData(Player player) // laod save data
{
/*
1) load the content of Player which includes: money, progress, and weapons using file stream
2) look for a data.txt file and load the content
3) set the date to Player, using setMoney(), setPortion(), and setWeapons()
*/
Weapon sword("Sword", 0, 10); // Wepaon definitions
Weapon greatSword("GreatSword", 200, 12);
Weapon longSword("LongSword", 450, 30);
Weapon axe("Axe", 600, 42);
Weapon bow("Bow", 900, 53);
Weapon bowgun("Bowgun", 1200, 90);
Weapon dualBlades("DualBlades", 2800, 120);
Weapon hammer("Hammer", 4500, 390);
Weapon lance("Lance", 6800, 970);
ifstream in;
in.open("data.txt");
if(in.fail()) // if there is no file, create a new game
{
string name;
cout << "[-] Failed to find save data, creating a new game..." << endl;
cout << "[*] Enter a username" << endl;
cout << ">> ";
cin >> name;
cout << "[+] Welcome, " << name << "!!" << endl;
ofstream out;
out.open("data.txt");
out << "0" << endl; // set default values
out << "200" << endl; // money
out << "0" << endl; // potion
out << "0" << endl; // exp
out << name << endl;// name
player.setName(name);
loadData(player); // re-load
}
else
{
string line;
int loop = 0;
vector <string> vec;
int money = 0;
int potion = 0;
int exp = 0;
Weapon weapon;
string username;
getline(in, line); // store the number of weapons, which is stored on the first line in the file,
loop = stoi(line); // line 1
getline(in, line); // set money (line 2)
money = stoi(line);
player.setMoney(money);
getline(in, line); // set potions(line 3)
potion = stoi(line);
player.setPotion(potion);
getline(in, line); // set EXP(line 4)
exp = stoi(line);
player.setExp(exp);
player.setLevel(player.getExp());
getline(in, line); // set name(line 5)
username = line;
player.setName(username);
while(getline(in, line)) // set weapons ( store wepon names in vector)
{
vec.push_back(line);
}
for(int j = 0; j < loop; j++) // set weapons
{
if(vec[j] == "Sword")
weapon = sword;
else if(vec[j] == "GreatSword")
weapon = greatSword;
else if(vec[j] == "LongSword")
weapon = longSword;
else if(vec[j] == "Axe")
weapon = axe;
else if(vec[j] == "Bow")
weapon = bow;
else if(vec[j] == "Bowgun")
weapon = bowgun;
else if(vec[j] == "DualBlades")
weapon = dualBlades;
else if(vec[j] == "Hammer")
weapon = hammer;
else if(vec[j] == "Lance")
weapon = lance;
player.setWeapon(weapon); // set weapon
}
cout << "[+] Load successful\n" << endl;
}// END OF ELSE
return player;
}
/*
1) have user pick a monster to fight using chooseMonster() function.
2) make a loop that ends when either user or monster's health reaches 0
3) in the loop, monster and user attacks each other alternately
4) user can choose which part of monster's body to attack
5) display eachother's health each turn
6) if user wins set 1 at the index of 1 of the vector and set 0 if user loses
7) if user wins, set the name of monster at the index 2 of the vector
8) returns the vector
*/
// This function runs a fight, and returns a vector, which contains the information on if player won, a name of monster user fought, and the amount of reward user gets
Player fight(Player player)
{
vector <string> result;
int num = -1;
int numWeapon = 0;
int oldRank = player.getLevel();
double power = 0;
Monster opponent;
Weapon weapon;
bool winLost = false;
double playerHealth = 0;
double monsterHealth = 0;
while(num != 0)
{
int i = 0;
bool pickMonster = true;
while(pickMonster)
{
cout << "\n\n" << endl;
cout << "=====================" << endl;
cout << "Welcome to the lobby!" << endl;
cout << "=====================" << endl;
cout << "[*] Pick a monster to start the game\n" << endl;
cout << "[0] Exit lobby" << endl;
cout << "[1] Rathian" << endl;
cout << "[2] Cavesnake" << endl;
cout << "[3] Grieveling" << endl;
cout << "[4] Mistclaw" << endl;
cout << "[5] Steammorph" << endl;
cout << "[6] Abyssbrood" << endl;
cout << "[7] Cavernghoul" << endl;
cout << "[8] Phasetaur" << endl;
cout << "[9] Netherflayer" << endl;
cout << "[10] Phantomcreep" << endl;
cout << "[11] Random" << endl;
cout << "\n>> ";
cin >> num;
if(num < 0 || num > 11)
cout << "[-] Invalid input" << endl;
else // if user enters a correct number, then end the loop
{
pickMonster = false;
if(num != 0) //since 0 is quit
{
opponent = chooseMonster(num); // need to think about option 0, which is exit
cout << "[+] You picked " << opponent.getName() << endl;
monsterHealth = opponent.getHealth(); // set each health
playerHealth = player.getHealth();
}
}
}
if(num == 0)
break;
//=========================== Pick a weapon ============================
bool pickWeapon = true;
while(pickWeapon)
{
int numWeapons = player.getWeaponCount(); //the num of weapons player has
cout << "\n[*] Choose a weapon (Enter a number)" << endl;
if(numWeapons == 0) // user might not have any weapon, if user has just started this game
{
cout << "[-] You don't have any weapons" << endl;
cout << "[*] Starting game without a weapon..." << endl;
break;
}
cout << "=======================" << endl;
cout << "Inventory - Name: Power" << endl;
cout << "=======================" << endl;
for (int i = 0; i < numWeapons; i++) // display all the weapons player has
{
weapon = player.getWeapon(i);
cout << "[" << i+1 << "] " << weapon.getName() << ": " << weapon.getPower() << endl;
}
cout << endl;
cout << "\n>> ";
cin >> numWeapon; // different from numWeapons
if(numWeapon < 0 || numWeapon > numWeapons || numWeapon == 0)
cout << "[-] Invalid input" << endl;
else // if user enters a correct number, then end the loop
{
pickWeapon = false;
weapon = player.getWeapon(numWeapon -1); // -1 is because it needs an index number
}
}
//=========================== Battle ==================================
cout << "=============" << endl;
cout << "Battle start!" << endl;
cout << "=============" << endl;
while(playerHealth > 0 || monsterHealth > 0) // loops until either player os monter's health reaches 0
{
string part = "";
power = weapon.getPower();
bool heal = true;
if(player.getWeaponCount() == 0) // if use has no weapon,
power = 2;
while(heal)
{
cout << "\n==== Your turn ==== " << endl;
cout << "[*] Attack monster's: (Enter a number or H/Q)" << endl;
cout << "[1] Head" << endl;
cout << "[2] Eyes" << endl;
cout << "[3] Throat" << endl;
cout << "[4] Arms" << endl;
cout << "[5] Stomach" << endl;
cout << "[6] Legs" << endl;
cout << "[H] Use a potion (x " << player.getPotion() << ")" << endl;
cout << "[Q] Quit game" << endl;
cout << "\n>> ";
cin >> part;
if(part == "h" || part == "H")
{
if(player.getPotion() > 0)
{
playerHealth += 10; // heal(+ 10)
cout << "\n[+] You used a potion" << endl;
player.setPotion(-1);
cout << "[HP] You: " << playerHealth << endl;
}
else
{
cout << "\n[-] You have no healing potion" << endl;
}
}
else if(part == "q"|| part == "Q" || part == "1" || part == "2" || part == "3" || part == "4" || part == "5" || part == "6")
break;
else
cout << "\n[-] Invalid input" << endl;
}
if(part == "Q" || part == "q") // Quit game
break;
//=================increase power if user attacks monster's weakness=================