-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
1322 lines (1053 loc) · 53.2 KB
/
script.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
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
var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;
// Define sound effects:
var challengeSound = new Audio('http://soundbible.com/mp3/Computer_Magic-Microsift-1901299923.mp3');
var hitSound = new Audio('http://soundbible.com/mp3/Jab-SoundBible.com-1806727891.mp3');
var newItemSound = new Audio('http://soundbible.com/mp3/Ting-Popup_Pixels-349896185.mp3');
var bonusSound = new Audio('http://soundbible.com/mp3/Music_Box-Big_Daddy-1389738694.mp3');
var deathSound = new Audio('http://soundbible.com/mp3/Grenade-SoundBible.com-1777900486.mp3');
var winner = new Audio('http://soundbible.com/mp3/Triangle Dinner Bell-SoundBible.com-220988408.mp3');
// Define colors:
var dark = 'rgb(30,30,30)';
var empty = 'rgba(20,20,20,0.20)';
var user = '#ffc952';
var blue = '#5677FF';
var itemBonus = '#FFCF5F';
var gray = 'rgb(180,180,180)';
var mint = '#67D5B5';
var gold = '#ffc952';
var brightBlue = '#00dffc';
var pink = '#ff7473';
var barrierColor = '#FFD740';
var headerBackground = '#19281E';
var alarm = '#F8002C';
var red = '#FF0000';
// Define Skill Items:
var skills = {
'Bootstrap': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/bootstarp_zpss8vblcyf.png', 'You mastered responsive web design with Bootstrap!'],
'Bower': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/bower_zpsiryvttjz.png', 'Your workflow skills improve with Bower!'],
'CamperBot': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/camper-bot_zpss0vmcylr.png', 'You completed a 100 day streak at freeCodeCamp! CamperBot joined your team!'],
'Codepen': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/codepen_zps7q5rhj96.png', 'Your project made the front page of Codepen! Respect!'],
'CSS3': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/css3_zpsfgjif0yl.png', 'You gained valuable style skills, you can now vertically center text!'],
'D3': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/d3_zpsqry6neks.png', 'You mastered D3 and now can transform arbitrary data into beautiful charts!'],
'ES6': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/es6_zpstofeky6l.png', 'You learned ES6! Your attack improves with fat arrow function skills!'],
'Git': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/git_zpsbqpulcno.png', 'You mastered git, your workflow continues to improve!'],
'Github': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/github_zpsscwefh3e.png', 'You contributed to Open Source! Octocat joined your team!'],
'Gitter': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/gitter_zpsf4bixwzd.png', 'Campers gave you brownie points in Gitter Chat!'],
'Grunt': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/grunt_zpse8urargg.png', 'Your workflow is totally automated!'],
'Heroku': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/heroku_zpsvanhf1kx.png', 'You\'re deploying apps from Heroku!'],
'HTML5': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/HTML5_zpswgfqraaq.png', 'You\'ve become a master of HTML5!'],
'jQuery': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/jQuery_zpshgckvwqv.png', 'You mastered jQuery! DOM selection is a piece of cake for you!'],
'Javascript': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/javascript_zpspq5wlpgf.png', 'You learned about hoisting and callbacks in Javascript!'],
'MongoDB': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/mongoDB_zpsw9fkl7t9.png', 'You became a database champ with MongoDB!'],
'NodeJS': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/node_zpsjqltyxfy.png', 'You started coding Javascript on the back end! You gained isomorphic attack power!'],
'React': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/react_zpsu5wxjan7.png', 'You gained powerful Virtual DOM abilities! JSX has been added to your weapons list!'],
'Redux': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/redux_zpsbdb7qgwg.png', 'You obtained Redux Superpowers! All of your items are now immutable!'],
'Sass': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/sass_zpswfmipglk.png', 'Your CSS has become Sassy!'],
'StackOverflow': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/stack-overflow_zpsgukj4ov4.png', 'You can finally vote on StackOverflow answers!'],
'Sublime': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/sublime_zps76mjstkv.png', 'Your code editing skills are leveled up with Sublime Text!'],
'Terminal': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/terminal_zpshcdn2axm.png', 'You\'ve become a master of the command line!'],
'Twitter': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/twitter_zpslsshz5z7.png', 'Developers are following you on Twitter!'],
'Webpack': ['http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/webpack_zpsevn2xywn.png', 'Your build skills are unmatched with Webpack! Gained Hot Reload as a Summon!'] };
// Define Challenges:
var challenges = {
'front-end-1': [150, 'You built a tribute page, congratulations!'],
'front-end-2': [250, 'You completed the Wikipedia Viewer project!'],
'front-end-3': [350, 'You finished the Pomodoro Clock! Your productivity rises by 3000 points!'],
'front-end-4': [450, 'You built a Tic Tac Toe Game! And wrote an unbeatable algorithm! Great work!'],
'front-end-5': [550, 'You built a Simon Game! Your skills are really looking good!'],
'data-viz-1': [550, 'You built a Markdown Previewer using React and Sass, impressive!'],
'data-viz-2': [700, 'You built a Recipe Box App! Your friends are getting jealous!'],
'data-viz-3': [850, 'You created stunning bar graphs, scatterplots, heatmaps, and force directed layouts with D3!'],
'data-viz-4': [900, 'You completed a Javascript version of Conway\'s Game of Life, mesmerizing!'],
'data-viz-5': [1050, 'You built a Roguelike Dungeon Crawler! Unbelievable!!!'],
'back-end-1': [1200, 'You created a File Metadata Microservice! Your friends are really jealous now!'],
'back-end-2': [1400, 'You created a Voting App, awesome!'],
'back-end-3': [1650, 'You built a Nightlife Coordination App! Party on!'],
'back-end-4': [1800, 'You created a Book Trading Club App! Your parents\' friends thank you!'],
'back-end-5': [2000, 'You built a Pinterest Clone! Bring on the Non-Profit Projects!'] };
// Define boss HP:
var bossHP = 1000000;
// Image URLs for certification img tags:
var certificationsList = {
'Front': 'http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/frontend-cert_zpsq7qjoxm8.png',
'Viz': 'http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/dataviz-cert_zpshjjcrndr.png',
'Back': 'http://i1361.photobucket.com/albums/r662/bonham000/Roguelike/backend-cert_zpsnmwzk83w.png' };
// Root Component:
class App extends React.Component {
constructor() {
super();
this.state = {
sound: true,
about: true,
replay: false,
playing: true,
game: 'alive',
userLocation: '',
offset: 130,
map: [],
renderMap: [],
frontEndChallenges: [],
dataVizChallenges: [],
backEndChallenges: [],
skillItems: [],
life: 5000,
attackPower: 50,
experience: 0,
certifications: [],
level: 1,
header: 'Welcome to the freeCodeCamp Dungeon Crawler Game' };
this.startGame = this.startGame.bind(this);
this.resetGame = this.resetGame.bind(this);
this.generateMap = this.generateMap.bind(this);
this.updateMap = this.updateMap.bind(this);
this.handleKeyPress = this.handleKeyPress.bind(this);
this.handleBattle = this.handleBattle.bind(this);
this.handleDeath = this.handleDeath.bind(this);
this.handleSound = this.handleSound.bind(this);
}
// Allow the user to mute the sound:
handleSound() {
if (this.state.sound) {
this.setState({
sound: false });
} else
{
this.setState({
sound: true });
};
}
startGame() {
if (this.state.sound) {bonusSound.play();}
this.setState({
about: false });
}
resetGame() {
// location.reload();
document.getElementById('headerBar').style.background = headerBackground;
this.setState({
about: false,
replay: false,
playing: true,
game: 'alive',
userLocation: '',
offset: 130,
frontEndChallenges: [],
dataVizChallenges: [],
backEndChallenges: [],
skillItems: [],
life: 5000,
attackPower: 50,
experience: 0,
certifications: [],
level: 1,
header: 'Welcome to the freeCodeCamp Dungeon Crawler Game' });
this.generateMap();
challenges['front-end-1'][0] = 150;
challenges['front-end-2'][0] = 250;
challenges['front-end-3'][0] = 350;
challenges['front-end-4'][0] = 450;
challenges['front-end-5'][0] = 550;
challenges['data-viz-1'][0] = 550;
challenges['data-viz-2'][0] = 700;
challenges['data-viz-3'][0] = 850;
challenges['data-viz-4'][0] = 900;
challenges['data-viz-5'][0] = 105;
challenges['back-end-1'][0] = 1200;
challenges['back-end-2'][0] = 1400;
challenges['back-end-3'][0] = 1650;
challenges['back-end-4'][0] = 1800;
challenges['back-end-5'][0] = 2000;
}
// Function to generate map data on initial render of page:
generateMap() {
var w = 1000;
var h = 5000;
var gridWidth = 50;
var gridHeight = gridWidth;
var numRows = h / gridWidth;
var arr = [];
var userIndex;
var initMap = [];
// Render an array of 2000 items based on specified dimensions:
for (var a = 0; a < w / gridWidth * numRows; a++) {
// Generate a random number to determine if cells will be filled or not
var rand = Math.round(Math.random() * 5);
// 1 represents solid cells; 0 represents empty cells — random number is not 1, make it 0:
if (rand !== 1) {rand = 0;}
var user = 0;
// Boss and User positions are hard-coded; all other cells are distributed randomly:
// Set boss position at top of map:
if (a === 47 || a === 48 || a === 49 || a === 50 || a === 67 || a === 70 || a === 87 || a === 90 || a === 107 || a === 108 || a === 109 || a === 110) {rand = 'barrier';} else
if (a === 68 || a === 69 || a === 88 || a === 89) {rand = 'boss';}
// Set user position:
else if (a === 1890) {rand = 0;user = 1;userIndex = a;}
arr[a] = {
cellSize: gridWidth,
cellType: rand,
user: user };
}
// Randomly place challenges on map:
var rand;
var challengeLimit = 15;
var b = 0;
while (b < challengeLimit) {
rand = 100 + 1800 - Math.round(Math.random() * 1800);
// Do not place a challenge on the user:
if (rand !== 1890) {
// Only use empty cells:
if (arr[rand].cellType === 0) {
// Avoid 'boss' and 'barrier' cells:
if (typeof arr[rand - 1].cellType !== 'string' && typeof arr[rand + 1].cellType !== 'string' && typeof arr[rand - 20].cellType !== 'string' && typeof arr[rand + 20].cellType !== 'string') {
// Avoid inaccessible cells:
if (arr[rand - 1].cellType === 0 && arr[rand + 1].cellType === 0 && arr[rand - 20].cellType === 0 && arr[rand + 20].cellType === 0) {
// Fifteen challenges are distributed, 5 for each certification:
if (b < 5) {
arr[rand].cellType = "front";
b++;
} else
if (b < 10) {
arr[rand].cellType = "viz";
b++;
} else
{
arr[rand].cellType = "back";
b++;
}
}
}
}
}
// If the above conditions are not satisfied for the given random number, return and try again:
else {
continue;
}
}
// Randomly place skills on map:
// Get the names of all the skill items from the skills object:
var skillsArray = [];
for (var key in skills) {
skillsArray.push(key);
}
var c = 0;
while (c < skillsArray.length) {
rand = 100 + 1800 - Math.round(Math.random() * 1800);
// Do not place a challenge on the user:
if (rand !== 1890) {
// Cell must be empty and not contain a challenge
if (arr[rand].cellType === 0 && typeof arr[rand].cellType !== 'string') {
// Avoid 'boss' and 'barrier' cells:
if (typeof arr[rand - 1].cellType !== 'string' && typeof arr[rand + 1].cellType !== 'string' && typeof arr[rand - 20].cellType !== 'string' && typeof arr[rand + 20].cellType !== 'string') {
// Avoid inaccessible cells:
if (arr[rand - 1].cellType === 0 && arr[rand + 1].cellType === 0 && arr[rand - 20].cellType === 0 && arr[rand + 20].cellType === 0) {
arr[rand].cellType = skillsArray[c];
c++;
}
}
}
}
// If the above conditiosn are not satisfied for the given random number, return and try again:
else {
continue;
}
}
// A slice of the map data is made for the viewing window:
initMap = arr.slice(userIndex - 130, arr.length);
this.setState({
userLocation: userIndex,
map: arr,
renderMap: initMap });
}
// Take in new map data and user location to render a new map to the page upon user movement:
updateMap(data, newLocation, offset) {
var gameMap = this.state.map;
var newMap = gameMap.slice(newLocation - offset, newLocation + (240 - offset));
this.setState({
userLocation: newLocation,
offset: offset,
renderMap: newMap });
}
// If player is defeated, alert Gameover and display the replay screen:
handleDeath() {
console.log('Player died!');
if (this.state.sound) {deathSound.play();}
this.setState({
playing: false,
header: 'You were defeated! Don\'t forget to level up your skills before trying the advanced challenges!' });
document.getElementById('headerBar').style.backgroundColor = red;
setTimeout(function () {
this.setState({
replay: true });
}.bind(this), 3000);
}
// Take battle parameters and render outcome of any battle:
handleBattle(challengeID, damage, userHP, attack) {
if (this.state.sound) {hitSound.play();}
var level = this.state.level;
var experience = this.state.experience;
var attackLevel = this.state.attackPower;
var challenge;
var challengeHP;
// Code to keep track of which challenge the user is attempting to persist damage on that challenge if user leaves without defeating it:
// Values are based on the challenge global object:
if (challengeID === 0) {challenge = 'front-end-1';challengeHP = challenges['front-end-1'][0];} else
if (challengeID === 1) {challenge = 'front-end-2';challengeHP = challenges['front-end-2'][0];} else
if (challengeID === 2) {challenge = 'front-end-3';challengeHP = challenges['front-end-3'][0];} else
if (challengeID === 3) {challenge = 'front-end-4';challengeHP = challenges['front-end-4'][0];} else
if (challengeID === 4) {challenge = 'front-end-5';challengeHP = challenges['front-end-5'][0];} else
if (challengeID === 10) {challenge = 'data-viz-1';challengeHP = challenges['data-viz-1'][0];} else
if (challengeID === 11) {challenge = 'data-viz-2';challengeHP = challenges['data-viz-2'][0];} else
if (challengeID === 12) {challenge = 'data-viz-3';challengeHP = challenges['data-viz-3'][0];} else
if (challengeID === 13) {challenge = 'data-viz-4';challengeHP = challenges['data-viz-4'][0];} else
if (challengeID === 14) {challenge = 'data-viz-5';challengeHP = challenges['data-viz-5'][0];} else
if (challengeID === 100) {challenge = 'back-end-1';challengeHP = challenges['back-end-1'][0];} else
if (challengeID === 101) {challenge = 'back-end-2';challengeHP = challenges['back-end-2'][0];} else
if (challengeID === 102) {challenge = 'back-end-3';challengeHP = challenges['back-end-3'][0];} else
if (challengeID === 103) {challenge = 'back-end-4';challengeHP = challenges['back-end-4'][0];} else
if (challengeID === 104) {challenge = 'back-end-5';challengeHP = challenges['back-end-5'][0];} else
if (challengeID === 'boss') {challenge = 'boss';}
// Compute damage and HP based on challenge parameters:
var challengeNewHP = challengeHP - attack;
var health = userHP - damage;
if (challengeID !== 'boss') {
challenges[challenge][0] = challengeNewHP;
} else
if (challengeID === 'boss') {
bossHP = bossHP - attack;
challengeNewHP = bossHP;
}
this.setState({
life: health });
// Computer outcome if user is either killed first or defeats the challenge first:
if (health > 0 && challengeNewHP <= 0) {
if (challengeID !== 'boss') {
this.setState({
level: level + 1,
life: health + 250,
attackPower: attackLevel + 50,
experience: +experience + Math.round(Math.random() * 11750),
header: challenges[challenge][1] });
}
if (challenge !== 'front-end-5' && challenge !== 'data-viz-5' && challenge !== 'back-end-5' && challenge !== 'boss') {
if (this.state.sound) {challengeSound.play();}
}
// Account for the different certifications to trigger state changes when the player completes all the challenges for a given certification:
var certs = this.state.certifications.slice();
if (challenge === 'front-end-5') {
certs[certs.length] = certificationsList['Front'];
setTimeout(function () {
if (this.state.sound) {bonusSound.play();}
this.setState({
life: health + 5000,
attackPower: attackLevel + 500,
experience: +experience + 2500,
header: 'You earned the Front End Development Certification!',
certifications: certs });
}.bind(this), 250);
} else
if (challenge === 'data-viz-5') {
certs[certs.length] = certificationsList['Viz'];
setTimeout(function () {
if (this.state.sound) {bonusSound.play();}
this.setState({
life: health + 10000,
attackPower: attackLevel + 500,
experience: +experience + 2500,
header: 'You earned the Data Visualization Certification!',
certifications: certs });
}.bind(this), 250);
} else
if (challenge === 'back-end-5') {
certs[certs.length] = certificationsList['Back'];
setTimeout(function () {
if (this.state.sound) {bonusSound.play();}
this.setState({
life: health + 15000,
attackPower: attackLevel + 500,
experience: +experience + 2500,
header: 'You earned the Back End Development Certification!',
certifications: certs });
}.bind(this), 250);
} else
if (challenge === 'boss') {
if (this.state.sound) {winner.play();}
// Remove the boss from the map and re-render:
var finalMap = this.state.map.slice();
finalMap[68].cellType = 0;
finalMap[69].cellType = 0;
finalMap[88].cellType = 0;
finalMap[89].cellType = 0;
this.setState({
header: 'You defeated the boss and earned the Full Stack Javascript Certification! Way to go!!!',
map: finalMap });
// Winning animatin:
document.getElementById('headerBar').style.backgroundColor = brightBlue;
document.getElementById('headerTitle').style.color = dark;
return true;
}
// When user completes all three certifications, remove the barrier around the boss and re-render the map:
if (certs.length === 3) {
setTimeout(function () {
var currentGameMap = this.state.map.slice();
currentGameMap[47].cellType = 0;
currentGameMap[48].cellType = 0;
currentGameMap[49].cellType = 0;
currentGameMap[50].cellType = 0;
currentGameMap[67].cellType = 0;
currentGameMap[70].cellType = 0;
currentGameMap[87].cellType = 0;
currentGameMap[90].cellType = 0;
currentGameMap[107].cellType = 0;
currentGameMap[108].cellType = 0;
currentGameMap[109].cellType = 0;
currentGameMap[110].cellType = 0;
var attackLevel = this.state.attackPower;
var exp = this.state.experience;
var lifeHP = this.state.life;
var level = this.state.level;
this.setState({
attackPower: attackLevel + 145000,
experience: exp + 1000000,
life: lifeHP + 500000,
level: level + 250,
map: currentGameMap,
header: 'You\'ve acquired all the certifications, remarkable! The final boss is now unlocked!' });
if (this.state.sound) {bonusSound.play();}
}.bind(this), 2500);
}
return true;
} else
if (health <= 0) {
this.handleDeath();
return false;
}
}
// Function to handle user movement based on arrow key input:
handleKeyPress(event) {
// Check target location to see if there is an item there, if so, handle the challenge:
var checkLocationForItem = function (locationObj) {
var a = [];
for (var key in skills) {
a.push(key);
}
// Add attack and exp points if user picks up an item based on current attack and exp points:
var raiseAttack = function () {
var currentAttack = this.state.attackPower;
var newAttack;
var currentHP = this.state.life;
var newHP;
if (currentAttack < 100) {newAttack = currentAttack + 15;newHP = currentHP + (150 - Math.round(Math.random() * 50));} else
if (currentAttack < 250) {newAttack = currentAttack + 25;newHP = currentHP + (300 - Math.round(Math.random() * 150));} else
if (currentAttack < 500) {newAttack = currentAttack + 75;newHP = currentHP + (500 - Math.round(Math.random() * 200));} else
if (currentAttack < 1000) {newAttack = currentAttack + 125;newHP = currentHP + (600 - Math.round(Math.random() * 500));} else
if (currentAttack >= 1000) {newAttack = currentAttack + 150;newHP = currentHP + (800 - Math.round(Math.random() * 600));}
var experience = this.state.experience;
var newExp = +experience + (5000 - Math.round(Math.random() * 2500));
this.setState({
attackPower: newAttack,
experience: newExp,
life: newHP });
}.bind(this);
for (var i = 0; i < a.length; i++) {
if (a[i] === locationObj.cellType) {
raiseAttack();
if (this.state.skillItems.length <= 23) {
if (this.state.sound) {newItemSound.play();}
}
return true;}
}
return false;
}.bind(this);
// Check target location to see if there is a challenge there, if so, handle the challenge:
function checkLocationForChallenge(locationObj) {
var cell = locationObj.cellType;
if (cell === 'front' || cell === 'viz' || cell === 'back') {
return true;
} else
if (cell === 'boss') {
return true;
} else
return false;
}
// Calculate parameters for battle function if player encounters a challenge:
var attemptChallenge = function (locationObj, newLocation) {
var challenge = locationObj.cellType;
var attack = this.state.attackPower;
var userHealth = this.state.life;
var damage, challengeHP, challengeID;
if (challenge === 'front') {
var currentChallenges = this.state.frontEndChallenges.slice();
var check = 0;
for (var a = 0; a < currentChallenges.length; a++) {
if (currentChallenges[a] === newLocation) {
challengeID = a * 1;
check = 1;
break;
} else
{
check = 0;
}
}
if (check === 0) {
currentChallenges[currentChallenges.length] = newLocation;
challengeID = (currentChallenges.length - 1) * 1;
}
this.setState({
frontEndChallenges: currentChallenges });
damage = 600 - Math.round(Math.random() * 200); // Damage for front end challenge
if (this.handleBattle(challengeID, damage, userHealth, attack)) {
return true;
}
} else
if (challenge === 'viz') {
var currentChallenges = this.state.dataVizChallenges.slice();
var check = 0;
for (var a = 0; a < currentChallenges.length; a++) {
if (currentChallenges[a] === newLocation) {
challengeID = a + 10;
check = 1;
break;
} else
{
check = 0;
}
}
if (check === 0) {
currentChallenges[currentChallenges.length] = newLocation;
challengeID = currentChallenges.length - 1 + 10;
}
this.setState({
dataVizChallenges: currentChallenges });
damage = 2500 - Math.round(Math.random() * 1000); // Damage for data viz challenge
if (this.handleBattle(challengeID, damage, userHealth, attack)) {
return true;
}
} else
if (challenge === 'back') {
var currentChallenges = this.state.backEndChallenges.slice();
var check = 0;
for (var a = 0; a < currentChallenges.length; a++) {
if (currentChallenges[a] === newLocation) {
challengeID = a + 100;
check = 1;
break;
} else
{
check = 0;
}
}
if (check === 0) {
currentChallenges[currentChallenges.length] = newLocation;
challengeID = currentChallenges.length - 1 + 100;
}
this.setState({
backEndChallenges: currentChallenges });
damage = 7500 - Math.round(Math.random() * 3000); // Damage for back end challenge
if (this.handleBattle(challengeID, damage, userHealth, attack)) {
return true;
}
} else
if (challenge === 'boss') {
challengeID = 'boss';
damage = 100000 - Math.round(Math.random() * 50000); // Damage for boss
if (this.handleBattle(challengeID, damage, userHealth, attack)) {
console.log('The player wins!');
}
}
}.bind(this);
var currentMap = this.state.map.slice();
var offset = this.state.offset;
var userLocation = this.state.userLocation;
var arrow;
if (event === 37) {arrow = 37;} else
if (event === 38) {arrow = 38;} else
if (event === 39) {arrow = 39;} else
if (event === 40) {arrow = 40;} else
{arrow = event.keyCode;event.preventDefault();}
// Functions to handle movement; there are four functions which are basically identical:
// Move Left:
if (arrow === 37) {
// Prevent arrow key from scrolling the page:
// If player dies, prevent further movement:
if (this.state.playing) {
var newLocation = userLocation - 1;
// Calculate new location for player if the cell is empty:
if (currentMap[newLocation].cellType === 0) {
currentMap[userLocation].user = 0;
currentMap[newLocation].user = 1;
offset = offset - 1;
this.updateMap(currentMap, newLocation, offset);
}
// If the cells is not empty, check is there is an item there, if there is, acquire the item and add it to the items array; then update the map:
else if (checkLocationForItem(currentMap[newLocation])) {
var currentSkills = this.state.skillItems.slice();
currentSkills[currentSkills.length] = skills[currentMap[newLocation].cellType][0];
this.setState({
header: skills[currentMap[newLocation].cellType][1],
skillItems: currentSkills });
if (this.state.skillItems.length === 25) {
setTimeout(function () {
var attackLevel = this.state.attackPower;
var exp = this.state.experience;
var lifeHP = this.state.life;
var level = this.state.level;
if (this.state.sound) {bonusSound.play();}
this.setState({
header: 'You\'ve mastered all the skills! Your coding abilities are now overpowered!',
attackPower: attackLevel + 2500,
experience: exp + 15000,
life: lifeHP + 15000,
level: level + 50 });
}.bind(this), 250);
};
currentMap[userLocation].user = 0;
currentMap[newLocation].user = 1;
currentMap[newLocation].cellType = 0;
offset = offset - 1;
this.updateMap(currentMap, newLocation, offset);
}
// If it is not an item, there should be a challenge; handle the challenge:
else if (checkLocationForChallenge(currentMap[newLocation])) {
if (attemptChallenge(currentMap[newLocation], newLocation)) {
currentMap[userLocation].user = 0;
currentMap[newLocation].user = 1;
currentMap[newLocation].cellType = 0;
offset = offset - 1;
this.updateMap(currentMap, newLocation, offset);
}
}
}
}
// Move Up:
else if (arrow === 38) {
if (this.state.playing) {
var newLocation = userLocation - 20;
if (newLocation >= 0) {
if (currentMap[newLocation].cellType === 0) {
if (offset > 120) {
offset = offset - 20;
} else
if (newLocation <= 130) {
offset = newLocation;
}
currentMap[userLocation].user = 0;
currentMap[newLocation].user = 1;
this.updateMap(currentMap, newLocation, offset);
} else
if (checkLocationForItem(currentMap[newLocation])) {
var currentSkills = this.state.skillItems.slice();
currentSkills[currentSkills.length] = skills[currentMap[newLocation].cellType][0];
this.setState({
header: skills[currentMap[newLocation].cellType][1],
skillItems: currentSkills });
if (this.state.skillItems.length === 25) {
setTimeout(function () {
var attackLevel = this.state.attackPower;
var exp = this.state.experience;
var lifeHP = this.state.life;
var level = this.state.level;
if (this.state.sound) {bonusSound.play();}
this.setState({
header: 'You\'ve mastered all the skills! Your coding abilities are now overpowered!',
attackPower: attackLevel + 50000,
experience: exp + 15000,
life: lifeHP + 100000,
level: level + 50 });
}.bind(this), 250);
};
if (offset > 120) {
offset = offset - 20;
} else
if (newLocation <= 130) {
offset = newLocation;
}
currentMap[userLocation].user = 0;
currentMap[newLocation].user = 1;
currentMap[newLocation].cellType = 0;
this.updateMap(currentMap, newLocation, offset);
} else
if (checkLocationForChallenge(currentMap[newLocation])) {
if (attemptChallenge(currentMap[newLocation], newLocation)) {
currentMap[userLocation].user = 0;
currentMap[newLocation].user = 1;
currentMap[newLocation].cellType = 0;
this.updateMap(currentMap, newLocation, offset);
}
}
}
}
}
// Move Right
else if (arrow === 39) {
if (this.state.playing) {
var newLocation = userLocation + 1;
if (currentMap[newLocation].cellType === 0) {
currentMap[userLocation].user = 0;
currentMap[newLocation].user = 1;
currentMap[newLocation].cellType = 0;
offset = offset + 1;
this.updateMap(currentMap, newLocation, offset);
} else
if (checkLocationForItem(currentMap[newLocation])) {
var currentSkills = this.state.skillItems.slice();
currentSkills[currentSkills.length] = skills[currentMap[newLocation].cellType][0];
this.setState({
header: skills[currentMap[newLocation].cellType][1],
skillItems: currentSkills });
if (this.state.skillItems.length === 25) {
setTimeout(function () {
var attackLevel = this.state.attackPower;
var exp = this.state.experience;
var lifeHP = this.state.life;
var level = this.state.level;
if (this.state.sound) {bonusSound.play();}
this.setState({
header: 'You\'ve mastered all the skills! Your coding abilities are now overpowered!',
attackPower: attackLevel + 50000,
experience: exp + 15000,
life: lifeHP + 100000,
level: level + 50 });
}.bind(this), 250);
};
currentMap[userLocation].user = 0;
currentMap[newLocation].user = 1;
currentMap[newLocation].cellType = 0;
offset = offset + 1;
this.updateMap(currentMap, newLocation, offset);
} else
if (checkLocationForChallenge(currentMap[newLocation])) {
if (attemptChallenge(currentMap[newLocation], newLocation)) {
currentMap[userLocation].user = 0;
currentMap[newLocation].user = 1;
currentMap[newLocation].cellType = 0;
offset = offset + 1;
this.updateMap(currentMap, newLocation, offset);
}
}
}
}
// Move Down:
else if (arrow === 40) {
if (this.state.playing) {
var newLocation = userLocation + 20;
if (newLocation <= 2000) {
if (currentMap[newLocation].cellType === 0) {
if (offset < 120) {
offset = offset + 20;
} else
if (newLocation >= 1870) {
offset = 240 - (2000 - newLocation);
}
currentMap[userLocation].user = 0;
currentMap[newLocation].user = 1;
currentMap[newLocation].cellType = 0;
this.updateMap(currentMap, newLocation, offset);
} else
if (checkLocationForItem(currentMap[newLocation])) {
var currentSkills = this.state.skillItems.slice();
currentSkills[currentSkills.length] = skills[currentMap[newLocation].cellType][0];
this.setState({
header: skills[currentMap[newLocation].cellType][1],
skillItems: currentSkills });
if (this.state.skillItems.length === 25) {
setTimeout(function () {
var attackLevel = this.state.attackPower;
var exp = this.state.experience;
var lifeHP = this.state.life;
var level = this.state.level;
if (this.state.sound) {bonusSound.play();}
this.setState({
header: 'You\'ve mastered all the skills! Your coding abilities are now overpowered!',
attackPower: attackLevel + 50000,
experience: exp + 15000,
life: lifeHP + 100000,
level: level + 50 });
}.bind(this), 250);
};
if (offset < 120) {
offset = offset + 20;
} else
if (newLocation >= 1870) {
offset = 240 - (2000 - newLocation);
}
currentMap[userLocation].user = 0;
currentMap[newLocation].user = 1;
currentMap[newLocation].cellType = 0;
this.updateMap(currentMap, newLocation, offset);
} else
if (checkLocationForChallenge(currentMap[newLocation])) {
if (attemptChallenge(currentMap[newLocation], newLocation)) {
currentMap[userLocation].user = 0;
currentMap[newLocation].user = 1;
currentMap[newLocation].cellType = 0;
this.updateMap(currentMap, newLocation, offset);
}
}
}
}
}
}
// Generate the map data on component initial render:
componentWillMount() {
this.generateMap();
}
// Add event listeners to detect user movement:
componentDidMount() {
window.addEventListener('keydown', this.handleKeyPress);
}
// Main render function of root component:
render() {
return /*#__PURE__*/(
React.createElement("div", { className: "pageWrapper" }, /*#__PURE__*/
React.createElement(About, {
about: this.state.about,