-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent_handler.cpp
669 lines (588 loc) · 21.8 KB
/
event_handler.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
/*
* Justin W Li
* event_handler.cpp
* Event handler function implementations
* Event function implementations
*/
#include "event_handler.h"
//-------------------------------------
//----EVENT HANDLER IMPLEMENTATIONS----
//-------------------------------------
//ctor
event_handler::event_handler() : events(), curr_event(nullptr) {}
//dtor
event_handler::~event_handler() { clear_events(); } //delete each event in the event list
//comparison function
bool event_handler::comp::operator()(game_event* lhs, game_event* rhs) const
{
return lhs->get_prio() < rhs->get_prio();
}
//adds event to queue
void event_handler::add_event(game_event* e) {
if (e == nullptr)
{
throw event_handler::bad_event();
return;
}
//make pair and push
events.push(e);
}
//replaces current event with event at top of queue; pops queue
//returns true if operation was performed successfully, otherwise returns false
bool event_handler::next_event() {
if (curr_event != nullptr)
{
delete curr_event;
curr_event = nullptr;
}
if (!events.empty())
{
curr_event = events.top();
events.pop();
return true;
}
else return false;
}
void event_handler::run_events() {
//execute all events
while (!events.empty())
events.top()->start_event();
}
void event_handler::clear_events() {
//delete current event
if (curr_event != nullptr)
{
delete curr_event;
curr_event = nullptr;
}
//delete every event in queue
while (!events.empty())
{
game_event* e = events.top();
events.pop();
delete e;
}
}
//returns type of event at top of queue; returns -1 if queue is empty
int event_handler::top_prio() const {
if (events.empty()) return -1;
else return events.top()->get_prio();
}
//----------------------------------
//----BASE EVENT IMPLEMENTATIONS----
//----------------------------------
//event function implementations
game_event::game_event(event_handler* evh_, room_handler* rh_, int prio,
void (room_handler::* pNotify_)()) :
evh(evh_), rh(rh_), priority(prio), pNotify(pNotify_) {
if (evh_ == nullptr) throw EVENT_EXCEPTION("Invalid event handler pointer!\n");
if (rh_ == nullptr) throw EVENT_EXCEPTION("Invalid room handler pointer!\n");
}
void game_event::start_event() {
//delete current event if necessary, then place event at top of queue into current_event
if(evh->next_event()) run_event();
}
void game_event::complete_event() {
if (priority == INPUT)
std::cout << std::endl; //print newline for readability
if((priority == COMBAT || priority == ROOM_OVER) && evh->top_prio() != FEEDBACK)
{
if(priority == COMBAT)
std::cout << "Press enter to start combat." << std::endl; //let player know that they're entering combat
else
std::cout << "Press enter to continue." << std::endl; //prompt player to press enter
while (std::cin.get() != '\n');
}
//notify room_handler of event, if notification function was inputted
if(pNotify != nullptr) (rh->*pNotify)();
}
int game_event::get_prio() const { return priority; }
enemy_event::enemy_event(event_handler* evh_, room_handler* rh_,
enemy_handler* enh_, int prio,
void (room_handler::* pNotify_)(), std::string(enemy_handler::* pName_)() const) try :
game_event(evh_, rh_, prio, pNotify_), enh(enh_), pName(pName_) {
if (enh_ == nullptr) throw EVENT_EXCEPTION("Invalid enemy handler pointer!\n");
if (pName_ == nullptr) throw EVENT_EXCEPTION("Invalid enemy name function pointer!\n");
}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
player_event::player_event(event_handler* evh_, room_handler* rh_, player* p_, int prio,
void (room_handler::* pNotify_)()) try :
game_event(evh_, rh_, prio, pNotify_), p(p_) {
if (p_ == nullptr) throw EVENT_EXCEPTION("Invalid player pointer!\n");
}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
//input reception event
input_event::input_event(event_handler* evh_, room_handler* rh_, word_handler* wh_,
game_event* pPassEvent_, game_event* pFailEvent_, int prio) try :
game_event(evh_, rh_, prio), wh(wh_), pPassEvent(pPassEvent_), pFailEvent(pFailEvent_) {
if (wh_ == nullptr) throw EVENT_EXCEPTION("Invalid word handler pointer!\n");
}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
//------------------------------------
//----GAMESTATE/ROOM EVENT CLASSES----
//------------------------------------
//load event
game_load::game_load(event_handler* evh_, room_handler* rh_, word_handler* wh_, int prio) try :
game_event(evh_, rh_, prio), wh(wh_) {
if (wh_ == nullptr) throw EVENT_EXCEPTION("Invalid word handler pointer!\n");
}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
void game_load::run_event() {
std::cout << "Loading word bank..." << std::endl;
wh->load_bank();
complete_event();
}
//intro event
game_intro::game_intro(event_handler* evh_, room_handler* rh_, word_handler* wh_,
player* p_, int prio) try :
game_event(evh_, rh_, prio), wh(wh_), p(p_) {
if (wh_ == nullptr) throw EVENT_EXCEPTION("Invalid word handler pointer!\n");
}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
void game_intro::run_event() {
//print intro
std::cout << "Welcome to Goblins! Prepare to go from room to room in a dungeon." << std::endl;
std::cout << "In each room, goblins will line up to fight you, one at a time." << std::endl;
std::cout << "Attack the goblins and dodge their attacks by quickly typing in the words they throw at you!" << std::endl;
std::cout << "Be warned that if you either spell the word wrong or fail to type it in time," << std::endl;
std::cout << "you will either miss your attack or get hit by that of goblin's. It's not case-sensitive, though." << std::endl;
std::cout << "You'll move to the next room once there are no goblins left in line." << std::endl;
try {
//add start/exit event
evh->add_event(new non_combat_event(evh, rh, wh,
new player_start(evh, rh, p),
new player_quit(evh, rh, p),
"Start", "Quit"));
}
catch (std::bad_alloc& e) { //check for alloc failure
throw e.what();
}
complete_event();
}
//turn over event for room
turn_over::turn_over(event_handler* evh_, room_handler* rh_, int prio,
void (room_handler::* pNotify_)()) try :
game_event(evh_, rh_, prio, pNotify_) {}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
void turn_over::run_event() {
complete_event(); //just complete the event
}
//room over event for room
room_over::room_over(event_handler* evh_, room_handler* rh_, enemy_handler* enh_,
int prio, void (room_handler::* pNotify_)()) try :
game_event(evh_, rh_, prio, pNotify_), enh(enh_) {
if (enh_ == nullptr) throw EVENT_EXCEPTION("Invalid enemy handler pointer!\n");
}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
void room_over::run_event() {
std::cout << "There are no more goblins in the room. You go and step into the next room." << std::endl;
rh->room_over(); //evaluate player performance
enh->set_stage(rh->get_performance()); //update stage
enh->set_thresholds(); //update thresholds
complete_event();
}
//-----------------------------------------
//----INPUT EVENT CLASS IMPLEMENTATIONS----
//-----------------------------------------
combat_event::combat_event(event_handler* evh_, room_handler* rh_,
word_handler* wh_, enemy_handler* enh_, game_event* pPassEvent_,
game_event* pFailEvent_, int prio) try :
input_event(evh_, rh_, wh_, pPassEvent_, pFailEvent_, prio),enh(enh_) {
if (enh_ == nullptr) throw EVENT_EXCEPTION("Invalid enemy handler pointer!\n");
}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
void combat_event::run_event() {
//time that event started checking for input
std::chrono::steady_clock::time_point start_t = std::chrono::steady_clock::now();
//generate a string based on the type
std::string str = wh->get_string(enh->get_type());
//prompt user for string
std::string user_str;
std::cout << "Type \"" << str << "\"." << std::endl;
std::cin >> user_str;
//calculate time to complete
unsigned int wait_t = static_cast<unsigned int>(std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now() - start_t).count());
//check that strings match, and that maximum time wasn't exceeded
if (wh->string_compare(str, user_str) && wait_t < (str.size() * 250 + 1500)) //250 milliseconds per letter, plus 1.5 seconds to read
{
try {
evh->add_event(pPassEvent); //event failed, add fail event
}
catch (std::bad_alloc& e) { //check for alloc failure
throw e.what();
}
delete pFailEvent; //fail event not needed; delete
}
else
{
try {
evh->add_event(pFailEvent); //event failed, add fail event
}
catch (std::bad_alloc& e) { //check for alloc failure
throw e.what();
}
delete pPassEvent; //pass event not needed; delete
}
//wait for user to lift enter
while (std::cin.get() != '\n');
complete_event();
}
non_combat_event::non_combat_event(event_handler* evh_, room_handler* rh_,
word_handler* wh_, game_event* pPassEvent_, game_event* pFailEvent_,
std::string pass_, std::string fail_, int prio) try :
input_event(evh_, rh_, wh_, pPassEvent_, pFailEvent_, prio),
pass(pass_), fail(fail_)
{
//check that pass, fail don't match
if (wh->string_compare(pass, fail))
{
//destroy pass/fail events, throw exception
delete pPassEvent;
delete pFailEvent;
throw game_event::EVENT_EXCEPTION("Pass, fail strings cannot match!\n");
}
}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
void non_combat_event::run_event() {
std::string user_str;
bool pass_event = false;
bool fail_event = false;
do {
//prompt user for string until entry matches either pass string or fail string
std::cout << "Type \"" << pass << "\" or \"" << fail << "\"." << std::endl;
std::cin >> user_str;
pass_event = wh->string_compare(user_str, pass);
fail_event = wh->string_compare(user_str, fail);
if (!(pass_event || fail_event))
{
//input matches neither; prompt user to try again
std::cout << "Sorry, input was not recognized. Please try again." << std::endl;
}
} while (!pass_event && !fail_event);
if (pass_event)
{
try {
evh->add_event(pPassEvent); //event failed, add fail event
}
catch (std::bad_alloc& e) { //check for alloc failure
throw e.what();
}
delete pFailEvent; //pass event not needed; delete
}
else
{
try {
evh->add_event(pFailEvent); //event failed, add fail event
}
catch (std::bad_alloc& e) { //check for alloc failure
throw e.what();
}
delete pPassEvent; //pass event not needed; delete
}
while (std::cin.get() != '\n');
complete_event();
}
//-----------------------------------------
//----ENEMY EVENT CLASS IMPLEMENTATIONS----
//-----------------------------------------
//enemy spawn event function implementations
enemy_spawn::enemy_spawn(event_handler* evh_, room_handler* rh_, enemy_handler* enh_,
int prio, void (room_handler::* pNotify_)()) try :
enemy_event(evh_, rh_, enh_, prio, pNotify_, &enemy_handler::last_name) {}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
void enemy_spawn::run_event() {
enh->spawn();
std::cout << "A " << (enh->*pName)() << " just got in line!" << std::endl;
std::cout << "HP: " << enh->hp_back() << ", " << "ATK: " << enh->attack_back() << std::endl;
int gobs_left = enh->enemies_left();
if (gobs_left != 1)
std::cout << "There are now " << gobs_left << " goblins in line." << std::endl;
else
std::cout << "There is now " << gobs_left << " goblin in line." << std::endl; //singular
complete_event();
}
//enemy attack event function implementations
enemy_attack::enemy_attack(event_handler* evh_, room_handler* rh_, word_handler* wh_,
enemy_handler* enh_, player* p_, int prio) try :
enemy_event(evh_, rh_, enh_, prio), p(p_), wh(wh_) {
if (p_ == nullptr) throw EVENT_EXCEPTION("Invalid player pointer!\n");
if (wh_ == nullptr) throw EVENT_EXCEPTION("Invalid word handler pointer!\n");
}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
void enemy_attack::run_event() {
//check that there are enemies
if (!enh->empty())
{
std::cout << "The " << (enh->*pName)() << " is attacking!" << std::endl;
try {
//create input event
evh->add_event(static_cast<game_event*>(new combat_event(evh, rh, wh, enh,
static_cast<game_event*>(new player_dodge(evh, rh, p)), //event success
static_cast<game_event*>(new player_defend(evh, rh, wh, enh, p, enh->attack())) //event fail
)));
}
catch (std::bad_alloc& e) { //check for alloc failure
throw e.what();
}
complete_event();
}
}
//enemy defense event function implementations
enemy_defend::enemy_defend(event_handler* evh_, room_handler* rh_, enemy_handler* enh_,
player* p_, int prio, void (room_handler::* pNotify_)()) try :
enemy_event(evh_, rh_, enh_, prio, pNotify_), p(p_) {
if (p_ == nullptr) throw EVENT_EXCEPTION("Invalid player pointer!\n");
}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
void enemy_defend::run_event() {
std::cout << "The " << (enh->*pName)() << " takes " << p->attack() << " damage!" << std::endl;
enh->defend(p->attack());
//check if enemy is alive; kill if dead
if (!enh->alive())
{
try {
//add enemy death event
evh->add_event(static_cast<game_event*>(new enemy_die(evh, rh, enh, p)));
}
catch (std::bad_alloc& e) { //check for alloc failure
throw e.what();
}
}
else
std::cout << "It still has " << enh->hp() << " hp." << std::endl;
complete_event();
}
//enemy death event function implementations
enemy_die::enemy_die(event_handler* evh_, room_handler* rh_, enemy_handler* enh_,
player* p_, int prio, void (room_handler::* pNotify_)()) try :
enemy_event(evh_, rh_, enh_, prio, pNotify_), p(p_) {
if (p_ == nullptr) throw EVENT_EXCEPTION("Invalid player pointer!\n");
}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
void enemy_die::run_event() {
std::cout << "The " << (enh->*pName)() << " is dead!" << std::endl;
//give player exp
try {
//add player exp event
evh->add_event(static_cast<game_event*>(new player_exp(evh, rh, p, enh->exp())));
}
catch (std::bad_alloc& e) { //check for alloc failure
throw e.what();
}
//kill enemy
enh->die();
int gobs_left = enh->enemies_left();
if (gobs_left)
{
//enemy at front of new line is different; notify player
std::cout << "A " << (enh->*pName)() << " steps up to take its place." << std::endl;
if (gobs_left != 1)
std::cout << "There are " << gobs_left << " goblins left in line." << std::endl;
else
std::cout << "There is " << gobs_left << " goblin left in line." << std::endl; //singular
}
else
{
//create a new room
try {
evh->add_event(static_cast<game_event*>(new room_over(evh, rh, enh)));
}
catch (std::bad_alloc& e) { //check for alloc failure
throw e.what();
}
}
complete_event();
}
//------------------------------------------
//----PLAYER EVENT CLASS IMPLEMENTATIONS----
//------------------------------------------
player_attack::player_attack(event_handler* evh_, room_handler* rh_, word_handler* wh_,
enemy_handler* enh_, player* p_, int prio) try :
player_event(evh_, rh_,p_, prio), enh(enh_), wh(wh_), pName(&enemy_handler::curr_name) {
if (enh_ == nullptr) throw EVENT_EXCEPTION("Invalid enemy handler pointer!\n");
if (wh_ == nullptr) throw EVENT_EXCEPTION("Invalid word handler pointer!\n");
}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
void player_attack::run_event(){
std::cout << "Attack the " << (enh->*pName)() << "!" << std::endl;
//create input event
try {
//add player exp event
evh->add_event(static_cast<game_event*>(new combat_event(evh, rh, wh, enh,
new enemy_defend(evh, rh, enh, p),
new player_miss(evh, rh, p))));
}
catch (std::bad_alloc& e) { //check for alloc failure
throw e.what();
}
complete_event();
}
//player dodge event
player_miss::player_miss(event_handler* evh_, room_handler* rh_, player* p_, int prio) try :
player_event(evh_, rh_, p_, prio) {}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
void player_miss::run_event() {
std::cout << "You missed!" << std::endl;
complete_event();
}
//player dodge event function implementations
player_dodge::player_dodge(event_handler* evh_, room_handler* rh_, player* p_, int prio,
void (room_handler::* pNotify_)()) try :
player_event(evh_, rh_, p_, prio, pNotify_) {}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
void player_dodge::run_event() {
std::cout << "You dodged the attack!" << std::endl;
complete_event();
}
//player defense function implementations
player_defend::player_defend(event_handler* evh_, room_handler* rh_, word_handler* wh_,
enemy_handler* enh_, player* p_, int dmg_, int prio) try :
player_event(evh_, rh_, p_, prio), wh(wh_), enh(enh_), dmg(dmg_) {
if (enh_ == nullptr) throw EVENT_EXCEPTION("Invalid enemy handler pointer!\n");
if (wh_ == nullptr) throw EVENT_EXCEPTION("Invalid word handler pointer!\n");
}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
void player_defend::run_event() {
std::cout << "You got hit and took " << dmg << " damage." << std::endl;
p->defend(dmg);
if (!p->alive()) //kill player if hp drops below zero
{
try {
//add player exp event
evh->add_event(static_cast<game_event*>(new player_die(evh, rh, wh, enh, p)));
}
catch (std::bad_alloc& e) { //check for alloc failure
throw e.what();
}
}
else
std::cout << "You still have " << p->health() << " hp." << std::endl;
complete_event();
}
//player exp gain function implementations
player_exp::player_exp(event_handler* evh_, room_handler* rh_, player* p_,
int exp_, int prio) try :
player_event(evh_, rh_, p_, prio), exp(exp_) {}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
void player_exp::run_event() {
std::cout << "You gained " << exp << " EXP!" << std::endl;
p->gain_exp(exp);
//check that player has leveled up
if (p->can_level())
{
try {
//add player exp event
evh->add_event(static_cast<game_event*>(new player_levelup(evh, rh, p)));
}
catch (std::bad_alloc& e) { //check for alloc failure
throw e.what();
}
}
complete_event();
}
//player level up event function implementations
player_levelup::player_levelup(event_handler* evh_, room_handler* rh_,
player* p_, int prio) try :
player_event(evh_, rh_, p_, prio) { }
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
void player_levelup::run_event() {
std::cout << "You leveled up!" << std::endl;
p->level_up();
p->print_stats();
complete_event();
}
//player death function implementations
player_die::player_die(event_handler* evh_, room_handler* rh_, word_handler* wh_,
enemy_handler* enh_, player* p_, int prio, void (room_handler::* pNotify_)()) try :
player_event(evh_, rh_, p_, prio, pNotify_), wh(wh_), enh(enh_) {
if (enh_ == nullptr) throw EVENT_EXCEPTION("Invalid enemy handler pointer!\n");
if (wh_ == nullptr) throw EVENT_EXCEPTION("Invalid word handler pointer!\n");
}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
void player_die::run_event() {
std::cout << "You died. Would you like to continue?" << std::endl;
try {
//add choice to continue/quit
evh->add_event(new non_combat_event(evh, rh, wh,
new player_continue(evh, rh, enh, p),
new player_quit(evh, rh, p)));
}
catch (std::bad_alloc& e) { //check for alloc failure
throw e.what();
}
complete_event();
}
player_continue::player_continue(event_handler* evh_, room_handler* rh_, enemy_handler* enh_,
player* p_, int prio) try :
player_event(evh_, rh_, p_, prio), enh(enh_) {
if (enh_ == nullptr) throw EVENT_EXCEPTION("Invalid enemy handler pointer!\n");
}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
void player_continue::run_event() {
//restart the room, but keep most metrics
std::cout << "Reseting the room." << std::endl;
p->fully_heal();
rh->reset();
enh->kill_all();
complete_event();
}
player_start::player_start(event_handler* evh_, room_handler* rh_, player* p_, int prio) try :
player_event(evh_, rh_, p_, prio) {}
catch (const game_event::EVENT_EXCEPTION& e) { //catch exceptions from initializer list
throw e.what();
}
void player_start::run_event() {
std::cout << "You walk into the dungeon. It smells like goblin in here!" << std::endl;
complete_event();
}
player_quit::player_quit(event_handler* evh_, room_handler* rh_, player* p_, int prio) :
player_event(evh_, rh_, p_, prio) {}
void player_quit::run_event() {
std::cout << "Thanks for playing!" << std::endl; //todo -- score/leaderboard stuff here
p->game_over(); //ensure hp is zero; player is dead
evh->clear_events(); //clear queue
//do not call complete_event; no need to call callback or wait for user
}