-
Notifications
You must be signed in to change notification settings - Fork 0
/
Application.cpp
1159 lines (825 loc) · 27.1 KB
/
Application.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
/**************************************************
Project: The Tamer, the Arigamo and the Fuhai Gem
Task: Assignment 2 + 3
Author: Sean Lee
Purpose: Application Definition File
The Definition file for the main application that
controls the flow and logic of the game.
**************************************************/
#include "Application.h"
int main() {
srand(unsigned(time(NULL)));
playGame();
pause();
return 0;
}
//-------------------------------------//
// display functions //
//-------------------------------------//
void setWindowSize(int height, int width) {
// sets the size of the console window
// code adpated from:
// Abdullah S. (2013). Resizing Console window C++.Retrieved from https://stackoverflow.com/questions/19605837/resizing-console-window-c
RECT r;
HWND console = GetConsoleWindow();
GetWindowRect(console, &r);
MoveWindow(console, r.left, r.top, width, height, TRUE);
}
void displayTitle() {
// displays the title of the game - usually signals the start of a new screen
system("cls");
displayString(titleScreen);
}
void displayInfo() {
// displays the game's starting info screen
displayTitle();
displayString(infoScreen);
}
void displayHowTo() {
// displays the game's "how to play" screen
displayTitle();
displayString(howToScreen);
}
void displayPlayerStats() {
// displays the player's stats screen
displayString(" Name: " + player.getName());
displayString("\t\t\t\t\t\tHealth: " + to_string(player.getHealthCurrent()) + "/" + to_string(player.getHealthMax()) + "\n");
displayString("\t\t\t\t\t\tIncense Sticks: " + to_string(player.getItem("Incense Sticks")->getAmount()) + "\n");
displayString("\t\t\t\t\t\tCrossbow Bolts: " + to_string(player.getItem("Crossbow Bolts")->getAmount()) + "\n\n");
displayString("Inventory: " + player.getInventoryAsString() + "\n");
displayString("_______________________________________________________________________________\n");
}
void displayEventDescriptions(){
// displays the strings contained within eventQueue sequentially
vector<string> eventQueueTemp = eventQueue.getEventQueueContents();
vector<string>::const_iterator iter;
for (iter = eventQueueTemp.begin(); iter != eventQueueTemp.end(); iter++) {
string eventDetails = *iter;
if (eventDetails != "$") {
displayString(eventDetails + "\n");
}
else {
break;
}
}
}
void displayRoomInfo(int room) {
// displays the selected room's information
displayString(ruinRooms.getRoom(room)->getRoomInfo() + "\n");
}
void displayRoomExits(int room) {
// displays the selected room's exits and hints
// display hints of nearby rooms
vector<int> connectedRooms = ruinRooms.getRoom(room)->getExitConnections();
for (unsigned int i = 0; i < connectedRooms.size(); i++) {
if (ruinRooms.getRoom(connectedRooms[i])->hasHazard()) {
vector<int> roomHazards = ruinRooms.getRoom(connectedRooms[i])->getHazards();
for (unsigned int j = 0; j < roomHazards.size(); j++) {
Hazard* hazTemp = hazards.getHazard(roomHazards[j]);
if (hazTemp->isRoaming()) {
if (!hazTemp->hasDied() && (hazTemp->conscious() || hazTemp->getType() == ARIGAMO)) {
displayString(hazTemp->getHint() + "\n\n");
}
}
else {
displayString(hazTemp->getHint() + "\n\n");
}
}
}
}
// display room exits
displayString(ruinRooms.getRoom(room)->getRoomExits());
}
void displayMap() {
// displays the game's map
displayTitle();
displayString(player.getItem("Map")->getOtherData());
}
void displayEndScreen(){
// displays the ending screen/ score screen of the game
displayTitle();
if (hasPlayerWon()) {
displayString("\t\t\t\tYou WIN!\n\n");
}
else {
displayString("\t\t\t\tYou LOSE!\n\n");
}
displayString("\t\tName: " + player.getName() + "\n\n");
displayString("\t\tHealth: " + to_string(player.getHealthCurrent()) + "/" + to_string(player.getHealthMax()) + "\n");
displayString("\t\tRemaining Incense Sticks: " + to_string(player.getItemAmount("Incense Sticks")) + "\n");
displayString("\t\tRemaining Crossbow Bolts: " + to_string(player.getItemAmount("Crossbow Bolts")) + "\n");
string hasTelecard = (player.getItemAmount("Telecard") > 0) ? "No" : "Yes";
displayString("\t\tHas used Telecard: " + hasTelecard + "\n");
displayString("\t\tNumber of Roaming Opponents Alive: " + to_string(hazards.getNumRoamingHazards()) + "\n");
string isArigamoDead = (hazards.getHazard("Arigamo")->hasDied()) ? "Yes" : "No";
displayString("\t\tHas Arigamo been slain: " + isArigamoDead + "\n");
string hasGem = (player.hasItem("Fuhai Gem")) ? "Yes" : "No";
displayString("\t\tHas Fuhai Gem been retrieved: " + hasGem + "\n");
displayString("\t\tScore Multiplier: " + to_string(difficulty + 1) + "\n");
displayString("\n\t\tFINAL SCORE: " + to_string(calculatePlayerScore() * hasPlayerWon()) + "\n");
displayString("_______________________________________________________________________________\n");
}
void displayUI() {
// displays the game's UI
displayTitle();
displayPlayerStats();
displayRoomInfo(player.getCurrentRoom());
displayEventDescriptions();
if (!player.isDisplaced() && !hasPlayerLost() && !hasPlayerWon()) {
displayRoomExits(player.getCurrentRoom());
}
displayString("_______________________________________________________________________________\n");
// uncomment to get current details of all hazards currently in the game
//cout << hazards.getAllHazardInfo();
}
//-------------------------------------//
// core game functions //
//-------------------------------------//
void playGame() {
// handles the flow of the game from setup to end
bool isPlaying = true;
do {
gameSetUp();
gameLoop();
displayEndScreen();
isPlaying = getBoolInput(" Do you want to play again? (Y/N): ");
} while (isPlaying);
displayString("\n Thank you for playing!\n");
}
void gameSetUp() {
// loads and sets up the core parts of the game
// comment out line below if having errors running the game
setWindowSize(700, 850);
// load and store required screens
titleScreen = loadFileAsString(TITLE_SCREEN_PATH);
infoScreen = loadFileAsString(INFO_SCREEN_PATH);
howToScreen = loadFileAsString(HOW_TO_SCREEN_PATH);
eventQueue = EventQueue();
displayInfo();
pause();
displayHowTo();
pause();
// setting up game objects
displayTitle();
hazards = HazardContainer();
string playerName = getStringInput(" What is your name player?: ");
initialiseRooms();
player = Player(playerName, 30);
player.setStartingRoom(ruinRooms, PLAYER_START_ROOM);
setGameDifficulty();
initialiseHazards();
pause();
}
void gameLoop() {
// handles the flow and progression of the main game
totalTurns = 0;
bool hasQuit = false;
do {
totalTurns++;
updateHazards();
displayUI();
if (!hasPlayerWon() && !hasPlayerLost() && !hasQuit) {
if (!player.isDisplaced()) {
hasQuit = playerInputLoop();
}
else {
player.updateDisplacement();
pause();
}
}
eventQueue.clearEventQueue();
} while (!hasPlayerWon() && !hasPlayerLost() && !hasQuit);
if (!hasQuit) {
if (hasPlayerWon()) {
displayString("\n You have Redeemed yourself!\n");
pause();
}
else if (hasPlayerLost()) {
displayString("\n" + getPlayerLostReason());
displayString("\n You have Lost!\n");
pause();
}
}
}
bool playerInputLoop() {
// handles the player's action during their turn
bool isPlayerTurn = true;
do {
stringstream userInput("");
string inputCommand = "";
vector<string> inputArguments = {};
displayString(" (type HELP to bring up the help menu)\n");
userInput << getStringInput(" What will you do?: ");
// splitting components of input into command and arguments
getline(userInput, inputCommand, ' ');
while (userInput.good()) {
string part = "";
getline(userInput, part, ' ');
inputArguments.push_back(part);
}
// run action
switch (getActionID(inputCommand)) {
case MOVE:
if (player.getItemAmount("Incense Sticks") > 0) {
isPlayerTurn = moveAction(inputArguments);
if (isPlayerTurn) {
displayString(" Those are not valid arguments for the MOVE action.\n");
pause();
displayUI();
}
}
else {
displayString(" You do not have any 'Incense Sticks' left.\n");
pause();
displayUI();
}
break;
case SHOOT:
if (player.getItemAmount("Crossbow Bolts") > 0) {
isPlayerTurn = shootAction(inputArguments);
if (isPlayerTurn) {
displayString(" Those are not valid arguments for the SHOOT action.\n");
pause();
displayUI();
}
}
else {
displayString(" You do not have any 'Crossbow Bolts' left.\n");
pause();
displayUI();
}
break;
case TELECARD:
if (player.getItemAmount("Telecard") > 0) {
isPlayerTurn = telecardAction(inputArguments);
if (isPlayerTurn) {
displayString(" Those are not valid arguments for the TELECARD action or you have not visited that Room yet.\n");
pause();
displayUI();
}
}
else {
displayString(" You do not have any 'Telecards' left.\n");
pause();
displayUI();
}
break;
case MAP:
if (player.hasItem("Map")) {
isPlayerTurn = mapAction();
}
else {
displayString(" You do not have a Map.\n");
pause();
displayUI();
}
break;
case INTERACT:
isPlayerTurn = interactAction();
break;
case HELP:
isPlayerTurn = helpAction();
break;
case QUIT:
return true;
default:
displayString(" That is not a valid ACTION. \n");
pause();
displayUI();
}
} while (isPlayerTurn);
return false;
}
PlayerAction getActionID(string action) {
// returns the action ID of the input action
if (action == "MOVE") {
return MOVE;
}
else if (action == "SHOOT") {
return SHOOT;
}
else if (action == "TELECARD") {
return TELECARD;
}
else if (action == "MAP") {
return MAP;
}
else if (action == "INTERACT") {
return INTERACT;
}
else if (action == "HELP") {
return HELP;
}
else if (action == "QUIT") {
return QUIT;
}
else {
return NOACTION;
}
}
bool moveAction(const vector<string>& arguments) {
// handles validation and operation of player's MOVE action
bool isPlayerTurn = true;
if (arguments.size() == 1) {
int targetRoom = ruinRooms.getRoom(player.getCurrentRoom())->getRoomConnection(arguments[0]);
if (targetRoom != -1) {
player.moveTo(ruinRooms, targetRoom, false);
isPlayerTurn = false;
}
}
return isPlayerTurn;
}
bool shootAction(const vector<string>& arguments) {
// handles validation and operation of player's SHOOT action
bool isPlayerTurn = true;
vector<string> compassDirs = { "N", "E", "S", "W", "NE", "NW", "SE", "SW" };
if (areArgsValid(arguments, compassDirs)) {
vector<string> boltHints;
boltHints = player.shootBolt(ruinRooms, hazards, arguments);
// display hints bolt has found
if (!boltHints.empty()) {
vector<string>::const_iterator hint;
displayString("\n");
for (hint = boltHints.begin(); hint != boltHints.end(); hint++) {
string hintTemp = *hint;
displayString(hintTemp + "\n");
}
isPlayerTurn = false;
pause();
}
}
return isPlayerTurn;
}
bool telecardAction(const vector<string>& arguments) {
// handles validation and operation of player's TELECARD action
bool isPlayerTurn = true;
if (arguments.size() == 1 && isNumber(arguments[0])) {
if (player.hasVisitedRoom(stoi(arguments[0]))) {
player.moveTo(ruinRooms, stoi(arguments[0]), false);
player.getItem("Telecard")->updateAmount(-1);
displayString("\n You Teleported!\n");
pause();
isPlayerTurn = false;
}
}
return isPlayerTurn;
}
bool mapAction() {
// handles validation and operation of player's MAP action
displayMap();
pause();
displayUI();
return true;
}
bool interactAction() {
// handles validation and operation of player's INTERACT action
vector<int> hazardsInRoom = ruinRooms.getRoom(player.getCurrentRoom())->getHazards();
if (!hazardsInRoom.empty()){
vector<int>::const_iterator iter;
for (iter = hazardsInRoom.begin(); iter != hazardsInRoom.end(); iter++) {
int hazID = *iter;
Hazard* hazTemp = hazards.getHazard(hazID);
switch (hazTemp->getType()) {
case ORACLE:
dynamic_cast<Oracle*>(hazTemp)->roomInteraction(player, hazards.getHazard("Arigamo")->getCurrentRoom());
break;
default:
hazTemp->roomInteraction();
}
}
}
else {
displayString("\n There is nothing in the Room to interact with.");
}
pause();
displayUI();
return true;
}
bool helpAction() {
// handles validation and operation of player's HELP action
displayHowTo();
pause();
displayUI();
return true;
}
void setGameDifficulty() {
// asks the user for the game's difficulty and applies the appropriate settings
// present difficulty options to player
displayTitle();
displayString("\n Game Difficulty: [0] Amendment (EASY)\n");
displayString(" \t\t [1] Atonement (NORMAL)\n");
displayString(" \t\t [2] Redemption (HARD)\n\n");
int userInput = getIntIntput(" Please select a difficulty according to their number: ", EASY, HARD);
// generate player items
vector<Item> items;
items.push_back(Item("Enchanted Crossbow", WEAPON, 1));
items.push_back(Item("Crossbow Bolts", CONSUMABLE, 0));
items.push_back(Item("Protective Censer", MAGIC, 1));
items.push_back(Item("Incense Sticks", CONSUMABLE, 0));
items.push_back(Item("Telecard", CONSUMABLE, 1));
items.push_back(Item("Map", NAVIGATION, 1));
// load the game's map
items[5].setOtherData(loadFileAsString(MAP_DATA_PATH));
// number of hazards to initialise
hazardsToInitialise[ARIGAMO] = 1;
hazardsToInitialise[PIT] = 2;
hazardsToInitialise[CCRAT] = 2;
hazardsToInitialise[ORACLE] = 1;
hazardsToInitialise[THIEF] = 1;
hazardsToInitialise[RAIDERS] = 1;
hazardsToInitialise[TRADER] = 1;
hazardsToInitialise[KNIGHT] = 1;
// apply appropriate settings
switch (userInput) {
case 0:
difficulty = EASY;
items[1].setAmount(8);
items[3].setAmount(20);
displayString("\n Difficulty set to Amendment (EASY)\n");
break;
case 1:
difficulty = NORMAL;
items[1].setAmount(5);
items[3].setAmount(15);
displayString("\n Difficulty set to Atonement (NORMAL)\n");
break;
case 2:
difficulty = HARD;
items[1].setAmount(3);
items[3].setAmount(12);
displayString("\n Difficulty set to Redemption (HARD)\n");
break;
default:
displayString("\n There was an error applying the correct difficulty settings.\n");
pause();
}
player.setInventory(items);
}
void initialiseRooms() {
// Initialises Abandon Ruin's rooms
ruinRooms = RoomContainer();
// load raw data into vector
vector<string> roomData = loadFileAsVector(ROOM_DATA_PATH);
unsigned int index = 0;
while (index < roomData.size()) {
int roomNum = 0;
string roomName = "";
stringstream roomDescription("");
vector<string> roomExits = {};
vector<int> roomConnections = {};
// load room number
roomNum = stoi(roomData[index]);
index++;
// load room name
roomName = roomData[index];
index++;
// load room description
index++;
while (roomData[index] != "#") {
roomDescription << " " + roomData[index] + "\n";
index++;
}
index++;
// load room exits
stringstream exitsTemp(roomData[index]);
while (exitsTemp.good()) {
string exit = "";
getline(exitsTemp, exit, ',');
roomExits.push_back(exit);
}
index++;
// load room connections
exitsTemp.clear();
exitsTemp.str(roomData[index]);
while (exitsTemp.good()) {
string connection = "";
getline(exitsTemp, connection, ',');
roomConnections.push_back(stoi(connection));
}
index++;
// add new room object to vector on heap
Room* newRoom = new Room(roomNum, roomName, roomDescription.str(), roomExits, roomConnections);
ruinRooms.addRoom(newRoom);
}
createRoomMatrix();
}
void createRoomMatrix(){
// creates adjacency matrix of room connections
vector<Room*>::const_iterator iter;
for (int i = 0; i < TOTAL_ROOMS; i++) {
int currentRoom = ruinRooms.getRoom(i)->getNumber();
vector<int> connections = ruinRooms.getRoom(i)->getExitConnections();
vector<int>::const_iterator cons;
for (cons = connections.begin(); cons != connections.end(); cons++) {
int con = *cons;
roomConnections[currentRoom][con] = 1;
roomConnections[con][currentRoom] = 1;
}
}
}
void initialiseHazards() {
// Initialises the game's hazards
for (int i = 0; i < TOTAL_HAZARD_TYPES - 1; i++) {
if (hazardsToInitialise[i] > 0) {
loadHazard((HazardType) i, hazardsToInitialise[i]);
}
}
}
void loadHazard(HazardType type, int amount) {
// loads and initialises a specific hazard into the game
if (amount != 0) {
// load raw data into vector
vector<string> hazardData = loadFileAsVector(HAZARD_DATA_PATHS[type]);
string hazardName = "";
string hazardHint = "";
vector<string> eventDescriptions = {};
bool isRoaming = false;
bool isConscious = false;
int index = 0;
// load hazard name
hazardName = hazardData[index];
index++;
// load hazard hint
hazardHint = " " + hazardData[index];
index++;
// load hazard event description
index++;
while (hazardData[index] != "$") {
stringstream hazardEvent("");
while (hazardData[index] != "#") {
hazardEvent << " " << hazardData[index] + "\n";
index++;
}
eventDescriptions.push_back(hazardEvent.str());
index++;
}
index++;
// load isRoaming
isRoaming = stoi(hazardData[index]);
index++;
// load isLiving
isConscious = stoi(hazardData[index]);
index++;
// initiaise correct amount of hazard
vector<int> exceptionRooms = {PLAYER_START_ROOM, ARIGAMO_START_ROOM};
switch (type) {
case ARIGAMO: {
// create required extra variables
int hpDrain = 2 * ((int) difficulty + 1);
float baseRoam = abs((((int) difficulty + 1) * 0.25) - 0.4);
// create and place as many as necessary
for (int i = 0; i < amount; i++) {
Hazard* newHazard = new Arigamo(hazardName, ARIGAMO, hazardHint, eventDescriptions, isRoaming, isConscious, hpDrain, baseRoam);
hazards.addHazard(newHazard);
hazards.getLastHazard()->setStartingRoom(ruinRooms, ARIGAMO_START_ROOM);
}
break;
}
case PIT: {
// create and place as many as necessary
for (int i = 0; i < amount; i++) {
Hazard* newHazard = new Pit(hazardName, PIT, hazardHint, eventDescriptions, isRoaming, isConscious);
hazards.addHazard(newHazard);
int startRoom = ruinRooms.findRandomEmptyStartRoom(exceptionRooms);
hazards.getLastHazard()->setStartingRoom(ruinRooms, startRoom);
}
break;
}
case CCRAT: {
// create required extra variables
int damage = (difficulty + 1) * 2;
// create and place as many as necessary
for (int i = 0; i < amount; i++) {
Hazard* newHazard = new CCRats(hazardName, CCRAT, hazardHint, eventDescriptions, isRoaming, isConscious, damage);
hazards.addHazard(newHazard);
int startRoom = ruinRooms.findRandomEmptyStartRoom(exceptionRooms);
hazards.getLastHazard()->setStartingRoom(ruinRooms, startRoom);
}
break;
}
case ORACLE: {
// create and place as many as necessary
for (int i = 0; i < amount; i++) {
Hazard* newHazard = new Oracle(hazardName, ORACLE, hazardHint, eventDescriptions, isRoaming, isConscious);
hazards.addHazard(newHazard);
int startRoom = ruinRooms.findRandomEmptyStartRoom(exceptionRooms);
hazards.getLastHazard()->setStartingRoom(ruinRooms, startRoom);
}
break;
}
case THIEF: {
// create and place as many as necessary
for (int i = 0; i < amount; i++) {
Hazard* newHazard = new Thief(hazardName, THIEF, hazardHint, eventDescriptions, isRoaming, isConscious);
hazards.addHazard(newHazard);
int startRoom = ruinRooms.findRandomEmptyStartRoom(exceptionRooms);
hazards.getLastHazard()->setStartingRoom(ruinRooms, startRoom);
}
break;
}
case RAIDERS: {
// create required extra variables
int damage = (difficulty + 1) * 3;
// create and place as many as necessary
for (int i = 0; i < amount; i++) {
Hazard* newHazard = new Raiders(hazardName, RAIDERS, hazardHint, eventDescriptions, isRoaming, isConscious, damage);
hazards.addHazard(newHazard);
int startRoom = ruinRooms.findRandomEmptyStartRoom(exceptionRooms);
hazards.getLastHazard()->setStartingRoom(ruinRooms, startRoom);
}
break;
}
case TRADER: {
// create and place as many as necessary
for (int i = 0; i < amount; i++) {
Hazard* newHazard = new Trader(hazardName, TRADER, hazardHint, eventDescriptions, isRoaming, isConscious);
hazards.addHazard(newHazard);
int startRoom = ruinRooms.findRandomEmptyStartRoom(exceptionRooms);
hazards.getLastHazard()->setStartingRoom(ruinRooms, startRoom);
}
break;
}
case KNIGHT: {
// create required extra variables
int damage = (difficulty + 1) * 4;
// create and place as many as necessary
for (int i = 0; i < amount; i++) {
Hazard* newHazard = new Knight(hazardName, KNIGHT, hazardHint, eventDescriptions, isRoaming, isConscious, damage);
hazards.addHazard(newHazard);
int startRoom = ruinRooms.findRandomEmptyStartRoom(exceptionRooms);
hazards.getLastHazard()->setStartingRoom(ruinRooms, startRoom);
}
break;
}
default:
displayString(" The hazard could not be initialised \n");
}
}
}
void updateHazards(){
// updates the game's hazards
if (!player.isDisplaced() && totalTurns > 1) {
moveHazards();
}
// updating interactions
vector<string> eventTemp;
Arigamo* arigamo = dynamic_cast<Arigamo*>(hazards.getHazard("Arigamo"));
// arigamo health drain
eventTemp = arigamo->drainPlayerHP((int*)roomConnections, TOTAL_ROOMS, player);
eventQueue.updateEventQueue(eventTemp);
// check arigamo interactions with player
if (arigamo->getCurrentRoom() == player.getCurrentRoom()) {
eventTemp = arigamo->updateInteraction(player);
eventQueue.updateEventQueue(eventTemp);
}
// check arigamo interactions with other hazards in the same room
if (ruinRooms.getRoom(arigamo->getCurrentRoom())->hasHazard()) {
vector<int> hazardsInRoom = ruinRooms.getRoom(arigamo->getCurrentRoom())->getHazards();
vector<int>::const_iterator iter;
for (iter = hazardsInRoom.begin(); iter != hazardsInRoom.end(); iter++) {
int hazID = *iter;
if (hazID != arigamo->getID()) {
eventTemp = arigamo->updateInteraction(hazards.getHazard(hazID));
eventQueue.updateEventQueue(eventTemp);
}
}
}
// check other hazards' interaction with the player
vector<int> hazardsInRoom = ruinRooms.getRoom(player.getCurrentRoom())->getHazards();
vector<int>::const_iterator iter;
for (iter = hazardsInRoom.begin(); iter != hazardsInRoom.end(); iter++) {
int hazID = *iter;
Hazard* hazTemp = hazards.getHazard(hazID);
switch (hazTemp->getType()) {
case PIT:
eventTemp = dynamic_cast<Pit*>(hazTemp)->updateInteraction(player);
eventQueue.updateEventQueue(eventTemp);
break;
case CCRAT:
eventTemp = dynamic_cast<CCRats*>(hazTemp)->updateInteraction(player, ruinRooms);
eventQueue.updateEventQueue(eventTemp);
break;
case ORACLE:
eventTemp = dynamic_cast<Oracle*>(hazTemp)->updateInteraction(player);
eventQueue.updateEventQueue(eventTemp);
break;
case THIEF:
eventTemp = dynamic_cast<Thief*>(hazTemp)->updateInteraction(player);
eventQueue.updateEventQueue(eventTemp);
break;