|
40 | 40 | */ |
41 | 41 |
|
42 | 42 | // Test you work by un-commenting these 3 objects and the list of console logs below: |
| 43 | +function GameObject(att){ |
| 44 | + this.createdAt = att.createdAt; |
| 45 | + this.name = att.name; |
| 46 | + this.dimensions = att.dimensions; |
| 47 | +} |
| 48 | +GameObject.prototype.destroy = function(){ |
| 49 | + console.log(`${this.name} was removed from the game`) |
| 50 | +} |
| 51 | + |
| 52 | + |
| 53 | +function CharacterStats(att){ |
| 54 | + GameObject.call(this, att) |
| 55 | + this.healthPoints = att.healthPoints; |
| 56 | + |
| 57 | +} |
| 58 | +CharacterStats.prototype = Object.create(GameObject.prototype) |
| 59 | +CharacterStats.prototype.takeDamage = function () { |
| 60 | + console.log(`${this.name} took damage`) |
| 61 | +} |
| 62 | + |
| 63 | + |
| 64 | +function Humanoid(att){ |
| 65 | + CharacterStats.call(this, att) |
| 66 | + CharacterStats.prototype.takeDamage.call(this, att) |
| 67 | + GameObject.call(this, att) |
| 68 | + this.team = att.team; |
| 69 | + this.weapons = att.weapons; |
| 70 | + this.language = att.language; |
| 71 | + |
| 72 | +} |
| 73 | +Humanoid.prototype = Object.create(CharacterStats.prototype) |
| 74 | +//Humanoid.prototype = Object.create(CharacterStats.prototype.takeDamage) |
| 75 | +//Humanoid.prototype = Object.create(GameObject.prototype) |
| 76 | +Humanoid.prototype.greet = function () { |
| 77 | + console.log(`${this.name} offers a greeting in ${this.language}`) |
| 78 | +} |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
43 | 85 |
|
44 | | -/* |
45 | 86 | const mage = new Humanoid({ |
46 | 87 | createdAt: new Date(), |
47 | 88 | dimensions: { |
|
102 | 143 | console.log(archer.greet()); // Lilith offers a greeting in Elvish. |
103 | 144 | console.log(mage.takeDamage()); // Bruce took damage. |
104 | 145 | console.log(swordsman.destroy()); // Sir Mustachio was removed from the game. |
105 | | -*/ |
| 146 | + |
106 | 147 |
|
107 | 148 | // Stretch task: |
108 | 149 | // * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function. |
|
0 commit comments