Skip to content

Commit 7d3a329

Browse files
committed
[WIP] JS-II
1 parent 63e591a commit 7d3a329

1 file changed

Lines changed: 31 additions & 3 deletions

File tree

src/prototype.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,51 @@ class GameObject {
5454
this.createdAt = obj.createdAt;
5555
this.dimensions = obj.dimensions;
5656
}
57-
5857
GameObject.prototype.destroy = function(destroyed) {
59-
console.log('Game object was removed from the game.') // Return string 'Game object was removed from the game.'
58+
console.log('Game object was removed from the game.') // Returns the string 'Game object was removed from the game.'
6059
};
6160
}
6261

6362
class NPC extends GameObject {
6463
constructor(npcObj) {
6564
super(npcObj);
6665
this.hp = 5;
67-
this.name = //??
66+
this.name = npcObj.name;
6867
}
6968
NPC.prototype.takeDamage = function(damage) {
7069
console.log(`${this.name} took damage.`) // Returns the string '<object name> took damage.'
7170
};
7271
}
7372

73+
class Humanoid extends NPC {
74+
constructor(humanoidObj) {
75+
super(humanoidObj);
76+
this.faction = humanoidObj.faction;
77+
this.weapons = humanoidObj.weapons;
78+
this.language = humanoidObj.language;
79+
}
80+
Humanoid.prototype.greet = function(greeting) {
81+
console.log(`${this.name} offers a greeting in ${this.language}.`) // Returns "(name) offers a greeting in (language)."
82+
};
83+
}
84+
85+
const hamsterHuey = new Humanoid({
86+
createdAt: new Date(),
87+
dimensions: {
88+
length: 2,
89+
width: 1,
90+
height: 1,
91+
},
92+
hp: 5,
93+
name: 'Hamster Huey',
94+
faction: 'Gooey Kablooie',
95+
weapons: [
96+
'bubblegum',
97+
],
98+
language: 'Hamsterish',
99+
});
100+
101+
console.log(hamsterHuey);
74102

75103

76104

0 commit comments

Comments
 (0)