This repository was archived by the owner on Jan 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.js
More file actions
2485 lines (2485 loc) · 77 KB
/
build.js
File metadata and controls
2485 lines (2485 loc) · 77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
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
/// <reference path="../_references.ts" />
class Game {
constructor() {
this._selected = [];
this._colliding = [];
this._dead = [];
Game._player = new Player("Goat");
this._tileMap = new TileMap(30, 15);
this._entities = [
Game._player
];
this._tileMap.insertEntities(this._entities);
this._currentLevel = -1;
this._timeScores = [];
}
//Only adding one entity to colliding, TODO
checkCollisions(entity) {
// let tiles: Tile[] = this._tileMap.getEntityTiles(entity);
let tiles = this._tileMap.getTiles([entity.head]);
let colliding = [];
for (let tile of tiles) {
for (let otherEntity of tile.entities) {
if (!colliding.includes(otherEntity) && entity !== otherEntity) { //&& otherEntity.constructor.name !== "Ground") {
colliding.push(otherEntity);
otherEntity.playerCollision();
}
}
}
this._colliding = colliding;
}
get colliding() {
return this._colliding;
}
get entities() {
return this._entities;
}
set entities(entities) {
this._entities = entities;
}
get battle() {
return this._battle;
}
set battle(battle) {
this._battle = battle;
}
get dead() {
return this._dead;
}
set dead(dead) {
this._dead = dead;
}
get tileMap() {
return this._tileMap;
}
set tileMap(tileMap) {
this._tileMap = tileMap;
}
nextLevel() {
let next;
try {
next = levels[this._currentLevel + 1];
}
catch (e) {
console.log(e);
return false;
}
this.changeLevel(next);
this._currentLevel += 1;
let skillGiven = Game.player.giveRandomSkill();
//TODO: Somehow tell the player what skill they have been given
return true;
}
changeLevel(level) {
let old = this._tileMap;
let newMap = level.call(this);
this._tileMap = newMap;
Game.player.hunger = 1;
this._timeScores.push(playerMenu.time);
playerMenu.time = [0, 0, 0];
main.draw();
// if (level == levels[0]) {
main.resize();
// }
return old;
}
static get player() {
return Game._player;
}
static set player(player) {
Game._player = player;
}
get selected() {
return this._selected;
}
set selected(tiles) {
this._selected = tiles;
}
updatePlayerMana(tiles) {
for (let tile of tiles) {
let vowels = tile.getVowels();
for (let vowel of vowels) {
Game.player.mana.increase(vowel, 1);
}
}
//temporary hacky solution: removes the e and o added from "HERO". TODO
Game.player.mana.decrease("a", 1);
Game.player.mana.decrease("o", 1);
// console.log(Game.player.mana.toString());
}
moveSnake(entity, dir) {
if (dir == [0, 0] || !dir) {
return null;
}
entity.oldDirs.unshift(dir);
if (entity.oldDirs.length > entity.location.length) {
entity.oldDirs.pop();
}
let oldLocation = entity.location;
let oldHead = entity.head;
let newLocation = [];
let newHead = [(oldHead[0] - dir[0]), (oldHead[1] - dir[1])];
if (this.tileMap.getTile(newHead[0], newHead[1]) != null
&& this.tileMap.getTile(newHead[0], newHead[1]).containsEntity(entity)) {
return oldLocation;
}
newLocation.push(newHead);
oldLocation = oldLocation.slice(0, -1);
newLocation = newLocation.concat(oldLocation);
return newLocation;
}
undoSnake(entity) {
let oldLocation = entity.location;
let oldBottom = oldLocation[oldLocation.length - 1];
let newLocation = [];
let dir = entity.oldDirs[entity.oldDirs.length - 1];
let newBottom = [(oldBottom[0] + dir[0]), (oldBottom[1] + dir[1])];
if (this.tileMap.getTile(newBottom[0], newBottom[1]) != null
&& this.tileMap.getTile(newBottom[0], newBottom[1]).containsEntity(entity)) {
return oldLocation;
}
newLocation.push(newBottom);
oldLocation = oldLocation.slice(1, 0);
newLocation = oldLocation.concat(newLocation);
return newLocation;
}
move(entity, newLocation) {
//check length of intended location
if (entity.name.length != newLocation.length) {
return false;
}
if (newLocation.includes(null)) {
return false;
}
//check if location contains at least one instance of entity
let i;
for (i = newLocation.length - 1; i >= 0; i--) {
if (newLocation[i].entities.includes(entity)) {
break;
}
}
if (i == -1) {
return false;
}
//check if selected is in a line
// let xdiff: number = Math.abs(this._tileMap.getTileLocation(newLocation[0])[0] - this._tileMap.getTileLocation(newLocation[newLocation.length - 1])[0]);
// let ydiff: number = Math.abs(this._tileMap.getTileLocation(newLocation[0])[1] - this._tileMap.getTileLocation(newLocation[newLocation.length - 1])[1]);
// if ((ydiff != 3 && ydiff != 0) || (xdiff != 3 && xdiff != 0)) {
// return false;
// }
//if all conditions were met, move to new location
let oldLocation = this._tileMap.getEntityTiles(entity);
for (let i = 0; i < newLocation.length; i++) {
let index = oldLocation[i].entityIndex(entity);
oldLocation[i].removeEntity(entity);
oldLocation[i].removeLetterAtIndex(index);
newLocation[i].addEntity(entity);
newLocation[i].addLetter(entity.name.charAt(i));
}
let curLocation = [];
for (let i = 0; i < newLocation.length; i++) {
curLocation.push(this._tileMap.getTileLocation(newLocation[i]));
}
entity.location = curLocation;
this._selected = [];
if (entity == Game._player) {
// this.updatePlayerMana(newLocation);
}
return true;
}
headshift(entity, mul) {
let newHead = entity.head;
newHead[0] += mul * entity.dir[0];
newHead[1] += mul * entity.dir[1];
let line = this._tileMap.getTiles(this._tileMap.line(newHead, entity.dir, entity.length));
if (line.indexOf(null) == -1 && this.move(entity, line)) {
entity.head = newHead;
return true;
}
else {
return false;
}
}
// changeDir(entity: Entity, dir: number[]): boolean {
// let line = this._tileMap.getTiles(this._tileMap.line(entity.head, dir, entity.length));
// if (line.indexOf(null) == -1 && this.move(entity, line)) {
// entity.dir = dir;
// return true;
// } else {
// return false;
// }
// }
rotateDir(entity, clockwise) {
let newDir = this._tileMap.rotateDir(entity.dir, clockwise);
entity.dir = newDir;
// return this.changeDir(entity, newdir);
return true;
}
}
/// <reference path="../_references.ts" />
class Tile {
constructor() {
this._entities = [];
this._letters = [];
}
get letters() {
return this._letters;
}
set letters(letters) {
this._letters = letters;
}
addLetter(letter) {
this._letters.push(letter);
}
removeLetter(letter) {
let index = this._letters.indexOf(letter);
this._letters.splice(index, 1);
}
removeLetterAtIndex(index) {
this._letters.splice(index, 1);
}
removeTopLetter() {
this._letters.pop();
}
changeLetter(index, newLetter) {
this._letters[index] = newLetter;
}
getTopLetter() {
return this._letters[this._letters.length - 1];
}
get entities() {
return this._entities;
}
set entities(entities) {
this._entities = entities;
}
addEntity(entity) {
this._entities.push(entity);
}
containsEntity(entity) {
return this._entities.indexOf(entity) != -1;
}
removeEntity(entity) {
for (let i = 0; i < this._entities.length; i++) {
if (this._entities[i] == entity) {
this._entities.splice(i, 1);
}
}
}
entityIndex(entity) {
return this._entities.indexOf(entity);
}
getVowels() {
let vowels = [];
for (let letter of this._letters) {
if ("aieou".includes(letter.toLowerCase())) {
vowels.push(letter);
}
}
return vowels;
}
}
/// <reference path="../_references.ts" />
class TileMap {
constructor(width, height) {
this._width = width;
this._height = height;
this._entities = [];
this._tiles = new Array(this._width);
for (let x = 0; x < this._width; x++) {
this._tiles[x] = new Array(this._height);
for (let y = 0; y < this._height; y++) {
let entity = new Ground();
entity.location.push([x, y]);
this._tiles[x][y] = new Tile();
this._tiles[x][y].addLetter(entity.name);
this._tiles[x][y].addEntity(entity);
this._entities.push(entity);
}
}
}
get width() {
return this._width;
}
get height() {
return this._height;
}
get tiles() {
return this._tiles;
}
get entities() {
return this._entities;
}
randomPosDir() {
let x = Math.floor(Math.random() * this._width), y = Math.floor(Math.random() * this._height);
let directions = [-1, 0, 1];
let xStep = directions[Math.floor((Math.random() * 3))];
if (xStep == 0) {
directions = [-1, 1];
}
let yStep = directions[Math.floor((Math.random() * directions.length))];
return [x, y, xStep, yStep];
}
rotateDir(dir, clockwise) {
let cos45 = 0.70710678118;
let sin45 = 0.70710678118;
let x = dir[0];
let y = dir[1];
if (clockwise) {
return [Math.round(x * cos45 + y * sin45), Math.round(y * cos45 - x * sin45)];
}
else {
return [Math.round(x * cos45 - y * sin45), Math.round(x * sin45 + y * cos45)];
}
}
insertEntities(entities) {
for (let i = 0; i < entities.length; i++) {
this.insertEntity(entities[i]);
}
}
line(head, dir, length) {
let locations = [];
let x = head[0];
let y = head[1];
for (let i = 0; i < length; i++) {
locations.push([x, y]);
x += dir[0];
y += dir[1];
}
return locations;
}
//inseerts the player at a random blank space
// draws player horizontally
insertPlayer(entity) {
let pos = this.randomPosDir();
let x = pos[0], y = pos[1];
let path = [];
let i;
let xStep = 1;
let yStep = 0;
//Does entity name fit?
for (i = 0; i < entity.name.length; i++) {
if (x < this.width && x > 0 && y < this.height && y > 0) {
let tile = this._tiles[x][y];
if (tile.entities.length == 1) { //||
// tile.getTopLetter() == entity.name.charAt(i)) {
tile.addLetter(entity.name.charAt(i));
path.push([x, y]);
x += xStep;
y += yStep;
}
else {
break;
}
}
else {
break;
}
}
//If so, add entity to tile.
if (i == entity.name.length) {
let currLocation = [];
for (let location of path) {
currLocation.push(location);
let x = location[0];
let y = location[1];
this._tiles[x][y].addEntity(entity);
}
entity.location = currLocation;
this._entities.push(entity);
return true;
}
else {
for (let location of path) {
let x = location[0];
let y = location[1];
this._tiles[x][y].removeTopLetter();
}
return this.insertPlayer(entity);
}
}
insertEntityAt(entity, x, y, xStep, yStep) {
let path = [];
let i;
//Does entity name fit?
for (i = 0; i < entity.name.length; i++) {
if (x < this.width && x > 0 && y < this.height && y > 0) {
let tile = this._tiles[x][y];
if (tile.entities.length == 1 ||
tile.getTopLetter() == entity.name.charAt(i)) {
tile.addLetter(entity.name.charAt(i));
path.push([x, y]);
x += xStep;
y += yStep;
}
else {
break;
}
}
else {
break;
}
}
//If so, add entity to tile.
if (i == entity.name.length) {
let currLocation = [];
for (let location of path) {
currLocation.push(location);
let x = location[0];
let y = location[1];
this._tiles[x][y].addEntity(entity);
}
entity.location = currLocation;
this._entities.push(entity);
return true;
}
else {
for (let location of path) {
let x = location[0];
let y = location[1];
this._tiles[x][y].removeTopLetter();
}
return this.insertEntity(entity);
}
}
insertEntity(entity) {
let posDir = this.randomPosDir();
let x = posDir[0], y = posDir[1], xStep = posDir[2], yStep = posDir[3];
let result = this.insertEntityAt(entity, x, y, xStep, yStep);
if (result == false) {
return this.insertEntity(entity);
}
else {
return result;
}
}
// insertEntityAtLocation(entity: Entity, x: number, y: number, xStep: number, yStep: number): boolean {
//
// let path: number[][] = [];
// let i: number;
//
// //Does entity name fit?
// for (i = 0; i < entity.name.length; i++) {
// if (x < this.width && x >= 0 && y < this.height && y >= 0) {
// let tile: Tile = this._tiles[x][y];
// if (tile.entities.length == 1 ||
// tile.getTopLetter() == entity.name.charAt(i)) {
// tile.addLetter(entity.name.charAt(i));
// path.push([x,y]);
// x += xStep;
// y += yStep;
// } else {
// break;
// }
// } else {
// break;
// }
// }
//
// //If so, add entity to tile.
// if (i == entity.name.length) {
// let currLocation = [];
// for (let location of path) {
// currLocation.push(location);
// let x: number = location[0];
// let y: number = location[1];
// this._tiles[x][y].addEntity(entity);
// }
// entity.location = currLocation;
// this._entities.push(entity);
// return true;
// } else {
// for (let location of path) {
// let x: number = location[0];
// let y: number = location[1];
// this._tiles[x][y].removeTopLetter();
// }
// return false;
// }
// }
removeEntity(entity) {
//TODO
let tiles = this.getEntityTiles(entity);
if (tiles.length <= 0) {
throw ("Entity not found.");
}
for (let tile of tiles) {
tile.removeEntity(entity);
tile.removeTopLetter();
}
game.dead.push(entity);
return entity;
}
// removeEntityKeepLetters(entity: Entity): Entity {
// //TODO
// let tiles: Tile[] = this.getEntityTiles(entity);
// if (tiles.length <= 0) {
// throw ("Entity not found.");
// }
// for (let tile of tiles) {
// tile.removeEntity(entity);
// // tile.removeTopLetter();
// }
// game.dead.push(entity);
// return entity;
// }
getTileLocation(tile) {
for (let x = 0; x < this._width; x++) {
for (let y = 0; y < this._height; y++) {
if (this._tiles[x][y] == tile) {
return [x, y];
}
}
}
}
getTile(x, y) {
if (x < 0 || x >= this.width || y < 0 || y >= this.height) {
// console.log("out of bounds....");
return null;
}
return this._tiles[x][y];
}
getTiles(points) {
let result = [];
for (let i = 0; i < points.length; i++) {
result.push(this.getTile(points[i][0], points[i][1]));
}
return result;
}
getEntityTiles(entity) {
let entityTiles = new Array();
for (let x = 0; x < this._width; x++) {
for (let y = 0; y < this._height; y++) {
let curr = this.getTile(x, y);
if (curr.containsEntity(entity)) {
entityTiles.push(curr);
}
}
}
return entityTiles;
}
}
/// <reference path="../_references.ts" />
class Entity {
constructor(name) {
this._name = name;
this._location = [];
// this._active = false;
this._oldDirs = [];
}
//override this default method method
playerCollision() {
// let that = this;
// window.setTimeout(function() {
// game.tileMap.removeEntity(that);
// }, 1000);
}
get name() {
return this._name;
}
set name(name) {
this._name = name;
}
get length() {
return this._name.length;
}
get location() {
return this._location;
}
set location(location) {
this._location = location;
if (location.length < 2) {
return;
}
this._head = location[0];
this._dir = [location[1][0] - this._head[0], location[1][1] - this._head[1]];
}
locationIncludes(x, y) {
for (let i = 0; i < this._location.length; i++) {
if (this._location[i][0] == x && this._location[i][1] == y) {
return true;
}
}
return false;
}
get head() {
return this._head;
}
set head(head) {
this._head = head;
}
get tail() {
return [this._head[0] + this.length * this._dir[0], this._head[1] + this.length * this._dir[1]];
}
get dir() {
return this._dir;
}
set dir(dir) {
this._dir = dir;
}
get oldDirs() {
return this._oldDirs;
}
set oldDirs(oldDirs) {
this._oldDirs = oldDirs;
}
get reverseDir() {
return [this._dir[0] * -1, this._dir[1] * -1];
}
}
/// <reference path="../_references.ts" />
class Ground extends Entity {
constructor() {
let randomLetter = Ground.alphabet[Math.floor(Math.random() * Ground.alphabet.length)];
super(randomLetter);
}
playerCollision() {
if (this.name != " ") {
Game.player.hunger -= 1;
let tile = game.tileMap.tiles[this.location[0][0]][this.location[0][1]];
let oldName = this.name;
this.name = " ";
tile.changeLetter(tile.letters.length - 2, this.name);
}
// this.interval = setInterval(this.revert.bind(this, tile, oldName), 10000);
}
revert(tile, oldName) {
this.name = oldName;
tile.changeLetter(tile.letters.length - 1, this.name);
clearInterval(this.interval);
}
}
//private static readonly alphabet: string[] = "abcdefghijklmnopqrstuvwxyz".split('');
Ground.alphabet = "bcdfghjklmnpqrstvwxyz".split('');
/// <reference path="../_references.ts" />
class Character extends Entity {
constructor(name) {
super(name);
this._inventory = [];
}
attack(enemy) {
enemy._health -= this._attackDamage;
}
addItem(item) {
this._inventory.push(item);
}
removeItem(item) {
let index = this._inventory.indexOf(item);
this._inventory.splice(index, 1);
}
//TODO
die() {
// if (!this.isDead) {
// if(game.tileMap.removeEntity(this)) {
// this.isDead = true;
// game.deadEntities.push(this);
// return true;
// }
// }
for (let item of this._inventory) {
game.colliding.push(item);
}
return false;
}
playerCollision() {
// while (this.isAlive() && Game.player.isAlive()) {
// Game.player.attack(this);
// this.attack(Game.player);
// console.log("enemy battled");
// }
// if (Game.player.isDead()) {
// Game.player.die();
// }
if (!Battle.active) {
// let b = new Battle(this._health, this._name, 3);
let b = new Battle(this, 3);
game.battle = b;
Battle.active = true;
}
super.playerCollision();
}
isDead() {
return !(this._health > 0);
}
isAlive() {
return (this._health > 0);
}
get inventory() {
return this._inventory;
}
giveItem(item) {
this._inventory.push(item);
}
get health() {
return this._health;
}
set health(health) {
this._health = health;
}
get attackDamage() {
return this._attackDamage;
}
set attackDamage(attackDamage) {
this._attackDamage;
}
inventoryToString() {
let s = "Inventory: ";
if (this._inventory.length > 0) {
s += this._inventory[0].name;
for (let i = 1; i < this._inventory.length; i++) {
s += ", " + this._inventory[i].name;
}
}
return s;
}
}
/// <reference path="../_references.ts" />
class Player extends Character {
constructor(name) {
super(name);
super._health = 10;
super._attackDamage = 1;
// super._active = true;
this._mana = new Manager("AAAAAAAAAA");
this._skills = [skills.slap, skills.yell, skills.pinch, skills.bop, skills.hug];
this._hunger = 2;
this._maxHunger = 10;
}
get mana() {
return this._mana;
}
set mana(mana) {
this._mana = mana;
}
get hunger() {
return this._hunger;
}
set hunger(hunger) {
this._hunger = hunger;
}
get maxHunger() {
return this._maxHunger;
}
set maxHunger(maxHunger) {
this._maxHunger = maxHunger;
}
get skills() {
return this._skills;
}
giveRandomSkill() {
let keepGoing = true;
while (keepGoing) {
let skill = allSkillNames[Math.floor(Math.random() * allSkillNames.length)];
keepGoing = !this.giveSkill(skills[skill]);
return skills[skill];
}
}
giveSkill(s) {
if (this._skills.indexOf(s) == -1 || s.constructor.name == "UsableOnceSkill") {
this._skills.push(s);
return true;
}
else {
return false;
}
}
revokeSkill(s) {
let index = this._skills.indexOf(s);
if (index != -1) {
this._skills.splice(index, 1);
}
else {
console.log("unspliceable");
}
}
playerCollision() { }
}
/// <reference path="../_references.ts" />
class Manager {
constructor(word = "") {
this._a = 0;
this._e = 0;
this._i = 0;
this._o = 0;
this._u = 0;
word = word.toLowerCase();
for (let i = 0; i < word.length; i++) {
let char = word.charAt(i);
if (Manager.vowels.indexOf(char) != -1) {
this.increase(char, 1);
}
}
}
get a() {
return this._a;
}
set a(x) {
this._a = x;
}
get e() {
return this._e;
}
set e(x) {
this._e = x;
}
get i() {
return this._i;
}
set i(x) {
this._i = x;
}
get o() {
return this._o;
}
set o(x) {
this._o = x;
}
get u() {
return this._u;
}
set u(x) {
this._u = x;
}
getAmount(which) {
switch (which.toLowerCase()) {
case "a":
return this._a;
case "e":
return this._e;
case "i":
return this._i;
case "o":
return this._o;
case "u":
return this._u;
}
}
setAmount(which, x) {
if (x < 0) {
x = 0;
}
switch (which.toLowerCase()) {
case "a":
this._a = x;
break;
case "e":
this._e = x;
break;
case "i":
this._i = x;
break;
case "o":
this._o = x;
break;
case "u":
this._u = x;
break;
}
}
increase(which, x) {
this.setAmount(which, this.getAmount(which) + x);
// switch (which.toLowerCase()) {
// case "a":
// this._a += x;
// break;
// case "e":
// this._e += x;
// break;
// case "i":
// this._i += x;
// break;
// case "o":
// this._o += x;
// break;
// case "u":
// this._u += x;
// break;
// }
}
decrease(which, x) {
this.setAmount(which, this.getAmount(which) - x);
// switch (which.toLowerCase()) {
// case "a":
// this._a -= x;
// break;
// case "e":
// this._e -= x;
// break;
// case "i":
// this._i -= x;
// break;
// case "o":
// this._o -= x;
// break;
// case "u":
// this._u -= x;
// break;
// }
}
add(other) {
for (let letter of Manager.vowels) {
console.log(letter);
console.log(other.getAmount(letter));
this.increase(letter, other.getAmount(letter));
}
return this;
}
subtract(other) {
for (let letter of Manager.vowels) {
this.decrease(letter, other.getAmount(letter));
}
return this;
}
multiply(scalar) {
scalar = Math.round(scalar);
for (let letter in Manager.vowels) {
this.setAmount(letter, this.getAmount(letter) * scalar);
}
return this;
}
fitsInto(other) {
for (let letter of Manager.vowels) {
if (this.getAmount(letter) > other.getAmount(letter)) {
return false;
}
}
return true;
}
isEmpty() {
return this.fitsInto(new Manager());
}
toString() {
return "Mana Runes (A: " + this._a + ", " + "E: " + this._e + ", " + "I: " + this._i + ", " + "O: " + this._o + ", " + "U: " + this._u + ")";
}
}
Manager.vowels = ["a", "e", "i", "o", "u"];
/// <reference path="../_references.ts" />
let enemies = {
Dinosaur: class extends Character {
constructor() {
super("Dinosaur");
super._health = 9;
super._attackDamage = 2;
}
},
Ghoul: class extends Character {
constructor() {
super("Ghoul");
super._health = 4;
super._attackDamage = 2;
}
},
Goblin: class extends Character {
constructor() {
super("Goblin");
super._health = 3;
super._attackDamage = 2;
}
},
Rat: class extends Character {
constructor() {
super("Rat");
super._health = 1;
super._attackDamage = 2;
}
},
Robot: class extends Character {
constructor() {
super("Robot");
super._health = 6;
super._attackDamage = 2;
}
},
Unicorn: class extends Character {
constructor() {
super("Unicorn");
super._health = 8;
super._attackDamage = 2;
}
},
Wizard: class extends Character {