Skip to content

Commit d2672de

Browse files
sofialevinsofialevin
authored andcommitted
Completed prototypes.js.
1 parent 7b31a31 commit d2672de

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎assignments/prototypes.js‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,34 @@
1616
* destroy() // prototype method that returns: `${this.name} was removed from the game.`
1717
*/
1818

19+
function GameObject(attr) {
20+
this.createdAt = attr.createdAt;
21+
this.name = attr.name;
22+
this.dimensions = attr.dimensions;
23+
}
24+
25+
GameObject.prototype.destroy = function() {
26+
return `${this.name} was removed from the game.`
27+
}
28+
1929
/*
2030
=== CharacterStats ===
2131
* healthPoints
2232
* takeDamage() // prototype method -> returns the string '<object name> took damage.'
2333
* should inherit destroy() from GameObject's prototype
2434
*/
2535

36+
function CharacterStats(attr) {
37+
GameObject.call(this, attr);
38+
this.healthPoints = attr.healthPoints;
39+
}
40+
41+
CharacterStats.prototype = Object.create(GameObject.prototype);
42+
43+
CharacterStats.prototype.takeDamage = function() {
44+
return `${this.name} took damage.`
45+
}
46+
2647
/*
2748
=== Humanoid (Having an appearance or character resembling that of a human.) ===
2849
* team
@@ -32,6 +53,19 @@
3253
* should inherit destroy() from GameObject through CharacterStats
3354
* should inherit takeDamage() from CharacterStats
3455
*/
56+
57+
function Humanoid(attr) {
58+
CharacterStats.call(this, attr);
59+
this.team = attr.team;
60+
this.weapons = attr.weapons;
61+
this.language = attr.language;
62+
}
63+
64+
Humanoid.prototype = Object.create(CharacterStats.prototype);
65+
66+
Humanoid.prototype.greet = function() {
67+
return `${this.name} offers a greeting in ${this.language}.`
68+
}
3569

3670
/*
3771
* Inheritance chain: GameObject -> CharacterStats -> Humanoid

0 commit comments

Comments
 (0)