-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameUtil.cpp
More file actions
812 lines (768 loc) · 26.8 KB
/
gameUtil.cpp
File metadata and controls
812 lines (768 loc) · 26.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
#include "gameUtil.h"
#include <stdlib.h>
#include <time.h>
#include <iostream>
using namespace std;
Hero* heroSelection(){
char* name;
name = const_cast<char*>(nameSelection().c_str());
string role;
cout << "Select a role for your hero. (Available: WARRIOR,SORCERER,PALADIN)\n";
cout << "Make your selection:";
cin >> role;
cout << "----------------------------------\n";
Hero* h;
while(true){
if (role == "WARRIOR"){
h = new Warrior(name);
break;
}
else if (role == "SORCERER"){
h = new Sorcerer(name);
break;
}
else if (role == "PALADIN"){
h = new Paladin(name);
break;
}
else{
cout << "Please check your spelling and try again:";
cin >> role;
cout << "----------------------------------\n";
}
}
return h;
}
string nameSelection(){
string choice;
string name;
cout << "Would you like to select your own name? (YES/NO)\n";
cout << "Insert selection:";
cin >> choice;
cout << "----------------------------------\n";
if (choice == "YES"){
cout << "Insert your name:";
cin.ignore();
getline(cin,name);
return name;
}
else{
name = NameInitializerList::generateHeroName();
return name;
}
}
PlayerPosition::PlayerPosition(const int x1, const int y1, const char ch) {
x = x1;
y = y1;
icon = ch;
}
void PlayerPosition::goUp() {
x-=1;
}
void PlayerPosition::goRight() {
y+=1;
}
void PlayerPosition::goLeft() {
y-=1;
}
void PlayerPosition::goDown() {
x+=1;
}
char PlayerPosition::getIcon() const {
return icon;
}
int PlayerPosition::getX() const {
return x;
}
int PlayerPosition::getY() const {
return y;
}
PlayerPosition::~PlayerPosition() {
}
Marketplace::Marketplace() {
itemStock = new vector<Item*>();
spellStock = new vector<Spell*>();
}
void Marketplace::addInItemStock(Item * t1) {
itemStock->push_back(t1);
}
void Marketplace::addInSpellStock(Spell * t1) {
spellStock->push_back(t1);
}
void Marketplace::removeFromItemStock(int t1) {
itemStock->erase(itemStock->begin()+t1);
}
void Marketplace::removeFromSpellStock(int t1) {
spellStock->erase(spellStock->begin()+t1);
}
void Marketplace::generateStock() {
int i;
int nameSlot=1;
for (i=1;i<=3;i++){
Weapon* w1 = new Weapon(const_cast<char*>(NameInitializerList::generateWeaponNames(nameSlot++).c_str()),1000*i,2+4*i,25*i,OneHanded);
Weapon* w2 = new Weapon(const_cast<char*>(NameInitializerList::generateWeaponNames(nameSlot++).c_str()),1000*i,2+4*i,25*i,OneHanded);
Weapon* w3 = new Weapon(const_cast<char*>(NameInitializerList::generateWeaponNames(nameSlot++).c_str()),1000*i,2+4*i,25*i,TwoHanded);
this->addInItemStock(w1);
this->addInItemStock(w2);
this->addInItemStock(w3);
}
nameSlot = 1;
for (i=1;i<=3;i++){
Armor* a1 = new Armor(const_cast<char*>(NameInitializerList::generateArmorNames(nameSlot++).c_str()),800*i,4*i,15*i);
Armor* a2 = new Armor(const_cast<char*>(NameInitializerList::generateArmorNames(nameSlot++).c_str()),800*i,4*i,15*i);
Armor* a3 = new Armor(const_cast<char*>(NameInitializerList::generateArmorNames(nameSlot++).c_str()),800*i,4*i,15*i);
this->addInItemStock(a1);
this->addInItemStock(a2);
this->addInItemStock(a3);
}
nameSlot = 1;
for (i=1;i<=4;i++){
IceSpell* s1 = new IceSpell(const_cast<char*>(NameInitializerList::generateIceSpellNames(nameSlot).c_str()),500*i,(i-1)*4+1,15*i,10*i,10*i+10);
FireSpell* s2 = new FireSpell(const_cast<char*>(NameInitializerList::generateFireSpellNames(nameSlot).c_str()),500*i,(i-1)*4+1,15*i,10*i,10*i+10);
LightningSpell* s3 = new LightningSpell(const_cast<char*>(NameInitializerList::generateLightningSpellNames(nameSlot++).c_str()),500*i,(i-1)*4+1,15*i,10*i,10*i+10);
this->addInSpellStock(s1);
this->addInSpellStock(s2);
this->addInSpellStock(s3);
}
nameSlot = 1;
string pname;
PotionType ptype;
int pstat;
for (i=1;i<=5;i++){
pname = NameInitializerList::generatePotionName();
if (pname == "Health Potion"){
ptype = HEAL;
pstat = 20;
}
else if (pname == "Mana Potion"){
ptype = MANA;
pstat = 10;
}
else if (pname == "Strength Potion"){
ptype = STRENGTH;
pstat = 3;
}
else if (pname == "Dexterity Potion"){
ptype = DEXTERITY;
pstat = 3;
}
else if (pname == "Agility Potion"){
ptype = AGILITY;
pstat = 3;
}
Potion* p = new Potion(const_cast<char*>(pname.c_str()),125*i,i,ptype,pstat*i);
this->addInItemStock(p);
}
}
void Marketplace::displayItemStock() {
cout << "Item Stock :\n";
int i = 1;
for (Item* n: *itemStock){
cout << i++ << ". " << n->getName() << ", Minimum Level: " << n->getLevelReq() << ", Price: " << n->getPrice() << endl;
};
}
void Marketplace::displaySpellStock() {
cout << "Spell Stock :\n";
int i = 1;
for (Spell* n: *spellStock){
cout << i++ << ". " << n->getName() << ", Minimum Level: " << n->getLevelReq() << ", Price: " << n->getPrice() << endl;
}
}
void Marketplace::buyItem(Hero* h1) {
cout << "This is what is up for sale.\n";
this->displayItemStock();
cout << "Type your number of selection or -1 to cancel:";
int selection;
cin >> selection;
cout << "----------------------------------\n";
if (selection == -1){
return;
}
else if (selection > itemStock->size()){
cout << "Wrong choice. Pick more carefully.\n";
}
else {
if(itemStock->at(selection-1)->getPrice()>h1->getMoney()){
cout << "Sorry, not enough gold.\n";
}
else{
h1->removeMoney(itemStock->at(selection-1)->getPrice());
h1->addToInventory(itemStock->at(selection-1));
this->removeFromItemStock(selection-1);
}
}
}
void Marketplace::sellItem(Hero* h1) {
int selection;
cout << "Choose an item from your inventory to sell in half the price.\n";
h1->printInventory();
cout << "Make your selection (Example: Input 1 to sell the first item or -1 to cancel) :";
cin >> selection;
cout << "----------------------------------\n";
if (selection == -1){
return;
}
else if (selection > h1->getInventorySize()){
cout << "Wrong choice. Pick more carefully.\n";
}
else {
h1->addMoneyFromItem(selection-1);
h1->removeFromInventory(selection-1);
}
}
void Marketplace::buySpell(Hero* h1) {
cout << "This is what is up for sale.\n";
this->displaySpellStock();
cout << "Type your number of selection or -1 to cancel:";
int selection;
cin >> selection;
cout << "----------------------------------\n";
if (selection == -1){
return;
}
else if (selection > spellStock->size()){
cout << "Wrong choice. Pick more carefully.\n";
}
else {
h1->removeMoney(spellStock->at(selection-1)->getPrice());
h1->addToSpellbook(spellStock->at(selection-1));
this->removeFromSpellStock(selection-1);
}
}
void Marketplace::sellSpell(Hero* h1) {
int selection;
cout << "Choose a spell from your spellbook to sell in half the price.\n";
h1->printSpellbook();
cout << "Make your selection (Example: Input 1 to sell the first spell or -1 to cancel) :";
cin >> selection;
cout << "----------------------------------\n";
if (selection == -1){
return;
}
else if (selection > h1->getSpellbookSize()){
cout << "Wrong choice. Pick more carefully.\n";
}
else {
h1->addMoneyFromSpell(selection-1);
h1->removeFromSpellbook(selection-1);
}
}
void Marketplace::operate(int number, Hero** al) {
cout<<"The Merchant greets you with a smile.\n";
int optionSelection;
int typeSelection;
int heroSelection;
bool talking = true;
while (talking) {
cout<<"What are you looking for?\n";
cout<<"1. Buy something.\n2. Sell something.\n3. Leave the shop.\n";
cout<<"Make your selection by typing the corresponding number:";
cin >> optionSelection;
cout << "----------------------------------\n";
switch (optionSelection) {
case 1:
cout << "1. Buy an item.\n2. Buy a spell.\n";
cout << "Make your selection by typing the corresponding number:";
cin >> typeSelection;
cout << "----------------------------------\n";
if (typeSelection!=1 and typeSelection!=2){
cout << "Wrong selection. Please try again.\n";
break;
}
if (number == 1){
if (typeSelection == 1){this->buyItem(al[0]);}
else {this->buySpell(al[0]);}
}
else {
cout << "Your team consists of " << number << " Heroes.\n[";
for (int i=0;i<number;i++){
cout << i+1 << "." << al[i]->getName() << ", ";
}
cout << "]\n";
cout << "Select a hero by its number to initiate a transaction:";
cin >> heroSelection;
cout << "----------------------------------\n";
if (heroSelection <= number and heroSelection >= 1){
if (typeSelection == 1){this->buyItem(al[heroSelection-1]);}
else {this->buySpell(al[heroSelection-1]);}
}
else {
cout << "Wrong choice. The merchant kicked you out.\n";
talking = false;
}
}
break;
case 2:
cout << "1. Sell an item.\n2. Sell a spell.\n";
cout << "Make your selection by typing the corresponding number:";
cin >> typeSelection;
cout << "----------------------------------\n";
if (typeSelection!=1 and typeSelection!=2){
cout << "Wrong selection. Please try again.\n";
break;
}
if (number == 1){
if (typeSelection == 1){this->sellItem(al[0]);}
else {this->sellSpell(al[0]);}
}
else {
cout << "Your team consists of " << number << " Heroes.\n";
cout << "Select a hero by its number to initiate a transaction:";
cin >> heroSelection;
cout << "----------------------------------\n";
if (heroSelection <= number and heroSelection >= 1){
if (typeSelection == 1) {this->sellItem(al[heroSelection-1]);}
else {this->sellSpell(al[heroSelection-1]);}
}
else {
cout << "Wrong choice. The merchant kicked you out.\n";
talking = false;
}
}
break;
case 3:
cout << "After taking a look around you decide to leave the shop.\n";
talking = false;
break;
default:
cout << "Wrong selection. The Merchant minds his business and you decide to walk away.\n";
talking = false;
}
}
}
Marketplace::~Marketplace() {
if (itemStock->size()!=0){
for(auto& pItem: *itemStock){
delete pItem;
}
}
itemStock->clear();
delete itemStock;
if (spellStock->size()!=0){
for(auto& pSpell: *spellStock){
delete pSpell;
}
}
spellStock->clear();
delete spellStock;
}
MobSpawner::MobSpawner(int cap) {
capacity = cap;
enemyTeam = new Monster*[capacity];
for (int i=0;i<capacity;i++){
enemyTeam[i] = NULL;
}
}
void MobSpawner::spawnEnemies(int amplifier) {
srand(time(NULL));
enemiesNum = rand()%capacity+1;
int enemyType;
string tmpMobName;
char* mobName;
for (int i=0;i<enemiesNum;i++){
enemyType = rand()%3+1;
switch (enemyType) {
case 1:
tmpMobName = NameInitializerList::generateDragonName();
mobName = &tmpMobName[0];
enemyTeam[i] = new Dragon(mobName);
break;
case 2:
tmpMobName = NameInitializerList::generateExoskeletonName();
mobName = &tmpMobName[0];
enemyTeam[i] = new Exoskeleton(mobName);
break;
case 3:
tmpMobName = NameInitializerList::generateSpiritName();
mobName = &tmpMobName[0];
enemyTeam[i] = new Spirit(mobName);
break;
}
enemyTeam[i]->adjustStats(amplifier);
}
}
void MobSpawner::displayEnemies() {
cout << "Enemy Team = {";
for (int i=0;i<capacity;i++){
if (enemyTeam[i]!=NULL){
cout << enemyTeam[i]->getName() << ",";
}
}
cout << "}\n";
}
void MobSpawner::displayCombatStats(int number, Hero** al){
int i;
cout << "Ally Team : \n";
for (i=0;i<number;i++){
cout << al[i]->getName() << " -> HP = " << al[i]->getCurrentHP() << ", MP = " << al[i]->getCurrentMP() << endl;
}
cout << "Enemy Team :\n";
for (i=0;i<capacity;i++){
if (enemyTeam[i]!=NULL){
cout << enemyTeam[i]->getName() << " -> HP = " << enemyTeam[i]->getCurrentHP() << endl;
}
}
}
void MobSpawner::fightEnemies(int alliesNum, Hero** al) {
bool allyWin = false;
bool enemyWin = false;
int allyEval;
int enemyEval;
int i;
int j;
int combatSelection;
int targetSelection;
int targetedAlly;
int menuSelection;
int attackDamage;
int spellDamage;
int dodgeValue;
bool canCast;
while (true){
dodgeValue = rand()%100+1;
for (i=0; i < alliesNum; i++){
allyEval = 0;
if (al[i]->getCurrentHP()<=0){
continue;
}
if (al[i]->getCurrentHP()<al[i]->getHealthPower() and al[i]->getCurrentHP()>0){
al[i]->recoverCurrentHP(al[i]->getHealthPower()*0.02);
}
if (al[i]->getCurrentMP()<al[i]->getMagicPower()){
al[i]->recoverCurrentMP(al[i]->getMagicPower()*0.1);
}
cout << "It's " << al[i]->getName() << "'s turn.\n";
cout << "1.Cast a spell\n2.Attack.\n3.Swap Gear/Use Potion.\n4.Display combat stats.\n";
cout << "Select an action:";
cin >> combatSelection;
cout << "----------------------------------\n";
switch (combatSelection) {
case 1:
canCast=true;
while(true){
if (al[i]->hasSpells()==true){
this->displayEnemies();
cout << "Select an enemy target.(Example: 1 for first enemy.):";
cin >> targetSelection;
cout << "----------------------------------\n";
if (targetSelection > 0 and targetSelection <= enemiesNum){
if (enemyTeam[targetSelection-1]->getCurrentHP()>0){
spellDamage = al[i]->cast(enemyTeam[targetSelection-1]);
if (spellDamage != -1){
enemyTeam[targetSelection-1]->reduceCurrentHP(spellDamage);
break;
}
else {
canCast = false;
break;
}
}
else {
cout << "Character is already dead. Please try again.\n";
}
}
else {
cout << "Wrong target. Please try again.\n";
}
}
else {
cout << "Your hero has not learned any spells yet. You attack instead.\n";
canCast = false;
break;
}
}
if (canCast){
break;
}
case 2:
while(true){
this->displayEnemies();
cout << "Select an enemy target.(Example: 1 for first enemy.):";
cin >> targetSelection;
cout << "----------------------------------\n";
if (targetSelection > 0 and targetSelection <= enemiesNum){
if (enemyTeam[targetSelection-1]->getCurrentHP()>0){
if (enemyTeam[targetSelection-1]->getDodge()>=dodgeValue){
cout << "Your enemy dodged your attack.\n";
}
else{
attackDamage = al[i]->attack() - enemyTeam[targetSelection-1]->getDefense();
if (attackDamage > 0){
enemyTeam[targetSelection-1]->reduceCurrentHP(attackDamage);
}
}
break;
}
else {
cout << "Character is already dead. Please try again.\n";
}
}
else {
cout << "Wrong target. Please try again.\n";
}
}
break;
case 3:
while (true){
cout << "Would you like to swap gear or use a potion?\n";
cout << "1.Swap Weapon.\n2.Swap Armor.\n3.Use a Potion.\n4.Cancel Selection.\n";
cout << "Input your selection:";
cin >> menuSelection;
cout << "----------------------------------\n";
if (menuSelection == 1){
al[i]->swapWeapon();
}
else if (menuSelection == 2){
al[i]->swapArmor();
}
else if (menuSelection == 3){
al[i]->usePotion();
}
else {
cout << "Option Cancelled.\n";
break;
}
}
break;
case 4:
this->displayCombatStats(alliesNum, al);
i--;
break;
default:
cout << "Invalid action. You lost your turn.\n";
}
for (j=0;j<enemiesNum;j++){
if (enemyTeam[j]->getCurrentHP()<=0){allyEval++;}
}
if (allyEval==enemiesNum){
allyWin=true;
break;
}
}
if (allyWin){
cout << "Victory!\n";
this->reward(enemiesNum,alliesNum,al);
for (i=0;i<alliesNum;i++){
if (al[i]->getCurrentHP()<=0){
al[i]->setCurrentHP(al[i]->getHealthPower()*0.5);
}
}
break;
}
for (i=0;i<enemiesNum;i++){
enemyEval = 0;
if (enemyTeam[i]->isCursed()){
enemyTeam[i]->cure();
}
if (enemyTeam[i]->getCurrentHP()<=0){
continue;
}
if (enemyTeam[i]->getCurrentHP()<enemyTeam[i]->getHealthPower() and enemyTeam[i]->getCurrentHP()>0){
enemyTeam[i]->recoverCurrentHP(enemyTeam[i]->getHealthPower()*0.1);
}
while(true){
targetedAlly = rand()%alliesNum;
if (al[targetedAlly]->getCurrentHP()>0){
if (al[targetedAlly]->getAgility()<=dodgeValue){
attackDamage = enemyTeam[i]->attack() - al[targetedAlly]->defend();
if (attackDamage>0){
al[targetedAlly]->reduceCurrentHP(attackDamage);
cout << enemyTeam[i]->getName() << " attacked " << al[targetedAlly]->getName() << " for " << attackDamage << " damage.\n";
break;
}
}
else{
break;
}
}
}
for (j=0; j < alliesNum; j++){
if (al[j]->getCurrentHP()<=0){enemyEval++;}
}
if (enemyEval == alliesNum){
enemyWin=true;
break;
}
}
if (enemyWin){
cout << "Defeat!\n";
this->penalty(alliesNum,al);
for (i=0;i<alliesNum;i++){
if (al[i]->getCurrentHP()<=0){
al[i]->setCurrentHP(al[i]->getHealthPower()*0.5);
}
}
break;
}
}
}
void MobSpawner::reward(int enemies, int allies, Hero** al){
int experience;
float parameter;
int gold;
for (int i=0;i<allies;i++){
gold = al[i]->getLevel()*enemies*10;
parameter = 1.0/float(al[i]->getLevel());
experience = parameter*enemies*50;
al[i]->setMoney(al[i]->getMoney()+gold);
al[i]->addExperience(experience);
}
}
void MobSpawner::penalty(int number, Hero** al){
for (int i=0;i<number;i++){
if (al[i]->getMoney()>0){
al[i]->setMoney(al[i]->getMoney()*0.5);
}
}
}
void MobSpawner::despawnEnemies() {
for (int i=0;i<capacity;i++){delete enemyTeam[i];}
for (int i=0;i<capacity;i++){enemyTeam[i]=NULL;}
}
MobSpawner::~MobSpawner() {
delete[] enemyTeam;
}
gameMap::gameMap(int number, Hero** al, int size) {
characters = number;
allies = al;
gridSize = size;
grid = new Tile**[gridSize];
for (int i = 0; i < gridSize; i++){
grid[i] = new Tile*[gridSize];
}
spawner = new MobSpawner(3);
}
void gameMap::generateMap() {
for (int i = 0; i < gridSize; i++){
for (int j = 0; j < gridSize; j++){
if(i==gridSize-2 and j ==1){
grid[i][j] = new EntranceTile();
player = new PlayerPosition(i,j);
}
else if(i==j and i==(gridSize/2)){
grid[i][j] = new MarketTile();
shop = new Marketplace();
shop->generateStock();
}
else if(i==0 or i == gridSize-1 or j==0 or j==gridSize-1){
grid[i][j] = new ObstacleTile();
}
else{
grid[i][j] = new CommonTile();
}
}
}
}
bool gameMap::isInBounds(int x, int y) {
return ((0<=x<gridSize and 0<=y<gridSize)?true:false);
}
void gameMap::playerInteract(int direction) {
int gridX = player->getX();
int gridY = player->getY();
bool goBack = false;
if (isInBounds(gridX,gridY)==true){
if (grid[gridX][gridY]->getIcon()=='O'){
cout<<"You can't move there, because there is an obstacle in your way.\n";
goBack=true;
}
else if (grid[gridX][gridY]->getIcon()=='M'){
shop->operate(characters,allies);
}
else if (grid[gridX][gridY]->getIcon()=='C'){
int probability = rand()%100+1;
if (probability>50){
cout << "You get ambushed by monsters.\n";
spawner->spawnEnemies(allies[0]->getLevel());
spawner->displayEnemies();
spawner->fightEnemies(characters,allies);
spawner->despawnEnemies();
}
}
else if (grid[gridX][gridY]->getIcon()=='E'){
cout<<"You are back at the entrance. Unfortunately there is no way out anymore...\n";
}
}
else{
cout << "This movement option is not valid. Map out of bounds. Please try again.\n";
goBack=true;
}
if (goBack==true){
switch (direction) {
case 1:
player->goDown();
break;
case 2:
player->goLeft();
break;
case 3:
player->goRight();
break;
case 4:
player->goUp();
}
}
}
void gameMap::playerMove() {
cout << "Where do you want to go? (1.UP,2.RIGHT,3.LEFT,4.DOWN)\n";
cout << "Define movement by typing the corresponding number:";
int direction;
cin >> direction;
cout << "----------------------------------\n";
switch (direction) {
case 1:
player->goUp();
this->playerInteract(direction);
break;
case 2:
player->goRight();
this->playerInteract(direction);
break;
case 3:
player->goLeft();
this->playerInteract(direction);
break;
case 4:
player->goDown();
this->playerInteract(direction);
break;
default:
cout << "Wrong Number Selection. Player did not move\n";
}
}
void gameMap::displayMap() {
cout << "Appendix: O=Obstacle, C=Common Grounds,\nM=Marketplace, P=Player(s), E=Entrance\n";
for (int i = 0; i < gridSize; i++){
for (int j = 0; j < gridSize; j++){
if(i==player->getX() and j==player->getY()){
cout << player->getIcon() << " ";
}
else{
cout << grid[i][j]->getIcon() << " ";
}
}
cout << endl;
}
}
void gameMap::displayHeroStats() {
cout << "Your team consists of " << characters << " Hero(s).\n";
for (int i=0;i<characters;i++){
cout << i+1 << ". ";
allies[i]->displayStats();
}
}
void gameMap::displayHeroInventory() {
for (int i=0;i<characters;i++){
allies[i]->displayEquipment();
}
}
gameMap::~gameMap() {
for (int i = 0; i < gridSize; i++){
for (int j =0; j < gridSize; j++){
delete grid[i][j];
}
delete grid[i];
}
delete[] grid;
delete player;
delete shop;
}