Repository navigation
Expand file tree
/
Copy pathprototype.js
More file actions
67 lines (57 loc) · 1.32 KB
/
Copy pathprototype.js
File metadata and controls
67 lines (57 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class GameObject {
constructor(options) {
this.createdAt = options.createdAt;
this.dimensions = options.dimensions;
}
destroy() {
const x = '';
this.x = 'Game object was removed from the game.';
return this.x;
}
}
// GameObject.prototype.
class NPC extends GameObject {
constructor(npcOptions) {
super(npcOptions);
this.hp = npcOptions.hp;
this.name = npcOptions.name;
}
takeDamage() {
return `${this.name} took damage.`;
}
}
class Humanoid extends NPC {
constructor(humanoidOptions) {
super(humanoidOptions);
this.faction = humanoidOptions.faction;
this.weapons = humanoidOptions.weapons;
this.language = humanoidOptions.language;
}
greet() {
return `${this.name} offers a greeting in ${this.language}.`;
}
}
const hamsterHuey = new Humanoid({
createdAt: Date(),
dimensions: {
length: 2,
width: 1,
height: 1,
},
hp: 5,
name: 'Hamster Huey',
faction: 'Gooey Kablooie',
weapons: [
'bubblegum',
],
language: 'Hamsterish',
});
hamsterHuey.greet(); // returns 'Hamster Huey offers a greeting in Hamsterish'
hamsterHuey.takeDamage(); // returns 'Hamster Huey took damage.'
hamsterHuey.destroy(); // returns 'Game object was removed from the game.'
/* eslint-disable no-undef */
module.exports = {
GameObject,
NPC,
Humanoid,
};