-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cpp
More file actions
568 lines (483 loc) · 21.8 KB
/
Game.cpp
File metadata and controls
568 lines (483 loc) · 21.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
/*******************************************************************************
* ** Author: Gavin Slusher
* ** Date: 6/2/2019
* ** Description: Game class implementation file. Contains game logic to house
* Spaces, link, declare, and create the scenes between them.
* Also contains logic to play the game until a Space returns
* a condition that ends it.
* ** *************************************************************************/
#include <iostream>
#include <string>
#include "Game.hpp"
#include "displayMenu.hpp"
using std::cout;
using std::cin;
using std::endl;
/*******************************************************************************
* Game::Game()
* Constructor. Takes no parameters and hardcodes the appropriate spaces
* within the game. Also sets other game conditions.
*******************************************************************************/
Game::Game()
: camp(),
cabin(CABIN_WIDTH, CABIN_HEIGHT, " CABIN"),
cabin2(CABIN_WIDTH, CABIN_HEIGHT, " CABIN"),
cabin3(CABIN_WIDTH, CABIN_HEIGHT, " CABIN"),
forest(FOREST_WIDTH, FOREST_HEIGHT, " FOREST III"),
forestBR(FOREST_WIDTH, FOREST_HEIGHT, " FOREST IV"),
forestTR(FOREST_WIDTH, FOREST_HEIGHT, " FOREST II"),
forestTL(FOREST_WIDTH, FOREST_HEIGHT, " FOREST I")
{
steps = 350;
solvedRiddle = false;
checkEnd = false;
}
/*******************************************************************************
* void Game::initializeGame()
* Method to initialize the game. Creats Spaces, links them, sets their
* transition scenes, and sets the starting space and player location.
*******************************************************************************/
void Game::initializeGame()
{
//Create Spaces
camp.createSpace();
cabin.createSpace();
cabin2.createSpace();
cabin3.createSpace();
forest.createSpace();
forestBR.createSpace();
forestTR.createSpace();
forestTL.createSpace();
//Link Spaces
camp.linkSpaces(nullptr, nullptr, nullptr, &cabin);
cabin.linkSpaces(nullptr, nullptr, nullptr, &cabin2);
cabin2.linkSpaces(nullptr, nullptr, nullptr, &cabin3);
cabin3.linkSpaces(nullptr, nullptr, nullptr, &forest);
forest.linkSpaces(&forestTL, nullptr, nullptr, &forestBR);
forestBR.linkSpaces(&forestTR, nullptr, &forest, nullptr);
forestTR.linkSpaces(nullptr, &forestBR, &forestTL, nullptr);
forestTL.linkSpaces(nullptr, &forest, nullptr, &forestTR);
//Set Descriptions / Cutscenes
setCampScene();
setDefaultCamp();
setCabinScene();
setDefaultCabin();
setForestScene();
setDefaultForest();
//Set Default Start
currentSpace = &camp;
camp.setPlayer(7, 5);
}
/*******************************************************************************
* void Game::mainGame()
* Main game function. Contains logic for the Main Game:
*******************************************************************************/
void Game::mainGame()
{
initializeGame();
playIntro();
currentSpace->getCutscene();
cout << endl;
currentSpace->setIfPlayed(true);
currentSpace->displaySpace();
char move;
do
{
move = movement();
clearScreen();
currentSpace->playerAction(move);
currentSpace = currentSpace->getCurrentSpace();
if(move != 'q')
{
if (!currentSpace->getIfPlayed())
{
currentSpace->getCutscene();
currentSpace->setIfPlayed(true);
}
else
{
cout << endl;
currentSpace->getDefDes();
}
if (currentSpace->getName() == " FOREST III")
{
solvedRiddle = dynamic_cast<Forest *>(currentSpace)->getSolved();
}
checkEnd = currentSpace->getEndGame();
cout << endl;
currentSpace->displayName();
currentSpace->displaySpace();
steps--;
cout << "Actions left: " << steps << endl << endl;
}
}while(steps != 0 && move != 'q' && checkEnd == false);
if (steps == 0)
{
badEnding1();
}
else if (move == 'q')
{
cout << " " << endl;
}
else if (solvedRiddle == true && currentSpace->getPlayer()->checkInvSize() == 6)
{
goodEnding();
}
else if (solvedRiddle == true && currentSpace->getPlayer()->checkInvSize() < 6)
{
neutralEnding1();
}
else if (solvedRiddle == false && currentSpace->getPlayer()->checkInvSize() == 6)
{
neutralEnding2();
}
else
{
badEnding2();
}
}
/*******************************************************************************
* Game::setCurrentSpace()
* Sets the currentSpace pointer
*******************************************************************************/
void Game::setCurrentSpace(Space *spaceIn)
{
currentSpace = spaceIn;
}
/*******************************************************************************
* Game::playIntro()
* Plays game intro
*******************************************************************************/
void Game::playIntro()
{
clearScreen();
string Intro = " PRELUDE: You are a Pacific Crest Trail thru-hiker,\n";
Intro += " hiking from Mexico to Canada in a 5 month journey to 'find yourself.'\n";
Intro += " Along the way, you've joined three others. You don't know their\n";
Intro += " real names, but their trail names are Pepperoni, Sparrow, and Pina Colada.\n";
Intro += " The goal of this game will be to play out the ensuing events, gather items,\n";
Intro += " solve puzzles, and escape alive...\n";
cout << Intro << endl << endl;
enterToCont();
cout << endl;
string symbExplanation = " The game is represented by ASCII characters: \n";
symbExplanation += " 'A': You 'R': Pepperoni 'S': Sparrow 'P': Pina Colada\n";
symbExplanation += " 'o': An item 'X':A door to another area\n";
symbExplanation += "\n Everything else is just cosmetic. Good luck.";
cout << symbExplanation << endl << endl;
enterToCont();
clearScreen();
}
/*******************************************************************************
* Game::setCampScene()
* Sets the Camp scene
*******************************************************************************/
void Game::setCampScene()
{
string campScene = " ACT I\n";
campScene += " -----\n";
campScene += "\n";
campScene += " Another 5AM wake-up. You can hear Roni outside your tent\n";
campScene += " yelling, 'Wakey wakey, eggs and bakey!'\n\n If only. You haven't";
campScene += " had eggs and bacons for weeks. Anyway, it's time for you to \n";
campScene += " get out of bed and pack up. Time to get moving.\n";
camp.setCutscene(campScene);
}
/*******************************************************************************
* Game::setDefaultCamp()
* Sets the default camp message
*******************************************************************************/
void Game::setDefaultCamp()
{
string defaultScene = " Better pack up and get moving.\n";
camp.setDefDes(defaultScene);
}
/*******************************************************************************
* Game::setCabinScene()
* Sets the Cabin scene
*******************************************************************************/
void Game::setCabinScene()
{
string cabinScene = " ACT II\n";
cabinScene += " ------\n";
cabinScene += "\n";
cabinScene += " Rain and Thunder! The moment you began hiking, it began to pour.\n";
cabinScene += " One bolt struck so close, you could feel the hairs on the back\n";
cabinScene += " of your neck standing up from the static. What's worse, that\n";
cabinScene += " strike must have had some weird, EMP-Like effects because all\n";
cabinScene += " your electronics are out. Including your group's headlamps.\n";
cabinScene += "\n";
cabinScene += " Luckily, Pina had paper maps with him and found a cabin not\n";
cabinScene += " too far off trail...\n";
cabinScene += "\n";
cabinScene += " That's where our luck seems to end, though. On the inside of\n";
cabinScene += " the cabin door reads: 'Come and stay as you like, but do NOT\n";
cabinScene += " fall asleep. Else, it will find you. And you will die.'\n";
cabinScene += "\n";
cabinScene += " Your fellow travelors seem pretty superstitious, so they've\n";
cabinScene += " resolved themselves to staying awake for the night while we\n";
cabinScene += " wait out the storm. The cabin's pitch black, and you can \n";
cabinScene += " barely see your own hand in front of your face. The current\n";
cabinScene += " plan is to have one of each of the group stand in a corner,\n";
cabinScene += " and have one person walk from one corner along the wall to \n";
cabinScene += " the next, tapping the next person to make sure they're awake.\n";
cabinScene += "\n";
cabinScene += " You're going to be doing this all night. Better get started...\n";
cabin.setCutscene(cabinScene);
}
/*******************************************************************************
* Game::setDefaultCamp()
* Sets the default cabin message
*******************************************************************************/
void Game::setDefaultCabin()
{
string defaultScene = " I have to tap Sparrow's shoulder to make sure we\n";
defaultScene += " all stay awake.\n";
cabin.setDefDes(defaultScene);
cabin2.setCutscene(defaultScene);
cabin2.setDefDes(defaultScene);
cabin3.setCutscene(defaultScene);
cabin3.setDefDes(defaultScene);
}
/*******************************************************************************
* Game::setForestScene()
* Sets the Forest Scene
*******************************************************************************/
void Game::setForestScene()
{
string forestScene = " ACT III\n";
forestScene += " -------\n";
forestScene += "\n";
forestScene += " The four of you scramble over each other towards the cabin entrance\n";
forestScene += " Hands over elbows, you can't tell who you pushed out of the\n";
forestScene += " way, but you're the second one out the door. Outside now, you can see dawn \n";
forestScene += " breaking in the distance into a blood-red sunrise. The four of you\n";
forestScene += " scatter into the surrounding woods. And not far behind, a shadow\n";
forestScene += " follows too...\n";
forest.setCutscene(forestScene);
}
/*******************************************************************************
* Game::setDefaultCamp()
* Sets the default forest message
*******************************************************************************/
void Game::setDefaultForest()
{
string defaultScene = " We have to find some way to get out of here.\n";
forest.setDefDes(defaultScene);
forestBR.setCutscene(defaultScene);
forestBR.setDefDes(defaultScene);
forestTR.setCutscene(defaultScene);
forestTR.setDefDes(defaultScene);
forestTL.setCutscene(defaultScene);
forestTL.setDefDes(defaultScene);
}
/*******************************************************************************
* Game::goodEnding()
* Sets the good ending for the game.
*******************************************************************************/
void Game::goodEnding()
{
clearScreen();
cout << " The four of you sprint to the trailhead parking lot Pina mentioned." << endl;
cout << " Thank god for his maps!! You get there, and you can still hear the faint" << endl;
cout << " whirring of helicopter blades. You guess it must be out here scouting for" << endl;
cout << " wildfires from the storm." << endl;
cout << endl;
enterToCont();
clearScreen();
cout << " Roni gets an idea." << endl;
cout << endl;
cout << " 'Everyone, empty your pockets!' he says." << endl;
cout << endl;
cout << " You do so. You've got medical tape, matches, a ratty shirt, a ziplock bag of" << endl;
cout << " sugar, the oil pastels from Sparrow, and the stump remover from the cabin." << endl;
cout << endl;
cout << " 'Yes!' Roni says as if he knows something you don't, and he gets to work." << endl;
cout << endl;
cout << " Roni tapes the matches into a bundle and stuffs a strip of the ratty shirt" << endl;
cout << " into the head to make a fuse. Putting that aside, he then takes his camp " << endl;
cout << " stove and begins melting all the yellow and orange oil pastels down." << endl;
cout << endl;
cout << " 'Keep an eye on this!' he says to you, 'Once melted, I'm going to give you" << endl;
cout << " a mixture of this sugar and the stump remover... also known as potasium" << endl;
cout << " nitrate.'" << endl;
cout << endl;
enterToCont();
clearScreen();
cout << " He smiles. And for the first time since the cabin, you smile too. The pastels" << endl;
cout << " are melted now, and Roni starts pouring a white powder mixture into the" << endl;
cout << " pan." << endl;
cout << endl;
cout << " Once cooled, you help pack the resulting crumbly, clay-like mixture into an empty" << endl;
cout << " can (salvaged from Sparrow's dinner two days ago). While you can't see it," << endl;
cout << " you swear can feel the 'whop whop whop' of the helicopter in your chest- " << endl;
cout << " it's so close. You stuff the make-shift fuse into the can and light" << endl;
cout << " the shirt..." << endl;
cout << endl;
enterToCont();
clearScreen();
cout << " A brilliant orange-red smoke begins pouring out of the old can." << endl;
cout << " A smoke flare. Amazing that Roni could measure the ingedients out just right." << endl;
cout << " It's good that you're in an open lot, because even though the smoke" << endl;
cout << " dissipates a bit as it rises, it's able to break the treeline just fine." << endl;
cout << endl;
cout << " And you see it! The helicopter flies over head, and makes a clear circle" << endl;
cout << " around your location. You're saved!" << endl;
cout << endl;
cout << " The End." << endl;
}
/*******************************************************************************
* Game::neutralEnding1()
* Sets the neutral ending if riddle is solved
*******************************************************************************/
void Game::neutralEnding1()
{
clearScreen();
cout << " The four of you sprint to the trailhead parking lot Pina mentioned." << endl;
cout << " Thank god for his maps!! You get there, and you can still hear the faint" << endl;
cout << " whirring of helicopter blades. You guess it must be out here scouting for" << endl;
cout << " wildfires from the storm." << endl;
cout << endl;
enterToCont();
clearScreen();
cout << " Roni gets an idea." << endl;
cout << endl;
cout << " 'Everyone, empty your pockets!' he says." << endl;
cout << endl;
cout << " You do so, but you don't have much." << endl;
cout << endl;
cout << " 'Hmmm...' Roni says, 'We're so close, but there's not much I can do with this..." << endl;
cout << endl;
enterToCont();
clearScreen();
cout << " You see it! The helicopter flies overhead... but it just flies over." << endl;
cout << " Without signaling it somehow, you suppose that the four of you look just" << endl;
cout << " like regular hikers. You look back at the forest and being to feel a certain" << endl;
cout << " tightness in your chest." << endl;
cout << endl;
enterToCont();
clearScreen();
cout << " You have no choice but to move forward. The lot opens up into what must be" << endl;
cout << " a logging road. Hopefully it leads to a highway or something." << endl;
cout << " Though the sun is high in the sky, the shadows of the trees around you" << endl;
cout << " seem to cast long, reaching shadows." << endl;
cout << endl;
cout << " The four of you begin walking..." << endl;
cout << endl;
cout << " The End." << endl;
}
/*******************************************************************************
* Game::neutralEnding2()
* Sets the neutral ending if the riddle is not solved, but has all items
*******************************************************************************/
void Game::neutralEnding2()
{
clearScreen();
cout << " The three of you sprint through the forest, not knowing which direction" << endl;
cout << " to take. Your mind reflects briefly on Pina, but you push it away. You" << endl;
cout << " don't want to think about that mess you encountered after leaving the cabin." << endl;
cout << endl;
enterToCont();
clearScreen();
cout << " Roni gets an idea." << endl;
cout << endl;
cout << " 'Everyone, empty your pockets!' he says." << endl;
cout << endl;
cout << " You do so. You've got medical tape, matches, a ratty shirt, a ziplock bag of" << endl;
cout << " sugar, the oil pastels from Sparrow, and the stump remover from the cabin." << endl;
cout << endl;
cout << " 'Yes!' Roni says as if he knows something you don't, and he gets to work." << endl;
cout << endl;
cout << " Roni tapes the matches into a bundle and stuffs a strip of the ratty shirt" << endl;
cout << " into the head to make a fuse. Putting that aside, he then takes his camp " << endl;
cout << " stove and begins melting all the yellow and orange oil pastels down." << endl;
cout << endl;
cout << " 'Keep an eye on this!' he says to you, 'Once melted, I'm going to give you" << endl;
cout << " a mixture of this sugar and the stump remover... also known as potasium" << endl;
cout << " nitrate.'" << endl;
cout << endl;
enterToCont();
clearScreen();
cout << " He smiles. And for the first time since the cabin, you smile too. The pastels" << endl;
cout << " are melted now, and Roni starts pouring a white powder mixture into the" << endl;
cout << " pan." << endl;
cout << endl;
cout << " Once cooled, you help pack the resulting crumbly, clay-like mixture into an empty" << endl;
cout << " can (salvaged from Sparrow's dinner two days ago). While you can't see it," << endl;
cout << " you swear can feel the 'whop whop whop' of the helicopter in your chest- " << endl;
cout << " it's so close. You stuff the make-shift fuse into the can and light" << endl;
cout << " the shirt..." << endl;
cout << endl;
enterToCont();
clearScreen();
cout << " A brilliant orange-red smoke begins pouring out of the old can." << endl;
cout << " A smoke flare. Amazing that Roni could measure the ingedients out just right." << endl;
cout << " But while a bright orange hue at ground level, the smoke dissipates as" << endl;
cout << " it rises. When the smoke hits the treeline, it's like the color scatters," << endl;
cout << " and from a bird's-eye-view the smoke is barely noticeable." << endl;
cout << endl;
cout << " The helicopter passes overhead. You're stuck in the forest now." << endl;
cout << " You'll just have to find another way to escape." << endl;
cout << endl;
cout << " Though the sun is high in the sky, the shadows of the trees around you" << endl;
cout << " seem to cast long, reaching shadows." << endl;
cout << endl;
cout << " The three of you begin walking..." << endl;
cout << endl;
cout << " The End." << endl;
}
/*******************************************************************************
* Game::badEnding()
* Sets the bad ending if you run out of steps
*******************************************************************************/
void Game::badEnding1()
{
clearScreen();
cout << " You stop, gasping for breath. Falling to your knees, you would" << endl;
cout << " give anything for a deep gulp of fresh air. Instead, the it" << endl;
cout << " comes in thick, almost sticky. You don't notice the shadows" << endl;
cout << " around you beginning to twist, but you do feel the deep cold" << endl;
cout << " envelop you." << endl;
cout << endl;
cout << " Everything goes dark." << endl;
cout << endl;
cout << " The End." << endl;
}
/*******************************************************************************
* Game::badEnding()
* Sets the bad ending if the player neither solves the riddle nor has all the
* items
*******************************************************************************/
void Game::badEnding2()
{
clearScreen();
cout << " The three of you sprint through the forest, not knowing which direction" << endl;
cout << " to take. Your mind reflects briefly on Pina, but you push it away. You" << endl;
cout << " don't want to think about that mess you encountered after leaving the cabin." << endl;
cout << endl;
enterToCont();
clearScreen();
cout << " Roni gets an idea." << endl;
cout << endl;
cout << " 'Everyone, empty your pockets!' he says." << endl;
cout << endl;
cout << " You do so, but you don't have much." << endl;
cout << endl;
cout << " 'Hmmm...' Roni says, 'We're so close, but there's not much I can do with this..." << endl;
cout << endl;
enterToCont();
clearScreen();
cout << " You see it! The helicopter flies overhead... but it just flies over." << endl;
cout << " Without signaling it somehow, you suppose that the four of you look just" << endl;
cout << " like regular hikers. You look back into the forest and being to feel a certain" << endl;
cout << " tightness in your chest." << endl;
cout << endl;
enterToCont();
clearScreen();
cout << " Though the sun is high in the sky, the shadows of the trees around you" << endl;
cout << " seem to cast long, reaching shadows." << endl;
cout << endl;
cout << " The three of you begin walking..." << endl;
cout << endl;
cout << " The End." << endl;
}