-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hazard.cpp
367 lines (253 loc) · 6.71 KB
/
Hazard.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
/**************************************************
Project: The Tamer, the Arigamo and the Fuhai Gem
Task: Assignment 2 + 3
Author: Sean Lee
Purpose: Hazard Class Definition File
The Definition file for the Hazard class which
serves as the base class for the game's hazards and
opponents.
**************************************************/
#include "Hazard.h"
int Hazard::numHazards = 0;
//-------------------------------------//
// static accessors //
//-------------------------------------//
int Hazard::getNumHazards() {
return numHazards;
}
//-------------------------------------//
// constructors and destructors //
//-------------------------------------//
Hazard::Hazard() {
numHazards++;
hazardID = -1;
hazardName = "";
hazardType = NOHAZARD;
currentRoom = 0;
hazardHint = "";
eventDescriptions = {};
isRoamingType = false;
isConscious = false;
isDead = false;
hasInteracted = false;
}
Hazard::Hazard(string name, HazardType type, string hint, vector<string> descriptions, bool roaming, bool conscious) {
numHazards++;
hazardID = numHazards;
hazardName = name;
hazardType = type;
currentRoom = 0;
hazardHint = hint;
eventDescriptions = descriptions;
isRoamingType = roaming;
isConscious = conscious;
isDead = false;
hasInteracted = false;
}
Hazard::~Hazard() {
--numHazards;
}
//-------------------------------------//
// accessor methods //
//-------------------------------------//
int Hazard::getID() {
return hazardID;
}
string Hazard::getName() {
return hazardName;
}
HazardType Hazard::getType() {
return hazardType;
}
string Hazard::getTypeAsString() {
switch (getType()) {
case ARIGAMO:
return "Arigamo";
case PIT:
return "Bottomless Pit";
case CCRAT:
return "Colony of Corrupted Rats";
case ORACLE:
return "Corrupted Oracle";
case THIEF:
return "Opportunistic Thief";
case RAIDERS:
return "Outcasted Raiders";
case TRADER:
return "Suspicious Trader";
case KNIGHT:
return "Dark Knight";
default:
return "No type has been assigned";
}
}
int Hazard::getCurrentRoom() {
return currentRoom;
}
string Hazard::getHint() {
return hazardHint;
}
vector<string> Hazard::getEventDescriptions() {
return eventDescriptions;
}
string Hazard::getDescriptionsAsString() {
// returns contents of eventDescriptions as string
// adapted from Week 7 Lab notes
string descriptions = "";
if (!eventDescriptions.empty()) {
vector<string>::const_iterator iter;
for (iter = eventDescriptions.begin(); iter != eventDescriptions.end(); iter++) {
string line = *iter;
descriptions += line + ", ";
}
}
else {
descriptions = "There are no descriptions for the Hazard";
}
return descriptions;
}
bool Hazard::hasGem() {
if (fuhaiGem.getName() == "Fuhai Gem") {
return true;
}
else {
return false;
}
}
bool Hazard::isRoaming() {
return isRoamingType;
}
bool Hazard::conscious() {
return isConscious;
}
bool Hazard::hasDied() {
return isDead;
}
bool Hazard::interacted() {
return hasInteracted;
}
string Hazard::getDetails() {
// returns the class details of the hazard as formatted string
stringstream hazardDetails;
hazardDetails << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
hazardDetails << " Hazard ID: " << getID() << "\n";
hazardDetails << " Hazard Name: " << getName() << "\n";
hazardDetails << " Hazard 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 << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
return hazardDetails.str();
}
//-------------------------------------//
// mutator methods //
//-------------------------------------//
void Hazard::setID(int ID) {
if (ID >= 0) {
hazardID = ID;
}
else {
displayString(" You have not entered a valid hazard ID to set.\n");
}
}
void Hazard::setName(string name) {
if (name.find_first_not_of(' ') != string::npos) {
hazardName = name;
}
else {
displayString(" You have not entered a valid hazard name to set.\n");
}
}
void Hazard::setType(HazardType type) {
if (type != NULL) {
hazardType = type;
}
else {
displayString(" You have not entered a valid hazard type to set.\n");
}
}
void Hazard::setStartingRoom(RoomContainer& world, int room) {
// sets the hazard's starting room
if (room >= 0) {
currentRoom = room;
world.getRoom(room)->addHazard(hazardID);
}
else {
displayString(" You have not entered a starting room to set.\n");
}
}
void Hazard::setCurrentRoom(int room) {
if (room >= 0) {
currentRoom = room;
}
else {
displayString(" You have not entered a valid current room number to set.\n");
}
}
void Hazard::setHint(string hint) {
if (hint.find_first_not_of(' ') != string::npos) {
hazardHint = hint;
}
else {
displayString(" You have not entered a valid hazard hint to set.\n");
}
}
void Hazard::setRoamingType(bool isRoaming) {
isRoamingType = isRoaming;
}
void Hazard::setIsConscious(bool conscious) {
isConscious = conscious;
}
void Hazard::setIsDead(bool dead) {
isDead = dead;
}
void Hazard::setEventDescriptions(vector<string> events) {
if (!events.empty()) {
eventDescriptions = events;
}
else {
displayString(" You have not entered a valid hazard description vector to set.\n");
}
}
void Hazard::setGem(Item gem) {
if (gem.getName() != "Fuhai Gem") {
fuhaiGem = gem;
}
else {
displayString(" You have not given a valid gem.\n");
}
}
void Hazard::setHasInteracted(bool interacted) {
hasInteracted = interacted;
}
void Hazard::kill() {
// kills the hazard
isDead = true;
isConscious = false;
}
//-------------------------------------//
// movement methods //
//-------------------------------------//
void Hazard::moveTo(RoomContainer& world, int room) {
// moves the hazard into the desired room and updates the appropriate rooms
world.getRoom(currentRoom)->removeHazard(hazardID);
setCurrentRoom(room);
world.getRoom(room)->addHazard(hazardID);
}
vector<string> Hazard::updateInteraction() {
vector<string> updateDescriptions = {"There are no interactions."};
setHasInteracted(true);
return updateDescriptions;
}
void Hazard::roomInteraction() {
if (isDead) {
displayString("\n" + eventDescriptions[3] + "\n");
}
else {
displayString("\n There is nothing in the Room to interact with.");
}
}