-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.js
920 lines (901 loc) · 24.7 KB
/
game.js
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
var gd = {
name: "Tank",
hearts: 5,
matches: 5,
lantern: false,
gems: 0,
rescuee: "Helga",
enemies: ["Grublor", "Stolak"],
forestKey: false,
forestBossKey: false,
silverSword: true,
leatherShield: false,
heartPotion: false,
bosses: [{name: "King Malvox", hearts: 7}],
_currentScreen: 0,
_previousScreen: 0,
_currentBoss: "",
_currentShield: 0,
_heartLimit: 5,
_gameOverWin: 43,
_gameOverLose: 42,
_quitScreen: 44,
_inventoryScreen: 40,
_creditsScreen: 41,
_invalidAnswer: 45,
inventory: {
sword: {
title: "Sword",
name: "---"
},
shield: {
title: "Shield",
name: "---"
},
light: {
title: "Light",
name: "---"
},
key: {
title: "key",
name: "---"
}
},
credits: "Created by RA Sims II",
screens: [{
id: 1,
title: "The Legend of Helga",
text: "Click OK to begin.",
a: "",
b: "",
c: "",
d: "",
e: "",
hideStats: true,
action: function(ge, gd, answer){
var matches = "Matches (" + ge.getItem("matches") + ")";
ge.setInventory('light', 'Light', matches);
return {goto: 2};
}
}, {
id: 2,
title:"Before we get started...",
text: "Adventurer, what is your name?",
a: "",
b: "",
c: "",
d: "",
e: "",
hideStats: true,
usePrompt: true,
action: function (ge, gd, answer){
var act = {};
if (ge.hasText(answer, "ABC123")) {
act.goto = 4;
ge.setItem('name', answer);
}
else {
act.goto = 3;
}
return act;
}
}, {
id: 3,
title:"That's not a name!",
text: "It's not that hard, just type your name.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {goto: 2};
}
}, {
id: 4,
title:"{{RESCUEE}} has been kidknapped!",
text: "The local village blacksmith said that he saw her taken into the forest by a shadowy figure. " +
"He gave you a Silver Sword to help you in your quest. You'd better hurry into the forest and save her. ",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {goto: 5};
}
}, {
id: 5,
title:"{{RESCUEE}} is not going to save herself.",
text: "where will you start?",
a: "Venture into the Dark Forest",
b: "Vist the Dark Forest Temple",
c: "QUIT",
d: "",
e: "",
usePrompt: true,
action: function (ge, gd, answer){
var act = {};
switch(answer){
case "A":
act.goto = 7;
break;
case "B":
act.goto = 6;
break;
case "STUFF":
case "INVENTORY":
act.goto = ge.getItem("_inventoryScreen");
break;
case "C":
case "QUIT":
act.goto = ge.getItem("_quitScreen");
break;
default:
act.goto = ge.getItem("_invalidAnswer");
}
return act;
}
}, {
id: 6,
title: "You need a key to get in the Dark Forest Temple.",
text: "Maybe you should look for one in the forest.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {goto: 5};
}
}, {
id: 7,
title:"The forest is dark.",
text: "you will need a lantern to find anything, what will you do?",
a: "Look for a lantern",
b: "Look for the temple key",
c: "Go to the Forest Temple",
d: "QUIT",
e: "",
usePrompt: true,
action: function (ge, gd, answer){
var act = {};
var lantern = ge.getItem('lantern');
var roll = ge.rollDice();
var matches = ge.getItem('matches');
var forestKey = ge.getItem('forestKey');
if (!lantern) {
//ge.adjustItem('matches', -1);
act.matches = -1;
}
if (!matches && !lantern) {
act.goto = 11;
return act;
}
switch(answer){
case "A":
if(lantern) {
act.goto = 10;
return act;
}
if (roll > 6) {
act.goto = 8;
}
else {
if(matches) {
act.goto = 9;
}
}
break;
case "B":
if (forestKey) {
act.goto = 17;
return act;
}
if (roll > 6) {
act.goto = 12;
}
else {
act.goto = 13;
}
break;
case "C":
if (forestKey) {
ge.setInventory("key", "", "---");
act.goto = 18;
}
else {
act.goto = 16;
}
break;
case "STUFF":
case "INVENTORY":
act.goto = ge.getItem("_inventoryScreen");
break;
case "D":
case "QUIT":
act.goto = ge.getItem("_quitScreen");
break;
default:
act.goto = ge.getItem("_invalidAnswer");
}
return act;
}
}, {
id: 8,
title:"You found a lantern!",
text: "Now you don't have to keep burning your fingers with those pesky matches.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
ge.setItem('lantern', true);
ge.setInventory("light", "", "Eternal Lantern");
gd.screens[6].title = "Keep your sword ready {{NAME}}.";
gd.screens[6].text = "The light of the lantern has show the true danger ahead. What will you do?";
return {goto: 7};
}
}, {
id: 9,
title:"Drats, you didn't find a lantern yet.",
text: "You'd better hurry you only have {{MATCHES}} matches left!",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
var act = {};
var matches = ge.getItem('matches');
if (matches) {
act.goto = 7;
}
else {
act.goto = 11;
}
return act;
}
}, {
id: 10,
title:"You can't find something you already have.",
text: "look for the key already!",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {goto: 7};
}
}, {
id: 11,
title: "As your last match burned to cinder, you saw your hope fade to blackness.",
text: "You are lost forever in darkness. -GAME OVER.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
var gameover = ge.getItem("_gameOverLose");
return {goto: gameover};
}
}, {
id: 12,
title: "Hooray!",
text: "You found the Forest Temple key.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
ge.setItem('forestKey', true);
ge.setInventory("key", "", "Forest Temple Key");
return {goto: 7};
}
}, {
id: 13,
title: "An {{ENEMY}} has appear.",
text: "Prepare for battle, I hope your sword is sharp.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
var act = {};
var roll = ge.rollDice();
if (roll > 7) {
act.goto = 14;
}
else {
act.goto = 15;
}
return act;
}
}, {
id: 14,
title: "Victory is yours {{NAME}}.",
text: "Your fought valiantly and earned 5 gems.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {
goto: 7,
gems: 5
};
}
}, {
id: 15,
title: "The agony of defeat!",
text: "Your managed to slay the beast but not before sustaining some damage.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {
goto: 7,
hearts: -1
};
}
}, {
id: 16,
title: "You need a key to enter the temple.",
text: "Maybe you should better equip yourself before you head there.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {goto: 7};
}
}, {
id: 17,
title: "{{NAME}} you are not going to find another key.",
text: "Is it time to head to the temple?",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {goto: 7};
}
}, {
id: 18,
title: "Forest Temple Entrance",
text: "Stay alert, this temple is very dangerous, {{NAME}} what will you do?",
a: "Visit the temple shop",
b: "Explore the temple",
c: "Enter Boss Room",
d: "Quit",
e: "",
action: function (ge, gd, answer){
if (!ge.getItem('_currentBoss')) {
var boss = ge.getBoss(1);
ge.setItem('_currentBoss', boss);
}
var bossKey = ge.getItem('forestBossKey');
var lantern = ge.getItem('lantern');
var act = {};
var roll = ge.rollDice();
switch(answer){
case "A":
act.goto = 19;
break;
case "B":
if (!lantern){
act.matches = -1;
}
if (roll === 1 || roll === 12) {
act.goto = 26;
}
if (roll === 9 || roll === 10 || roll === 11) {
act.goto = 27;
}
if (roll === 2 || roll === 3 || roll === 4 || roll === 5 || roll === 6 || roll === 7 || roll === 8) {
act.goto = 28;
}
break;
case "C":
if (bossKey) {
act.goto = 31;
}
else {
act.goto = 32;
}
break;
case "STUFF":
case "D":
case "QUIT":
act.goto = ge.getItem("_quitScreen");
break;
default:
act.goto = ge.getItem("_invalidAnswer");
}
return act;
}
}, {
id: 19,
title: "Hayloo, welcome to my shop.",
text: "I am Dreeko, What would yoooh like to buy?",
a: "A lantern - 20 gems",
b: "5 matches 10 gems",
c: "A leather shield - 25 gems",
d: "A heart potion - 15 gems",
e: "Exit the shop",
action: function (ge, gd, answer){
var lanternPrice = 20;
var shieldPrice = 25;
var potionPrice = 15;
var act = {};
var gems = ge.getItem('gems');
var lantern = ge.getItem('lantern');
var shield = ge.getItem('leatherShield');
var potion = ge.getItem('heartPotion');
switch(answer){
case "A":
if (lantern) {
act.goto = 20;
}
else {
if (ge.sellItem('lantern', lanternPrice)) {
act.goto = 21;
}
else {
act.goto = 22;
}
}
break;
case "B":
act.goto = 23;
break;
case "C":
if (shield) {
act.goto = 20;
}
else {
if (ge.sellItem('leatherShield', shieldPrice)) {
act.goto = 24;
}
else {
act.goto = 22;
}
}
break;
case "D":
if (potion) {
act.goto = 20;
}
else {
if (ge.sellItem('heartPotion', potionPrice)) {
act.goto = 25;
}
else {
act.goto = 22;
}
}
break;
case "E":
act.goto = 18;
break;
case "STUFF":
case "QUIT":
act.goto = ge.getItem("_quitScreen");
break;
default:
act.goto = ge.getItem("_invalidAnswer");
}
return act;
}
}, {
id: 20,
title: "Looks like you already have one of those.",
text: "As much as Dreeko would like to sell you another one, I just can't.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {goto: 19};
}
}, {
id: 21,
title: "{{NAME}} you are the owner of a shiny new lantern!",
text: "Dreeko thinks you could have saved money looking for one in the forest though...",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
ge.setInventory("light", "", "Eternal Lantern");
return {goto: 19};
}
}, {
id: 22,
title: "Dreeko really likes charity, but I have 9 kids to feed.",
text: "Maybe you should check the temple for treasure and come back later?",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {goto: 19};
}
}, {
id: 23,
title: "I'd really like to sell you something, but in this temple you really need a lantern.",
text: "Maybe there is somethign else you need?",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {goto: 19};
}
}, {
id: 24,
title: "Dreeko thinks you are smart.",
text: "The leather shield will cut your damage in half.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
ge.setItem('_currentShield', 1);
ge.setInventory("shield", "", "Leather Shield");
return {goto: 19};
}
}, {
id: 25,
title: "This potion is quite special.",
text: "If you fall in battle, it will revive you to full health.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
ge.setInventory("potion", "Heart Potion", "Fairy Syrup");
return {goto: 19};
}
}, {
id: 26,
title: "What luck!",
text: "You found a chest that contains 10 gems.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
ge.adjustItem('gems', 10);
return {goto: 18};
}
}, {
id: 27,
title: "You found the boss room.",
text: "Are you ready to do battle?",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
ge.setItem('forestBossKey', true);
ge.setInventory("key", "", "Forest Boss Key");
return {goto: 18};
}
}, {
id: 28,
title: "An {{ENEMY}} appeared, prepare for battle.",
text: "",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
var act = {};
var roll = ge.rollDice();
if (roll > 8) {
act.goto = 29;
}
else {
act.goto = 30;
}
return act;
}
}, {
id: 29,
title: "BEAST-MODE activated, you slayed the enemy!",
text: "You just earned 10 gems.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {
goto: 18,
gems: 10
};
}
}, {
id: 30,
title: "Temple monsters are stonger than those found in the forest.",
text: "You defeated your foe but were injured in the process.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {
goto: 18,
hearts: -2
};
}
}, {
id: 31,
title: "<<<{{BOSS}}>>> - Forest Temple Boss.",
text: "Strike fast or perish.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {goto: 33};
}
}, {
id: 32,
title: "You cannot enter this room.",
text: "You must explore the temple to find the boss room key to get in.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {goto: 18};
}
}, {
id: 33,
title: "{{BOSS}} is charging you.",
text: "What will you do?",
a: "Sword attack",
b: "Try special attack",
c: "Dodge",
d: "Quit",
e: "",
action: function (ge, gd, answer){
var act = {};
var roll1 = ge.rollDice();
var roll2 = ge.rollDice();
switch(answer){
case "A":
if (roll1 > 6) {
act.goto = 34;
}
else {
act.goto = 35;
}
break;
case "B":
if (roll1 === roll2 || (roll1 + roll2 === 14)) {
act.goto = 36;
}
else {
act.goto = 37;
}
break;
case "C":
act.goto = 38;
break;
case "STUFF":
case "D":
case "QUIT":
act.goto = ge.getItem("_quitScreen");
break;
default:
act.goto = ge.getItem("_invalidAnswer");
}
return act;
}
}, {
id: 34,
title: "Excellent attack {{NAME}}!",
text: "Keep this up and {{BOSS}} will be defeated soon.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
var act = {goto: 33};
var boss = ge.getItem("_currentBoss");
var bossHearts = ge.attack(boss, -1);
if (!bossHearts) {
act.goto = 39;
}
return act;
}
}, {
id: 35,
title: "{{BOSS}} is a skilled figher.",
text: "You have been injured, I'm not sure how much of this you can take.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {
goto: 33,
hearts: -2
};
}
}, {
id: 36,
title: "<< Five Strike Blazing Slash >> - Special Attack Unleashed!",
text: "You inflicted major damage to {{BOSS}}.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
var act = {goto: 33};
var boss = gd._currentBoss;
var bossHearts = ge.attack(boss, -3);
if (!bossHearts) {
act.goto = 39;
}
return act;
}
}, {
id: 37,
title: "Special attacks are not easy to pull off.",
text: "{{BOSS}} struck before you could power up.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {
goto: 33,
hearts: -2
};
}
}, {
id: 38,
title: "You can't run forever {{NAME}}.",
text: "The only way to free {{RESCUEE}} is to defeat {{BOSS}}.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {goto: 33};
}
}, {
id: 39,
title: "You defeated {{BOSS}}.",
text: "A hidden stone door crumbles and {{RESCUEE}} runs out and hugs you. Thank you for saving me {{NAME}} I do not know how to thank you! \n" +
"Congratulations what will your next quest be?",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
ge.setItem('_currentBoss', null);
ge.adjustItem('_heartLimit', 1);
ge.setItem('hearts', ge.getItem('_heartLimit'));
var gameover = ge.getItem("_gameOverWin");
return {goto: gameover};
}
}, {
id: 40,
title: "Inventory",
text: "{{INVENTORY}}",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
var screenNum = ge.getItem("_previousScreen");
return {goto: screenNum};
}
}, {
id: 41,
title: "Credits",
text: "{{CREDITS}}",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {goto: 9999};
}
}, {
id: 42,
title: "Game Over",
text: "What is that sad music playing? Try again?",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {
goto: 9999,
gameover: true
};
}
}, {
id: 43,
title: "Game Over",
text: "Congratulation! You saved Princess {{RESCUEE}}. {{NAME}}, perhaps now you might create your own quest?",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
return {
goto: 9999,
gameover: true
};
}
}, {
id: 44,
title: "Quitters never prosper.",
text: "What's the matter {{NAME}} couldn't take it?",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
ge.reset(gd);
return {
goto: 9999,
gameover: true
};
}
}, {
id: 45,
title: "Hey, that not a valid answer!",
text: "Please make a proper selection.",
a: "",
b: "",
c: "",
d: "",
e: "",
action: function (ge, gd, answer){
var screenNum = ge.getItem("_previousScreen");
return {goto: screenNum};
}
}]
};
ge.start(gd);