/
d20Game.cpp
1662 lines (1492 loc) · 55 KB
/
d20Game.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
/**
* d20Game.cpp
* comp345-assignment-03
*
*/
#include <iostream>
#include "d20Game.h"
/**
* Observer/Windows/Info variables and functions
*/
// character basic panels
// basic window
WINDOW* d20Game::createWindowBasic() {
WINDOW* win = newwin(4, 16, 0, 0);
wborder(win, '|', '|', '-', '-', '+', '+', '+', '+');
return win;
}
void d20Game::updateBasic() {
mvwprintw(wBasic, 1, 2, player->getName().c_str());
mvwprintw(wBasic, 2, 2, player->getCharacterClass().c_str());
wrefresh(wBasic);
}
WINDOW* d20Game::createWindowVital() {
WINDOW* win = newwin(6, 16, 3, 0);
wborder(win, '|', '|', '-', '-', '+', '+', '+', '+');
return win;
}
void d20Game::updateVital() {
wclear(wVital);
wborder(wVital, '|', '|', '-', '-', '+', '+', '+', '+');
wrefresh(wVital);
stringstream msg;
msg << "HP: " << player->getHitPoint() << "/" << player->getMaxHitPoint();
mvwprintw(wVital, 1, 2, msg.str().c_str());
msg.str("");
msg.clear();
msg << "MP: " << player->getManaPoint() << "/" << player->getMaxManaPoint();
mvwprintw(wVital, 2, 2, msg.str().c_str());
msg.str("");
msg.clear();
int experiencePercent = (player->getExperience()/(double)player->getExperienceToLevel())*100;
msg << "EXP: " << experiencePercent << "%%";
mvwprintw(wVital, 3, 2, msg.str().c_str());
msg.str("");
msg.clear();
msg << "LVL: " << player->getLevel();
mvwprintw(wVital, 4, 2, msg.str().c_str());
msg.str("");
msg.clear();
wrefresh(wVital);
}
// ability window
WINDOW* d20Game::createWindowAbility() {
WINDOW* win = newwin(11, 16, 8, 0);
wborder(win, '|', '|', '-', '-', '+', '+', '+', '+');
return win;
}
void d20Game::updateAbility() {
wclear(wAbility);
wborder(wAbility, '|', '|', '-', '-', '+', '+', '+', '+');
wrefresh(wAbility);
stringstream msg;
msg << "CON: " << player->getAbilityScore(CON);
mvwprintw(wAbility, 1, 2, msg.str().c_str());
msg.str("");
msg.clear();
msg << "STR: " << player->getAbilityScore(STR);
mvwprintw(wAbility, 2, 2, msg.str().c_str());
msg.str("");
msg.clear();
msg << "DEX: " << player->getAbilityScore(DEX);
mvwprintw(wAbility, 3, 2, msg.str().c_str());
msg.str("");
msg.clear();
msg << "INT: " << player->getAbilityScore(INT);
mvwprintw(wAbility, 4, 2, msg.str().c_str());
msg.str("");
msg.clear();
msg << "WIS: " << player->getAbilityScore(WIS);
mvwprintw(wAbility, 5, 2, msg.str().c_str());
msg.str("");
msg.clear();
msg << "CHR: " << player->getAbilityScore(CHR);
mvwprintw(wAbility, 6, 2, msg.str().c_str());
msg.str("");
msg.clear();
msg << "MAX. ATK: " << player->getMaxAttackBonus();
mvwprintw(wAbility, 7, 2, msg.str().c_str());
msg.str("");
msg.clear();
msg << "MAX. DMG: " << player->getMaxDamagBonus();
mvwprintw(wAbility, 8, 2, msg.str().c_str());
msg.str("");
msg.clear();
msg << "ARMOR: " << player->getArmorBonus();
mvwprintw(wAbility, 9, 2, msg.str().c_str());
msg.str("");
msg.clear();
wrefresh(wAbility);
}
// option window -- static
WINDOW* d20Game::createWindowOption() {
WINDOW* win = newwin(7, 16, 18, 0);
wborder(win, '|', '|', '-', '-', '+', '+', '+', '+');
return win;
}
void d20Game::updateOption() {
mvwprintw(wOption, 1, 2, "[i]nventory");
mvwprintw(wOption, 2, 2, "[d]interact");
mvwprintw(wOption, 3, 2, "[q]uit");
wrefresh(wOption);
}
// character inventory/equipments panels
WINDOW* d20Game::createWindowWeapon() {
WINDOW* win = newwin(5, 34, 0, 16);
wborder(win, '|', '|', '-', '-', '+', '+', '+', '+');
return win;
}
void d20Game::updateWeapon() {
wclear(wWeapon);
wborder(wWeapon, '|', '|', '-', '-', '+', '+', '+', '+');
stringstream msg;
mvwprintw(wWeapon, 1, 2, "[Character Panel]");
Weapon* mh = player->getEquippedWeapon(MAINHAND);
Weapon* oh = player->getEquippedWeapon(OFFHAND);
if (mh != NULL) {
if (mh->getWeaponWield() == TWOHAND) {
msg << "[M]H: " << (player->getEquippedWeapon(MAINHAND)->getName());
mvwprintw(wWeapon, 2, 2, msg.str().c_str());
msg.str("");
msg.clear();
msg << "[O]H: <OCCUPIED>";
mvwprintw(wWeapon, 3, 2, msg.str().c_str());
msg.str("");
msg.clear();
} else if (oh == NULL) {
msg << "[M]H: " << (player->getEquippedWeapon(MAINHAND)->getName());
mvwprintw(wWeapon, 2, 2, msg.str().c_str());
msg.str("");
msg.clear();
msg << "[O]H: -";
mvwprintw(wWeapon, 3, 2, msg.str().c_str());
msg.str("");
msg.clear();
} else {
msg << "[M]H: " << (player->getEquippedWeapon(MAINHAND)->getName());
mvwprintw(wWeapon, 2, 2, msg.str().c_str());
msg.str("");
msg.clear();
msg << "[O]H: " << (player->getEquippedWeapon(OFFHAND)->getName());
mvwprintw(wWeapon, 3, 2, msg.str().c_str());
msg.str("");
msg.clear();
}
} else if (oh != NULL) {
msg << "[M]H: -";
mvwprintw(wWeapon, 2, 2, msg.str().c_str());
msg.str("");
msg.clear();
msg << "[O]H: " << (player->getEquippedWeapon(OFFHAND)->getName());
mvwprintw(wWeapon, 3, 2, msg.str().c_str());
msg.str("");
msg.clear();
} else {
msg << "[M]H: -";
mvwprintw(wWeapon, 2, 2, msg.str().c_str());
msg.str("");
msg.clear();
msg << "[O]H: -";
mvwprintw(wWeapon, 3, 2, msg.str().c_str());
msg.str("");
msg.clear();
}
wrefresh(wWeapon);
}
// armor window
WINDOW* d20Game::createWindowArmor() {
WINDOW* win = newwin(8, 34, 4, 16);
wborder(win, '|', '|', '-', '-', '+', '+', '+', '+');
return win;
}
void d20Game::updateArmor() {
wclear(wArmor);
wborder(wArmor, '|', '|', '-', '-', '+', '+', '+', '+');
wrefresh(wArmor);
stringstream msg;
if (player->getEquippedArmor(HEAD) != NULL) {
msg << "[H]ead: " << player->getEquippedArmor(HEAD)->getName();
mvwprintw(wArmor, 1, 2, msg.str().c_str());
msg.str("");
msg.clear();
} else {
mvwprintw(wArmor, 1, 2, "[H]ead: -");
}
if (player->getEquippedArmor(CHEST) != NULL) {
msg << "[C]hest: " << player->getEquippedArmor(CHEST)->getName();
mvwprintw(wArmor, 2, 2, msg.str().c_str());
msg.str("");
msg.clear();
} else {
mvwprintw(wArmor, 2, 2, "[C]hest: -");
}
if (player->getEquippedArmor(HANDS) != NULL) {
msg << "[G]loves: " << player->getEquippedArmor(HANDS)->getName();
mvwprintw(wArmor, 3, 2, msg.str().c_str());
msg.str("");
msg.clear();
} else {
mvwprintw(wArmor, 3, 2, "[G]loves: -");
}
if (player->getEquippedArmor(FEET) != NULL) {
msg << "[F]eet: " << player->getEquippedArmor(FEET)->getName();
mvwprintw(wArmor, 4, 2, msg.str().c_str());
msg.str("");
msg.clear();
} else {
mvwprintw(wArmor, 4, 2, "[F]eet: -");
}
if (player->getEquippedArmor(WAIST) != NULL) {
msg << "[B]elt: " << player->getEquippedArmor(WAIST)->getName();
mvwprintw(wArmor, 5, 2, msg.str().c_str());
msg.str("");
msg.clear();
} else {
mvwprintw(wArmor, 5, 2, "[B]elt: -");
}
if (player->getEquippedArmor(FINGER) != NULL) {
msg << "[R]ing: " << player->getEquippedArmor(FINGER)->getName();
mvwprintw(wArmor, 6, 2, msg.str().c_str());
msg.str("");
msg.clear();
} else {
mvwprintw(wArmor, 6, 2, "[R]ing: -");
}
wrefresh(wArmor);
}
// inventory window
WINDOW* d20Game::createWindowInventory() {
WINDOW* win = newwin(13, 34, 11, 16);
wborder(win, '|', '|', '-', '-', '+', '+', '+', '+');
return win;
}
void d20Game::updateInventory() {
wclear(wInventory);
wborder(wInventory, '|', '|', '-', '-', '+', '+', '+', '+');
wrefresh(wInventory);
stringstream msg;
msg << "[Inventory " << (10 - player->emptyInventorySlot()) << "/10][Gold: " << player->getGold() << "g]";
mvwprintw(wInventory, 1, 2, msg.str().c_str());
msg.str("");
msg.clear();
for (int i = 0; i < 10; i++) {
Item* tmp = player->getInventoryItem(i);
if (tmp == NULL)
msg << i << ": -";
else
msg << i << ": " << (tmp->getName());
mvwprintw(wInventory, i+2, 2, msg.str().c_str());
msg.str("");
msg.clear();
}
wrefresh(wInventory);
}
// help window -- static
WINDOW* d20Game::createWindowHelp() {
WINDOW* win = newwin(12, 31, 0, 49);
wborder(win, '|', '|', '-', '-', '+', '+', '+', '+');
return win;
}
void d20Game::updateCharacterPaneHelp() {
wclear(wHelp);
wborder(wHelp, '|', '|', '-', '-', '+', '+', '+', '+');
wrefresh(wHelp);
mvwprintw(wHelp, 1, 2, "[Inventory Help]");
mvwprintw(wHelp, 2, 3, "ESC: Return to game.");
mvwprintw(wHelp, 3, 3, "\\d | [mohcgfbr]:");
mvwprintw(wHelp, 4, 3, " Item edit mode.");
wrefresh(wHelp);
}
void d20Game::updateItemPaneHelp() {
wclear(wHelp);
wborder(wHelp, '|', '|', '-', '-', '+', '+', '+', '+');
wrefresh(wHelp);
mvwprintw(wHelp, 1, 2, "[Item Help]");
mvwprintw(wHelp, 2, 3, "ESC: Quit item edit");
mvwprintw(wHelp, 3, 3, "D: Delete item");
mvwprintw(wHelp, 4, 3, "[\\d | [mohcgfbr]]:");
mvwprintw(wHelp, 5, 3, " Swap item slot");
wrefresh(wHelp);
}
void d20Game::updateMerchantPaneHelp() {
wclear(wHelp);
wborder(wHelp, '|', '|', '-', '-', '+', '+', '+', '+');
wrefresh(wHelp);
mvwprintw(wHelp, 1, 2, "[Merchant Help]");
mvwprintw(wHelp, 2, 3, "M: Access merchant's");
mvwprintw(wHelp, 3, 3, " stach");
mvwprintw(wHelp, 4, 3, "B: Buy an item");
mvwprintw(wHelp, 5, 3, "S: Sell an item");
mvwprintw(wHelp, 6, 3, "D: Delete an item");
wrefresh(wHelp);
}
void d20Game::updateChestPaneHelp() {
wclear(wHelp);
wborder(wHelp, '|', '|', '-', '-', '+', '+', '+', '+');
wrefresh(wHelp);
mvwprintw(wHelp, 1, 2, "[Merchant Help]");
mvwprintw(wHelp, 2, 3, "C: Access chest's");
mvwprintw(wHelp, 3, 3, " stach");
mvwprintw(wHelp, 4, 3, "T: Take an item");
//mvwprintw(wHelp, 5, 3, " Swap item slot");
wrefresh(wHelp);
}
// item window
WINDOW* d20Game::createWindowItem() {
WINDOW* win = newwin(12, 30, 12, 50);
wborder(win, '|', '|', '-', '-', '+', '+', '+', '+');
return win;
}
void d20Game::updateItem(Item* it) {
wclear(wItem);
wborder(wItem, '|', '|', '-', '-', '+', '+', '+', '+');
wrefresh(wItem);
stringstream msg;
if (it->getItemType() == IS_WEAPON) {
Weapon* wp = static_cast<Weapon*>(it);
wattron(wItem, A_STANDOUT);
mvwprintw(wItem, 1, 2, it->getName().c_str());
wattroff(wItem, A_STANDOUT);
msg << wp->getWeaponWield() << " Weapon";
mvwprintw(wItem, 2, 2, msg.str().c_str());
msg.str("");
msg << "Attack Bonus: " << wp->getAttackBonus();
mvwprintw(wItem, 3, 2, msg.str().c_str());
msg.str("");
msg << "Damage Bonus: " << wp->getDamageBonus();
mvwprintw(wItem, 4, 2, msg.str().c_str());
msg.str("");
msg << "Size: " << wp->getSize();
mvwprintw(wItem, 5, 2, msg.str().c_str());
msg.str("");
msg << "Cost: " << wp->getCost() << "g";
mvwprintw(wItem, 6, 2, msg.str().c_str());
msg.str("");
} else if (it->getItemType() == IS_ARMOR) {
Armor* am = static_cast<Armor*>(it);
wattron(wItem, A_STANDOUT);
mvwprintw(wItem, 1, 2, it->getName().c_str());
wattroff(wItem, A_STANDOUT);
msg << am->getSlot() << " Armor";
mvwprintw(wItem, 2, 2, msg.str().c_str());
msg.str("");
msg << "Armor Bonus: " << am->getArmor();
mvwprintw(wItem, 3, 2, msg.str().c_str());
msg.str("");
msg << "Max. Dexterity: " << am->getMaxDexterity();
mvwprintw(wItem, 4, 2, msg.str().c_str());
msg.str("");
int line = 5;
std::map<Attribute, int> stats = am->getStatsMap();
std::map<Attribute, int>::const_iterator itr;
for(itr = stats.begin(); itr != stats.end(); ++itr) {
if (itr->first == CON) {
msg << "CON: " << itr->second;
mvwprintw(wItem, line, 2, msg.str().c_str());
msg.str("");
line++;
} else if (itr->first == STR) {
msg << "STR: " << itr->second;
mvwprintw(wItem, line, 2, msg.str().c_str());
msg.str("");
line++;
} else if (itr->first == DEX) {
msg << "DEX: " << itr->second;
mvwprintw(wItem, line, 2, msg.str().c_str());
msg.str("");
line++;
} else if (itr->first == INT) {
msg << "INT: " << itr->second;
mvwprintw(wItem, line, 2, msg.str().c_str());
msg.str("");
line++;
} else if (itr->first == WIS) {
msg << "WIS: " << itr->second;
mvwprintw(wItem, line, 2, msg.str().c_str());
msg.str("");
line++;
} else if (itr->first == CHR) {
msg << "CHR: " << itr->second;
mvwprintw(wItem, line, 2, msg.str().c_str());
msg.str("");
line++;
}
}
msg << "Cost: " << am->getCost() << "g";
mvwprintw(wItem, line, 2, msg.str().c_str());
msg.str("");
} else if (it->getItemType() == IS_POTION) {
Potion* pt = static_cast<Potion*>(it);
wattron(wItem, A_STANDOUT);
mvwprintw(wItem, 1, 2, pt->getName().c_str());
wattroff(wItem, A_STANDOUT);
msg << "Amount: " << pt->getPotionPool();
mvwprintw(wItem, 2, 2, msg.str().c_str());
msg.str("");
msg << "Cost: " << pt->getCost() << "g";
mvwprintw(wItem, 3, 2, msg.str().c_str());
msg.str("");
} else if (it->getItemType() == IS_SHIELD) {
Shield* am = static_cast<Shield*>(it);
wattron(wItem, A_STANDOUT);
mvwprintw(wItem, 1, 2, it->getName().c_str());
wattroff(wItem, A_STANDOUT);
msg << am->getWeaponWield() << " Shield";
mvwprintw(wItem, 2, 2, msg.str().c_str());
msg.str("");
msg << "Armor Bonus: " << am->getArmor();
mvwprintw(wItem, 3, 2, msg.str().c_str());
msg.str("");
msg << "Cost: " << am->getCost() << "g";
mvwprintw(wItem, 4, 2, msg.str().c_str());
msg.str("");
}
wrefresh(wItem);
}
// console window
WINDOW* d20Game::createWindowConsole() {
WINDOW* win = newwin(1, 64, 24, 16);
wrefresh(win);
return win;
}
void d20Game::updateConsole(string str, bool log) {
wclear(wConsole);
mvwprintw(wConsole, 0, 1, str.c_str());
wrefresh(wConsole);
// append to combat log if applicable
if (log)
clog << str << std::endl;
}
void d20Game::updateConsole(stringstream* sstr, bool log) {
updateConsole((sstr->str()).c_str(), log);
sstr->str("");
sstr->clear();
}
// object specific window
WINDOW* d20Game::createWindowMerchant() {
WINDOW* win = newwin(12, 34, 0, 16);
wborder(win, '|', '|', '-', '-', '+', '+', '+', '+');
return win;
}
void d20Game::updateMerchantInventory(Merchant* merchant) {
wclear(wMerchantInventory);
wborder(wMerchantInventory, '|', '|', '-', '-', '+', '+', '+', '+');
wrefresh(wMerchantInventory);
stringstream msg;
mvwprintw(wMerchantInventory, 1, 2, "[Merchant]");
Item* temp;
// IMPORTANT HERE ONLY UPDATE 9 ITEMS FROM MERCHANT!!
for (int i = 0; i < merchant->size(); i++) {
temp = merchant->peek(i);
msg << i + 1 << ": " << temp->getName();
mvwprintw(wMerchantInventory, i+2, 2, msg.str().c_str());
msg.str("");
msg.clear();
}
wrefresh(wMerchantInventory);
}
// object specific window
WINDOW* d20Game::createWindowChest() {
WINDOW* win = newwin(12, 34, 0, 16);
wborder(win, '|', '|', '-', '-', '+', '+', '+', '+');
return win;
}
void d20Game::updateChestStach(Chest* chest) {
wclear(wChest);
wborder(wChest, '|', '|', '-', '-', '+', '+', '+', '+');
wrefresh(wChest);
stringstream msg;
mvwprintw(wChest, 1, 2, "[Chest]");
Item* temp;
// IMPORTANT HERE ONLY UPDATE 9 ITEMS FROM MERCHANT!!
for (int i = 0; i < chest->size(); i++) {
temp = chest->peek(i);
if (temp != NULL) {
msg << i + 1 << ": " << temp->getName();
mvwprintw(wChest, i+2, 2, msg.str().c_str());
msg.str("");
msg.clear();
} else {
msg << i + 1 << ": - ";
mvwprintw(wChest, i+2, 2, msg.str().c_str());
mvwprintw(wChest, i+2, 2, msg.str().c_str());
msg.str("");
msg.clear();
}
}
wrefresh(wChest);
}
WINDOW* d20Game::createWindowMonster() {
WINDOW* win = newwin(8, 16, 0, 64);
wborder(win, '|', '|', '-', '-', '+', '+', '+', '+');
return win;
}
void d20Game::updateMonsterVital(Character* monster) {
wclear(wMonster);
wborder(wMonster, '|', '|', '-', '-', '+', '+', '+', '+');
wrefresh(wMonster);
mvwprintw(wMonster, 1, 2, monster->getName().c_str());
mvwprintw(wMonster, 2, 2, monster->getCharacterClass().c_str());
mvwprintw(wMonster, 3, 0, "+--------------+");
stringstream msg;
msg << "HP: " << monster->getHitPoint() << "/" << monster->getMaxHitPoint();
mvwprintw(wMonster, 4, 2, msg.str().c_str());
msg.str("");
msg.clear();
msg << "MP: " << monster->getManaPoint() << "/" << player->getMaxManaPoint();
mvwprintw(wMonster, 5, 2, msg.str().c_str());
msg.str("");
msg.clear();
msg << "LVL: " << monster->getLevel();
mvwprintw(wMonster, 6, 2, msg.str().c_str());
msg.str("");
msg.clear();
wrefresh(wMonster);
}
// windows related functions
void d20Game::wkill(WINDOW* win) {
wborder(win, ' ', ' ', ' ',' ',' ',' ',' ',' ');
wclear(win);
wrefresh(win);
delwin(win);
}
void d20Game::loadCharacterPanel() {
wWeapon = createWindowWeapon();
updateWeapon();
wArmor = createWindowArmor();
updateArmor();
wInventory = createWindowInventory();
updateInventory();
// print character panel tip
updateConsole("Tip: Press ESC to return to the game.");
bool done = FALSE;
int c;
while (!done) {
// renew help menu
if (wHelp != NULL)
wkill(wHelp);
wHelp = createWindowHelp();
updateCharacterPaneHelp();
// clean the item panel
// kill item panel
if (wItem != NULL) {
wkill(wItem);
wItem = NULL;
}
switch (c = getch()) {
case 'm':
case 'o':
// kill character pane help n load item pane help
wkill(wHelp);
wHelp = createWindowHelp();
updateItemPaneHelp();
updateConsole("Tip: Press ESC to quit item edit.");
equippedWeaponEdit(c);
break;
case 'h':
case 'c':
case 'g':
case 'f':
case 'b':
case 'r':
equippedArmorEdit(c);
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
inventoryEdit(c);
break;
case 27:
done = TRUE;
break;
default:
break;
}
}
// destroy the character panes windows
killCharacterPanel();
}
void d20Game::killCharacterPanel() {
wkill(wWeapon);
wkill(wArmor);
wkill(wInventory);
wkill(wHelp);
if (wItem != NULL)
wkill(wItem);
wWeapon = NULL;
wArmor = NULL;
wInventory = NULL;
wHelp = NULL;
wItem = NULL;
updateConsole("");
// refresh the std map
// refreshmap(); -- to add later
}
/**
* Game playing related functions
*/
void d20Game::endgame() {
// level up the player automatically
// player->levelUp();
// save character stuffs // not implemented
// put character back to initial position calls
if (map->getAtLocation(player->getCoordinate()->y, player->getCoordinate()->x)->mapObjectType != EXIT)
map->getAtLocation(player->getCoordinate()->y, player->getCoordinate()->x)->mapObjectType = EMPTY;
player->setCoordinate(playerInitialCoordinate->y, playerInitialCoordinate->x);
map->getAtLocation(playerInitialCoordinate->y, playerInitialCoordinate->x)->mapObjectType = PLAYER;
// save map
map->save();
// end of ncurses
endwin();
}
void d20Game::start() {
// attach d20game as character observer
player->attachCharacterObserver(this);
/**
* others initialization
*/
// attach combat log file
clog.open("combat.log");
/**
* Building ncurses windows
*/
// initiate basic ncurses funcs
initscr();
noecho();
curs_set(0);
raw();
keypad(stdscr, TRUE);
wclear(stdscr);
refresh();
// basic character windows
wBasic = createWindowBasic();
wVital = createWindowVital();
wAbility = createWindowAbility();
wOption = createWindowOption();
// update basic character windows
updateBasic();
updateVital();
updateAbility();
updateOption(); // static
// console window
wConsole = createWindowConsole();
updateConsole("Tip: Use the arrow key to move your character!");
/**
* End of ncurses initiation
*/
/**
* Setting object coordinates based on the map
*/
// getting player coordinate
setPlayerCoordinate();
Coordinate* playerCoord = player->getCoordinate();
playerInitialCoordinate = new Coordinate(playerCoord->y, playerCoord->x);
/**
* Game loop mode
*/
int c;
bool quit = FALSE;
stringstream msg;
// print tip
updateConsole("Tip: Use the arrow key to move your character!");
while (!quit) {
// check player location see if it is at the exit
playerCoord = player->getCoordinate();
if ((map->getAtLocation(playerCoord->y, playerCoord->x))->mapObjectType != EXIT) {
// refresh map on screen
refreshmap();
switch (c = getch()) {
case KEY_UP:
case KEY_DOWN:
case KEY_LEFT:
case KEY_RIGHT:
move(c);
break;
case 'm':
player->levelUp();
break;
case 'i':
loadCharacterPanel();
break;
case 'd':
interactWithEnvironment();
break;
case 's':
updateConsole("Error: There aren't any merchant around!");
case 'q':
updateConsole("Are you sure you want to end the game? (y/n) ");
if ((c = getch()) == 'y') {
quit = TRUE;
break;
} else {
updateConsole("Tip: Use the arrow key to move your character!");
}
break;
default:
break;
}
} else {
// save the character
// do exit callings
quit = TRUE;
}
}
// end of game
endgame();
}
/**
* Player actions/interactions
*/
void d20Game::interactWithEnvironment() {
if (getPrioritaryInteractableObject()->mapObjectType == MONSTER)
interactWithMonster();
else if (getPrioritaryInteractableObject()->mapObjectType == TREASURE_CHEST)
interactWithChest();
else if (getPrioritaryInteractableObject()->mapObjectType == MERCHANT)
interactWithMerchant();
else if (getPrioritaryInteractableObjectRadius2()->mapObjectType == MONSTER)
if (player->getEquippedWeapon(MAINHAND) != NULL && player->getEquippedWeapon(MAINHAND)->getWeaponType() == IS_RANGE)
interactWithMonster();
else
updateConsole("Error: A ranged weapon is required for this interaction!");
else
updateConsole("Error: There aren't anything around you to interact with!");
}
void d20Game::interactWithMerchant() {
// create a new merchant
MerchantBuilder* mb = new MerchantBuilder();
mb->createNewMerchant();
mb->fillMerchantStach();
Merchant* merchant = mb->getMerchant();
wMerchantInventory = createWindowMerchant();
updateMerchantInventory(mb->getMerchant());
wInventory = createWindowInventory();
updateInventory();
wHelp = createWindowHelp();
updateMerchantPaneHelp();
// print character panel tip
updateConsole("Tip: Press ESC to close merchant window.");
bool quit = FALSE;
int c;
int index;
stringstream msg;
Item* temp;
while (!quit) {
switch (c = getch()) {
case 27:
quit = TRUE;
break;
case 'm':
updateConsole("Tip: Press 1 to 9 to view an item.");
c = getch();
index = static_cast<int>(c - '0') - 1;
if (index >= 0 && index <= 8) {
updateConsole("Tip: Press [B] to buy this item.");
if (wItem != NULL)
wkill(wItem);
wItem = createWindowItem();
updateItem(merchant->peek(index));
if ((c = getch()) == 'b') {
player->buy(merchant, index);
updateMerchantInventory(merchant);
} else {
updateConsole("Error: Trade cancelled.");
}
} else
updateConsole("Error: That item doesn't exists!");
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
index = static_cast<int>(c - '0');
temp = player->getInventoryItem(index);
if (temp != NULL) {
if (wItem == NULL) {
wItem = createWindowItem();
updateItem(temp);
}
switch (c = getch()) {
case 'd':
msg << "Permanently delete " << temp->getName() << "? (y/n) ";
updateConsole(msg.str().c_str());
msg.str("");
msg.clear();
if ((c = getch()) == 'y') {
msg << temp->getName() << " was permanently deleted from your inventory.";
updateConsole(msg.str().c_str(), TRUE);
player->deleteInventoryItem(index);
msg.str("");
msg.clear();
} else {
updateConsole("Error: Delete unsuccessful.");
}
break;
case 's':
msg << "Sell " << temp->getName() << " for " << temp->getCost() << " gold? (y/n) ";
updateConsole(msg.str().c_str());
msg.str("");
msg.clear();
if ((c = getch()) == 'y') {
player->sell(index);
} else {
updateConsole("Error: Delete unsuccessful.");
}
break;
case 'u':
if (temp->getItemType() == IS_POTION) {
player->usePotion(static_cast<Potion*>(temp));
player->deleteInventoryItem(index, TRUE, FALSE, "You have just consumed a potion.");
} else {
updateConsole("Error: That item has no use effect.");
}
break;
default:
break;
}
// kill item panel
if (wItem != NULL)
wkill(wItem);
wItem = NULL;
} else {
updateConsole("Error: That item does not exists!");
}
break;
default:
updateConsole("Error: Unrecognized command!");
break;
}
if (wItem != NULL)
wkill(wItem);
wItem = NULL;
}
// clean the console
updateConsole("");
// clean the windows
wkill(wMerchantInventory);
wkill(wInventory);
wkill(wHelp);
if (wItem != NULL)
wkill(wItem);
wMerchantInventory = NULL;
wInventory = NULL;
wHelp = NULL;
wItem = NULL;
}
void d20Game::interactWithChest() {
// on first interaction, check first if