Skip to content

Commit 91e705c

Browse files
committed
completed prototype.js
1 parent 9a4f0b9 commit 91e705c

1 file changed

Lines changed: 56 additions & 20 deletions

File tree

‎src/prototype.js‎

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,36 @@
77
createdAt
88
dimensions
99
destroy() // prototype method -> returns the string 'Game object was removed from the game.'
10+
*/
11+
12+
function GameObject(options) {
13+
this.createdAt = options.createdAt;
14+
this.dimensions = options.dimensions;
15+
}
16+
17+
GameObject.prototype.destroy = function destroy() {
18+
return 'Game object was removed from the game.';
19+
};
1020

21+
/*
1122
NPC
1223
hp
1324
name
1425
takeDamage() // prototype method -> returns the string '<object name> took damage.'
1526
// should inherit destroy() from GameObject's prototype
27+
*/
28+
function NPC(options) {
29+
GameObject.call(this, options);
30+
this.hp = options.hp;
31+
this.name = options.name;
32+
}
33+
34+
NPC.prototype = Object.create(GameObject.prototype);
35+
NPC.prototype.takeDamage = function takeDamage() {
36+
return (`${this.name} took damage.`);
37+
};
1638

39+
/*
1740
Humanoid
1841
faction
1942
weapons
@@ -27,27 +50,40 @@
2750
Instances of NPC should have all of the same properties as GameObject.
2851
2952
Example:
53+
*/
3054

31-
const hamsterHuey = new Humanoid({
32-
createdAt: new Date(),
33-
dimensions: {
34-
length: 2,
35-
width: 1,
36-
height: 1,
37-
},
38-
hp: 5,
39-
name: 'Hamster Huey',
40-
faction: 'Gooey Kablooie',
41-
weapons: [
42-
'bubblegum',
43-
],
44-
language: 'Hamsterish',
45-
});
46-
47-
hamsterHuey.greet(); // returns 'Hamster Huey offers a greeting in Hamsterish'
48-
hamsterHuey.takeDamage(); // returns 'Hamster Huey took damage.'
49-
hamsterHuey.destroy(); // returns 'Game object was removed from the game.'
50-
*/
55+
function Humanoid(options) {
56+
NPC.call(this, options);
57+
GameObject.call(this, options);
58+
this.faction = options.faction;
59+
this.weapons = options.weapons;
60+
this.language = options.language;
61+
}
62+
63+
Humanoid.prototype = Object.create(NPC.prototype);
64+
Humanoid.prototype.greet = function greet() {
65+
return (`${this.name} offers a greeting in ${this.language}.`);
66+
};
67+
68+
const hamsterHuey = new Humanoid({
69+
createdAt: new Date(),
70+
dimensions: {
71+
length: 2,
72+
width: 1,
73+
height: 1,
74+
},
75+
hp: 5,
76+
name: 'Hamster Huey',
77+
faction: 'Gooey Kablooie',
78+
weapons: [
79+
'bubblegum',
80+
],
81+
language: 'Hamsterish',
82+
});
83+
84+
hamsterHuey.greet(); // returns 'Hamster Huey offers a greeting in Hamsterish'
85+
hamsterHuey.takeDamage(); // returns 'Hamster Huey took damage.'
86+
hamsterHuey.destroy(); // returns 'Game object was removed from the game.'
5187

5288
/* eslint-disable no-undef */
5389

0 commit comments

Comments
 (0)