|
15 | 15 | * destroy() // prototype method -> returns the string: 'Object was removed from the game.' |
16 | 16 | */ |
17 | 17 |
|
| 18 | +GameObject.prototype = Object.create(Humanoid.prototype); |
| 19 | +function GameObject(gameobjectbutes){ |
| 20 | + this.createdAt = gameobjectbutes.createdAt; |
| 21 | + this.dimensions = gameobjectbutes.dimensions; |
| 22 | + //CharacterStats.call(this, gameobjectbutes); |
| 23 | + Humanoid.call(this, gameobjectbutes); |
| 24 | +} |
| 25 | + |
| 26 | +GameObject.prototype.destroy = function(){ |
| 27 | + return `Object was removed from the game.` |
| 28 | +} |
| 29 | + |
| 30 | + |
18 | 31 | /* |
19 | 32 | === CharacterStats === |
20 | 33 | * healthPoints |
|
23 | 36 | * should inherit destroy() from GameObject's prototype |
24 | 37 | */ |
25 | 38 |
|
| 39 | +CharacterStats.prototype = Object.create(Humanoid.prototype); |
| 40 | +function CharacterStats(characterbutes){ |
| 41 | + //Humanoid.call(this, characterbutes); |
| 42 | + GameObject.call(this, characterbutes); |
| 43 | + this.healthPoints = characterbutes.healthPoints; |
| 44 | + this.name = characterbutes.name; |
| 45 | +} |
| 46 | + |
| 47 | + |
| 48 | +CharacterStats.prototype.takeDamage = function(){ |
| 49 | + return `${this.name} took damage.`; |
| 50 | +} |
| 51 | + |
26 | 52 | /* |
27 | 53 | === Humanoid (Having an appearance or character resembling that of a human.) === |
28 | 54 | * team |
|
32 | 58 | * should inherit destroy() from GameObject through CharacterStats |
33 | 59 | * should inherit takeDamage() from CharacterStats |
34 | 60 | */ |
35 | | - |
| 61 | +function Humanoid(attributes) { |
| 62 | + //CharacterStats.call(this, attributes); |
| 63 | + //GameObject.call(this, attributes); |
| 64 | + this.team = attributes.team; |
| 65 | + this.weapons = attributes.weapons; |
| 66 | + this.language = attributes.language; |
| 67 | +} |
| 68 | +Humanoid.prototype.great = function(){ |
| 69 | + return `${this.team} says hello in ${this.language}`; |
| 70 | + } |
| 71 | + |
36 | 72 | /* |
37 | 73 | * Inheritance chain: GameObject -> CharacterStats -> Humanoid |
38 | 74 | * Instances of Humanoid should have all of the same properties as CharacterStats and GameObject. |
|
41 | 77 |
|
42 | 78 | // Test you work by un-commenting these 3 objects and the list of console logs below: |
43 | 79 |
|
44 | | -/* |
| 80 | + |
45 | 81 | const mage = new Humanoid({ |
46 | | - createdAt: new Date(), |
| 82 | + createdAt: Date.now(), |
47 | 83 | dimensions: { |
48 | 84 | length: 2, |
49 | 85 | width: 1, |
|
58 | 94 | language: 'Common Tongue', |
59 | 95 | }); |
60 | 96 |
|
| 97 | + console.log(mage); |
| 98 | + |
61 | 99 | const swordsman = new Humanoid({ |
62 | | - createdAt: new Date(), |
| 100 | + createdAt: Date.now(), |
63 | 101 | dimensions: { |
64 | 102 | length: 2, |
65 | 103 | width: 2, |
|
76 | 114 | }); |
77 | 115 |
|
78 | 116 | const archer = new Humanoid({ |
79 | | - createdAt: new Date(), |
| 117 | + createdAt: Date.now(), |
80 | 118 | dimensions: { |
81 | 119 | length: 1, |
82 | 120 | width: 2, |
|
91 | 129 | ], |
92 | 130 | language: 'Elvish', |
93 | 131 | }); |
| 132 | + |
| 133 | + |
| 134 | + // console.log(mage.createdAt); // Today's date |
| 135 | + // console.log(archer.dimensions); // { length: 1, width: 2, height: 4 } |
| 136 | + // console.log(swordsman.healthPoints); // 15 |
| 137 | + // console.log(mage.name); // Bruce |
| 138 | + // console.log(swordsman.team); // The Round Table |
| 139 | + // console.log(mage.weapons); // Staff of Shamalama |
| 140 | + // console.log(archer.language); // Elvish |
| 141 | + // console.log(archer.great()); // Lilith offers a greeting in Elvish. |
| 142 | + // console.log(mage.takeDamage()); // Bruce took damage. |
| 143 | + // console.log(swordsman.destroy()); // Sir Mustachio was removed from the game. |
94 | 144 |
|
95 | | - console.log(mage.createdAt); // Today's date |
96 | | - console.log(archer.dimensions); // { length: 1, width: 2, height: 4 } |
97 | | - console.log(swordsman.healthPoints); // 15 |
98 | | - console.log(mage.name); // Bruce |
99 | | - console.log(swordsman.team); // The Round Table |
100 | | - console.log(mage.weapons); // Staff of Shamalama |
101 | | - console.log(archer.language); // Elvish |
102 | | - console.log(archer.greet()); // Lilith offers a greeting in Elvish. |
103 | | - console.log(mage.takeDamage()); // Bruce took damage. |
104 | | - console.log(swordsman.destroy()); // Sir Mustachio was removed from the game. |
105 | | -*/ |
106 | 145 |
|
107 | 146 | // Stretch task: |
108 | 147 | // * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function. |
|
0 commit comments