Skip to content
This repository was archived by the owner on Feb 14, 2022. It is now read-only.

Commit dc277a6

Browse files
committed
Finished part16
1 parent 32a93ce commit dc277a6

File tree

9 files changed

+359
-41
lines changed

9 files changed

+359
-41
lines changed

assets/dynamicglyph.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,26 @@ class DynamicGlyph extends Glyph {
9292
// Extract any arguments passed, removing the event name
9393
var args = Array.prototype.slice.call(arguments, 1)
9494
// Invoke each listener, with this entity as the context and the arguments
95+
var results = [];
9596
for (var i = 0; i < this._listeners[event].length; i++) {
96-
this._listeners[event][i].apply(this, args);
97+
results.push(this._listeners[event][i].apply(this, args));
9798
}
99+
return results;
98100
}
99101

102+
details() {
103+
var details = [];
104+
var detailGroups = this.raiseEvent('details');
105+
// Iterate through each return value, grabbing the detaisl from the arrays.
106+
if (detailGroups) {
107+
for (var i = 0, l = detailGroups.length; i < l; i++) {
108+
if (detailGroups[i]) {
109+
for (var j = 0; j < detailGroups[i].length; j++) {
110+
details.push(detailGroups[i][j].key + ': ' + detailGroups[i][j].value);
111+
}
112+
}
113+
}
114+
}
115+
return details.join(', ');
116+
}
100117
}

assets/entities.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
// Player template
33
Game.PlayerTemplate = {
4+
name: 'human (you)',
45
character: '@',
56
foreground: 'white',
67
background: 'black',

assets/entitymixins.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ Game.EntityMixins.Destructible = {
6565
onGainLevel: function() {
6666
// Heal the entity.
6767
this.setHp(this.getMaxHp());
68+
},
69+
details: function() {
70+
return [
71+
{key: 'defense', value: this.getDefenseValue()},
72+
{key: 'hp', value: this.getHp()}
73+
];
6874
}
6975
}
7076
}
@@ -112,6 +118,11 @@ Game.EntityMixins.Attacker = {
112118

113119
target.takeDamage(this, damage);
114120
}
121+
},
122+
listeners: {
123+
details: function() {
124+
return [{key: 'attack', value: this.getAttackValue()}];
125+
}
115126
}
116127
}
117128

@@ -571,6 +582,9 @@ Game.EntityMixins.ExperienceGainer = {
571582
if (exp > 0) {
572583
this.giveExperience(exp);
573584
}
585+
},
586+
details: function() {
587+
return [{key: 'level', value: this.getLevel()}];
574588
}
575589
}
576590
};

assets/geometry.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Game.Geometry = {
2+
getLine: function(startX, startY, endX, endY) {
3+
var points = [];
4+
var dx = Math.abs(endX - startX);
5+
var dy = Math.abs(endY - startY);
6+
var sx = (startX < endX) ? 1 : -1;
7+
var sy = (startY < endY) ? 1 : -1;
8+
var err = dx - dy;
9+
var e2;
10+
11+
while (true) {
12+
points.push({x: startX, y: startY});
13+
if (startX == endX && startY == endY) {
14+
break;
15+
}
16+
e2 = err * 2;
17+
if (e2 > -dx) {
18+
err -= dy;
19+
startX += sx;
20+
}
21+
if (e2 < dx){
22+
err += dx;
23+
startY += sy;
24+
}
25+
}
26+
27+
return points;
28+
}
29+
};

assets/glyph.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ class Glyph {
1818
return this._foreground;
1919
}
2020

21+
getRepresentation() {
22+
return '%c{' + this._foreground + '}%b{' + this._background + '}' + this._char +
23+
'%c{white}%b{black}';
24+
}
2125
}

assets/itemmixins.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ Game.ItemMixins.Edible = {
2727
} else {
2828
return this._name;
2929
}
30+
},
31+
listeners: {
32+
'details': function() {
33+
return [{key: 'food', value: this._foodValue}];
34+
}
3035
}
3136
};
3237

@@ -49,5 +54,17 @@ Game.ItemMixins.Equippable = {
4954
},
5055
isWearable: function() {
5156
return this._wearable;
57+
},
58+
listeners: {
59+
'details': function() {
60+
var results = [];
61+
if (this._wieldable) {
62+
results.push({key: 'attack', value: this.getAttackValue()});
63+
}
64+
if (this._wearable) {
65+
results.push({key: 'defense', value: this.getDefenseValue()});
66+
}
67+
return results;
68+
}
5269
}
5370
};

0 commit comments

Comments
 (0)