Skip to content

Commit 30d88a4

Browse files
SunJieMingSunJieMing
authored andcommitted
Added prototype solution
1 parent 07cfe65 commit 30d88a4

2 files changed

Lines changed: 33 additions & 94 deletions

File tree

‎solutions.js‎

Lines changed: 0 additions & 93 deletions
This file was deleted.

‎src/prototype.js‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,39 @@
4949
hamsterHuey.destroy(); // returns 'Game object was removed from the game.'
5050
*/
5151

52-
/* eslint-disable no-undef */
52+
function GameObject(options) {
53+
this.createdAt = options.createdAt;
54+
this.dimensions = options.dimensions;
55+
}
56+
57+
GameObject.prototype.destroy = function destroy() {
58+
return 'Game object was removed from the game.';
59+
};
60+
61+
function NPC(options) {
62+
GameObject.call(this, options);
63+
this.hp = options.hp;
64+
this.name = options.name;
65+
}
66+
67+
NPC.prototype = Object.create(GameObject.prototype);
68+
69+
NPC.prototype.takeDamage = function takeDamage() {
70+
return `${this.name} took damage.`;
71+
};
72+
73+
function Humanoid(options) {
74+
NPC.call(this, options);
75+
this.faction = options.faction;
76+
this.weapons = options.weapons;
77+
this.language = options.language;
78+
}
79+
80+
Humanoid.prototype = Object.create(NPC.prototype);
81+
82+
Humanoid.prototype.greet = function greet() {
83+
return `${this.name} offers a greeting in ${this.language}.`;
84+
};
5385

5486
module.exports = {
5587
GameObject,

0 commit comments

Comments
 (0)