You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8c3761b
Browse filesBrowse the repository at this point in the historyBrowse files
Object oriented design is commonly used in video games. For this part of the assignment you will be implementing several constructor functions with their correct inheritance hierarchy.
2
+
Object oriented design is commonly used in video games.
3
+
For this part of the assignment you will be implementing several constructor functions with their correct inheritance hierarchy.
3
4
4
5
In this file you will be creating three constructor functions: GameObject, CharacterStats, Humanoid.
5
6
6
7
At the bottom of this file are 3 objects that all end up inheriting from Humanoid. Use the objects at the bottom of the page to test your constructor functions.
7
8
8
9
Each constructor function has unique properties and methods that are defined in their block comments below:
9
10
*/
10
-
11
+
11
12
/*
12
13
=== GameObject ===
13
14
* createdAt
@@ -32,79 +33,165 @@
32
33
* should inherit destroy() from GameObject through CharacterStats
console.log(archer.greet());// Lilith offers a greeting in Elvish.
129
+
console.log(mage.takeDamage());// Bruce took damage.
130
+
console.log(swordsman.destroy());// Sir Mustachio was removed from the game.
131
+
132
+
// Stretch task:
133
+
// * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function.
134
+
// * Give the Hero and Villains different methods that could be used to remove health points from objects which could result in destruction if health gets to 0 or drops below 0;
135
+
// * Create two new objects, one a villain and one a hero and fight it out with methods!
136
+
137
+
functionHero(heroObj){
138
+
Humanoid.call(this,heroObj);
139
+
this.dmg=heroObj.dmg;
140
+
}
141
+
142
+
Hero.prototype=Object.create(Humanoid.prototype);
143
+
144
+
Hero.prototype.hit=function(enemy){
145
+
enemy.healthPoints=enemy.healthPoints-this.dmg;
146
+
letleftHealthMessage="";
147
+
if(enemy.healthPoints<=0){
148
+
enemy.healthPoints=0;
149
+
leftHealthMessage="Now it's dead.";
150
+
}else{
151
+
leftHealthMessage=`Now ${enemy.name} has ${enemy.healthPoints} health.`;
152
+
}
153
+
return`${this.name} hit ${this.dmg} damage to ${enemy.name}. ${leftHealthMessage}`;
154
+
};
155
+
156
+
functionVillain(villainObj){
157
+
Hero.call(this,villainObj);
158
+
}
159
+
160
+
Villain.prototype=Object.create(Hero.prototype);
161
+
162
+
constpudge=newHero({
163
+
createdAt: newDate(),
164
+
dimensions: {
165
+
length: 1,
166
+
width: 2,
167
+
height: 4
168
+
},
169
+
healthPoints: 100,
170
+
name: "Pudge",
171
+
team: "Radiant",
172
+
weapons: ["Hook","Dismember"],
173
+
language: "Butcherish",
174
+
dmg: 20
175
+
});
176
+
177
+
constsniper=newVillain({
178
+
createdAt: newDate(),
179
+
dimensions: {
180
+
length: 1,
181
+
width: 2,
182
+
height: 2
183
+
},
184
+
healthPoints: 75,
185
+
name: "Sniper",
186
+
team: "Dire",
187
+
weapons: ["Rifle","Sharapnel"],
188
+
language: "Sniperish",
189
+
dmg: 30
190
+
});
106
191
107
-
// Stretch task:
108
-
// * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function.
109
-
// * Give the Hero and Villains different methods that could be used to remove health points from objects which could result in destruction if health gets to 0 or drops below 0;
110
-
// * Create two new objects, one a villain and one a hero and fight it out with methods!
0 commit comments