-
Notifications
You must be signed in to change notification settings - Fork 0
/
Arigamo.cpp
334 lines (229 loc) · 7.61 KB
/
Arigamo.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
/**************************************************
Project: The Tamer, the Arigamo and the Fuhai Gem
Task: Assignment 2 + 3
Author: Sean Lee
Purpose: Arigamo Class Definition File
The Definition file for the Arigamo class - the main
objective of the game.
**************************************************/
#include "Arigamo.h"
//-------------------------------------//
// constructors and destructors //
//-------------------------------------//
Arigamo::Arigamo() {
healthDrainRate = 0;
fuhaiGem = Item();
turnsToWake = 0;
baseRoamChance = 0.0;
roamChanceMod = 0.0;
}
Arigamo::Arigamo(string name, HazardType type, string hint, vector<string> description, bool roaming, bool conscious, int hpDrain, float baseRoam) : Hazard(name, type, hint, description, roaming, conscious) {
healthDrainRate = hpDrain;
fuhaiGem = Item("Fuhai Gem", MAGIC, 1);
turnsToWake = rand() % 7 + 3;
baseRoamChance = baseRoam;
roamChanceMod = 0.4;
}
Arigamo::~Arigamo() {
}
//-------------------------------------//
// accessor methods //
//-------------------------------------//
int Arigamo::getHealthDrainRate() {
return healthDrainRate;
}
int Arigamo::getTurnsToWake() {
return turnsToWake;
}
float Arigamo::getBaseRoamChance() {
return baseRoamChance;
}
float Arigamo::getRoamChanceMod() {
return roamChanceMod;
}
string Arigamo::getDetails() {
// returns the class details of the Arigamo as formatted string
stringstream hazardDetails;
hazardDetails << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
hazardDetails << " Arigamo ID: " << getID() << "\n";
hazardDetails << " Arigamo Name: " << getName() << "\n";
hazardDetails << " Arigamo Type: " << getTypeAsString() << "\n";
hazardDetails << " Current Room: " << getCurrentRoom() << "\n";
hazardDetails << " Hint: " << getHint() << "\n";
hazardDetails << " Event Descriptions: " << getDescriptionsAsString() << "\n";
hazardDetails << " Is Roaming Type: " << isRoaming() << "\n";
hazardDetails << " Is Conscious: " << conscious() << "\n";
hazardDetails << " Is Dead: " << hasDied() << "\n";
hazardDetails << " Has Interacted: " << interacted() << "\n";
hazardDetails << " Health Drain Rate: " << getHealthDrainRate() << "\n";
hazardDetails << " Has Gem: " << hasGem() << "\n";
hazardDetails << " Turns till Wake: " << getTurnsToWake() << "\n";
hazardDetails << " Base Roam Chance: " << getBaseRoamChance() << "\n";
hazardDetails << " Roam Chance Modifier: " << getRoamChanceMod() << "\n";
hazardDetails << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
return hazardDetails.str();
}
//-------------------------------------//
// mutator methods //
//-------------------------------------//
void Arigamo::setHealthDrainRate(int rate) {
if (rate > 0) {
healthDrainRate = rate;
}
else {
displayString(" You have not entered a valid health drain rate to set.\n");
}
}
void Arigamo::setTurnsToWake(int turns) {
if (turns >= 0) {
turnsToWake = turns;
}
else {
displayString(" You have not entered a valid number of turns to set.\n");
}
}
void Arigamo::setBaseRoamChance(float chance) {
if (chance >= 0.0 || chance < 1.0) {
baseRoamChance = chance;
}
else {
displayString(" You have not entered a valid base roam chance to set.\n");
}
}
void Arigamo::setRoamChanceMod(float chance) {
if (chance >= 0.0 || chance < 1.0) {
roamChanceMod = chance;
}
else {
displayString(" You have not entered a valid roam chance modifier to set.\n");
}
}
void Arigamo::updateTurnsToWake(int turns) {
if (turns != 0) {
turnsToWake += turns;
if (turnsToWake <= 0) {
turnsToWake = 0;
}
}
else {
displayString(" You have not entered a valid number of turns to update turnsToWake set.\n");
}
}
//-------------------------------------//
// hazard turn update methods //
//-------------------------------------//
int Arigamo::calculateRoamChance(int entitiesAlive) {
// the chance of the Arigamo randomly roaming increases as the number of alive roaming opponents decrease
int roamChance = (baseRoamChance + (roamChanceMod / entitiesAlive)) * 100;
return roamChance;
}
void Arigamo::wakeArigamo(int entitiesAlive) {
// check to see if arigamo can be woken up
if (!conscious() && turnsToWake == 0) {
int wakeUp = rand() % (100 - calculateRoamChance(entitiesAlive));
if (wakeUp == 0) {
setIsConscious(true);
}
}
}
void Arigamo::resetTurnsToWake() {
turnsToWake = rand() % 7 + 3;
}
vector<string> Arigamo::drainPlayerHP(int* roomConnections, int total_rooms, Player& player) {
// drains the health of the player if they are close enough to the arigamo
// code adapted from:
// Madan, S. (2020). Passing a 2D Array as a Function Parameter in C and C++. Retrieved from https://medium.com/swlh/passing-a-2-d-array-as-a-function-parameter-in-c-mainly-c-7a29d196530a
vector<string> results;
if (canDrainPlayer(roomConnections, total_rooms, player.getCurrentRoom())) {
player.updateHealth(-healthDrainRate);
results.push_back(eventDescriptions[5]);
if (player.getHealthCurrent() == 0) {
results.push_back(" Your life has been completely drained.");
results.push_back("$");
}
}
return results;
}
bool Arigamo::canDrainPlayer(int* roomConnections, int total_rooms, int playerRoom) {
// checks whether the player is close enough to the Arigamo to be drained by applying breadth-first-search
if (!hasDied()) {
vector<int> dists(total_rooms, 0);
vector<int> visited;
deque<int> boundary;
boundary.push_back(currentRoom);
while (boundary.size() > 0) {
int v = boundary.front();
boundary.pop_front();
visited.push_back(v);
vector<int> nextCons = neighbours(roomConnections, total_rooms, v);
vector<int>::const_iterator iter;
for (iter = nextCons.begin(); iter != nextCons.end(); iter++) {
int u = *iter;
if (find(visited.begin(), visited.end(), u) == visited.end() && find(boundary.begin(), boundary.end(), u) == boundary.end()) {
boundary.push_back(u);
dists[u] += dists[v] + 1;
if (u == playerRoom && dists[u] < 3) {
return true;
}
}
}
}
}
return false;
}
vector<int> Arigamo::neighbours(int* roomConnections, int total_rooms, int room) {
// returns the neighbours of room from the input adjacency matrix roomConnections
vector<int> res;
for (int i = 0; i < total_rooms; i++) {
if (*((roomConnections + room * total_rooms) + i) == 1) {
res.push_back(i);
}
}
return res;
}
Item Arigamo::giveGem() {
// returns and removes the Fuhai gem from the Arigamo
Item gemTemp = fuhaiGem;
fuhaiGem = Item();
return gemTemp;
}
vector<string> Arigamo::updateInteraction(Hazard* hazard) {
// the arigamo's interaction with a hazard
vector<string> results;
if (!hasDied()) {
if (!hazard->hasDied() && hazard->isRoaming()) {
hazard->kill();
results.push_back(hazard->getEventDescriptions()[2]);
}
}
else {
if (hasGem() && !hazard->hasDied() && hazard->isRoaming()) {
hazard->setGem(giveGem());
}
}
return results;
}
vector<string> Arigamo::updateInteraction(Player& player) {
// the arigamo's interaction with the player
vector<string> results;
setHasInteracted(true);
if (!hasDied()) {
player.kill();
results.push_back(eventDescriptions[0]);
results.push_back(eventDescriptions[1]);
results.push_back("$");
}
else {
results.push_back(eventDescriptions[3]);
if (hasGem()) {
player.updateInventory(giveGem());
results.push_back(" You have retreived the Fuhai Gem!\n");
results.push_back("$");
}
else {
results.push_back(" The Fuhai Gem was nowhere to be found...\n");
results.push_back("$");
}
}
return results;
}