|
49 | 49 | hamsterHuey.destroy(); // returns 'Game object was removed from the game.' |
50 | 50 | */ |
51 | 51 |
|
| 52 | +/* |
| 53 | + GameObject |
| 54 | + createdAt |
| 55 | + dimensions |
| 56 | + destroy() // prototype method -> returns the string 'Game object was removed from the game.' |
| 57 | +*/ |
| 58 | +function GameObject(options) { |
| 59 | + this.createdAt = options.createdAt; |
| 60 | + this.dimensions = options.dimensions; |
| 61 | +} |
| 62 | +GameObject.prototype.destroy = function () { |
| 63 | + return 'Game object was removed from the game.'; |
| 64 | +}; |
| 65 | + |
| 66 | +/* |
| 67 | + NPC |
| 68 | + hp |
| 69 | + name |
| 70 | + takeDamage() // prototype method -> returns the string '<object name> took damage.' |
| 71 | + // should inherit destroy() from GameObject's prototype |
| 72 | +*/ |
| 73 | +function NPC(options) { |
| 74 | + GameObject.call(this, options); |
| 75 | + this.hp = options.hp; |
| 76 | + this.name = options.name; |
| 77 | +} |
| 78 | +NPC.prototype = Object.create(GameObject.prototype); |
| 79 | +NPC.prototype.takeDamage = function () { |
| 80 | + return `${this.name} took damage.`; |
| 81 | +}; |
| 82 | + |
| 83 | +/* |
| 84 | + Humanoid |
| 85 | + faction |
| 86 | + weapons |
| 87 | + language |
| 88 | + greet() // prototype method -> returns the string '<object name> offers a greeting in <object language>.' |
| 89 | + // should inherit destroy() from GameObject through NPC |
| 90 | + // should inherit takeDamage() from NPC |
| 91 | +*/ |
| 92 | +function Humanoid(options) { |
| 93 | + NPC.call(this, options); |
| 94 | + this.faction = options.faction; |
| 95 | + this.weapons = options.weapons; |
| 96 | + this.language = options.language; |
| 97 | +} |
| 98 | +Humanoid.prototype = Object.create(NPC.prototype); |
| 99 | +Humanoid.prototype.greet = function () { |
| 100 | + return `${this.name} offers a greeting in ${this.language}.`; |
| 101 | +}; |
| 102 | + |
52 | 103 | /* eslint-disable no-undef */ |
53 | 104 |
|
54 | 105 | module.exports = { |
|
0 commit comments