|
16 | 16 | * destroy() // prototype method that returns: `${this.name} was removed from the game.` |
17 | 17 | */ |
18 | 18 |
|
| 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 | + |
19 | 29 | /* |
20 | 30 | === CharacterStats === |
21 | 31 | * healthPoints |
22 | 32 | * takeDamage() // prototype method -> returns the string '<object name> took damage.' |
23 | 33 | * should inherit destroy() from GameObject's prototype |
24 | 34 | */ |
25 | 35 |
|
| 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 | + |
26 | 47 | /* |
27 | 48 | === Humanoid (Having an appearance or character resembling that of a human.) === |
28 | 49 | * team |
|
32 | 53 | * should inherit destroy() from GameObject through CharacterStats |
33 | 54 | * should inherit takeDamage() from CharacterStats |
34 | 55 | */ |
| 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 | +} |
35 | 69 |
|
36 | 70 | /* |
37 | 71 | * Inheritance chain: GameObject -> CharacterStats -> Humanoid |
|
0 commit comments