-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprototype.js
More file actions
49 lines (46 loc) · 1.17 KB
/
prototype.js
File metadata and controls
49 lines (46 loc) · 1.17 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
function GameObject(properties) {
this.createdAt = properties.createdAt;
this.dimensions = properties.dimensions;
}
GameObject.prototype.destroy = function _() {
return 'Game object was removed from the game.';
};
function NPC(stats) {
GameObject.call(this, stats);
this.hp = stats.hp;
this.name = stats.name;
}
function Humanoid(characteristics) {
NPC.call(this, characteristics);
this.faction = characteristics.faction;
this.weapons = characteristics.weapons;
this.language = characteristics.language;
}
NPC.prototype = Object.create(GameObject.prototype);
NPC.prototype.takeDamage = function _() {
return `${this.name} took damage.`;
};
Humanoid.prototype = Object.create(NPC.prototype);
Humanoid.prototype.greet = function _() {
return `${this.name} offers a greeting in ${this.language}.`;
};
const dogRomeo = new Humanoid({
createdAt: new Date(),
dimensions: {
length: 12,
width: 2,
height: 2,
},
hp: 1000,
name: 'Romeo',
faction: 'Bohemia',
weapon: ['ultrasonic bark', 'jaws of death', 'rocket mode'],
language: 'Italian',
});
dogRomeo.destroy();
/* eslint-disable no-undef */
module.exports = {
GameObject,
NPC,
Humanoid,
};