|
39 | 39 | * Instances of CharacterStats should have all of the same properties as GameObject. |
40 | 40 | */ |
41 | 41 |
|
| 42 | +function GameObject (objAttributes) { |
| 43 | + this.createdAt = objAttributes.createdAt; |
| 44 | + this.dimensions = objAttributes.dimensions; |
| 45 | +} |
| 46 | + |
| 47 | +GameObject.prototype.destroy = function (){ |
| 48 | + return `${this.name} was removed from the game.`; |
| 49 | +} |
| 50 | + |
| 51 | +function CharacterStats(charAttributes){ |
| 52 | + GameObject.call(this, charAttributes); |
| 53 | + this.hp = charAttributes.hp; |
| 54 | + this.name = charAttributes.name; |
| 55 | +} |
| 56 | + |
| 57 | +CharacterStats.prototype = Object.create(GameObject.prototype); |
| 58 | + |
| 59 | +CharacterStats.prototype.takeDamage = function (){ |
| 60 | + return `${this.name} took damage`; |
| 61 | +}; |
| 62 | + |
| 63 | +function Humanoid(humanAttributes){ |
| 64 | + CharacterStats.call(this, humanAttributes); |
| 65 | + this.faction = humanAttributes.faction; |
| 66 | + this.weapons = humanAttributes.weapons; |
| 67 | + this.language = humanAttributes.language; |
| 68 | +} |
| 69 | + |
| 70 | +Humanoid.prototype = Object.create(CharacterStats.prototype); |
| 71 | + |
| 72 | +Humanoid.prototype.greet = function (){ |
| 73 | + return `${this.name} offers a greeting in ${this.language}`; |
| 74 | +} |
| 75 | + |
42 | 76 | // Test you work by uncommenting these 3 objects and the list of console logs below: |
43 | 77 |
|
44 | | -/* |
| 78 | + |
45 | 79 | const mage = new Humanoid({ |
46 | 80 | createdAt: new Date(), |
47 | 81 | dimensions: { |
|
102 | 136 | console.log(archer.greet()); // Lilith offers a greeting in Elvish. |
103 | 137 | console.log(mage.takeDamage()); // Bruce took damage. |
104 | 138 | console.log(swordsman.destroy()); // Sir Mustachio was removed from the game. |
105 | | -*/ |
106 | 139 |
|
107 | 140 | // Stretch task: |
108 | 141 | // * Create Villian and Hero constructor functions that inherit from the Humanoid constructor function. |
|
0 commit comments