Skip to content

Commit 59c8e7a

Browse files
committed
Thank god for copy and pasting....
1 parent f63da7d commit 59c8e7a

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

‎assignments/prototypes.js‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
* dimensions
1515
* destroy() // prototype method -> returns the string 'Object was removed from the game.'
1616
*/
17+
function GameObject(gameObjAttr) {
18+
this.createdAt = gameObjAttr.createdAt;
19+
this.dimensions = gameObjAttr.dimensions;
20+
}
21+
22+
GameObject.prototype.destroy = function(){
23+
return 'Object was removed from the game';
24+
}
25+
1726

1827
/*
1928
=== CharacterStats ===
@@ -23,6 +32,17 @@
2332
* should inherit destroy() from GameObject's prototype
2433
*/
2534

35+
function CharacterStats(charStatsAttr){
36+
GameObject.call(this,charStatsAttr)
37+
this.hp = charStatsAttr.hp;
38+
this.name = charStatsAttr.name;
39+
}
40+
41+
CharacterStats.prototype = Object.create(GameObject.prototype)
42+
43+
CharacterStats.prototype.takeDamage = function(){
44+
return `$this.name took damage`;
45+
}
2646
/*
2747
=== Humanoid ===
2848
* faction
@@ -33,6 +53,19 @@
3353
* should inherit takeDamage() from CharacterStats
3454
*/
3555

56+
function Humanoid(humanAttr){
57+
CharacterStats.call(this,humanAttr);
58+
this.faction = humanAttr.faction;
59+
this.weapons = humanAttr.weapons;
60+
this.language = humanAttr.language;
61+
}
62+
63+
Humanoid.prototype = Object.create(CharacterStats.prototype)
64+
65+
Humanoid.prototype.greet = function(){
66+
return `${this.name} offers a greeting in ${this.language} `;
67+
}
68+
3669
/*
3770
* Inheritance chain: Humanoid -> CharacterStats -> GameObject
3871
* Instances of Humanoid should have all of the same properties as CharacterStats and GameObject.
@@ -41,7 +74,6 @@
4174

4275
//Test you work by uncommenting these 3 objects and the list of console logs below:
4376

44-
/*
4577
const mage = new Humanoid({
4678
createdAt: new Date(),
4779
dimensions: {
@@ -102,7 +134,7 @@
102134
console.log(archer.greet()); // Lilith offers a greeting in Elvish.
103135
console.log(mage.takeDamage()); // Bruce took damage.
104136
console.log(swordsman.destroy()); // Sir Mustachio was removed from the game.
105-
*/
137+
106138

107139
// Stretch task:
108140
// * Create Villian and Hero classes that inherit from the Humanoid class.

0 commit comments

Comments
 (0)