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
Copy file name to clipboardExpand all lines: assignments/prototype-refactor.js
+194Lines changed: 194 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -7,3 +7,197 @@ Prototype Refactor
7
7
2. Your goal is to refactor all of this code to use ES6 Classes. The console.log() statements should still return what is expected of them.
8
8
9
9
*/
10
+
11
+
12
+
13
+
14
+
/*
15
+
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.
16
+
17
+
In this file you will be creating three constructor functions: GameObject, CharacterStats, Humanoid.
18
+
19
+
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.
20
+
21
+
Each constructor function has unique properties and methods that are defined in their block comments below:
22
+
*/
23
+
24
+
25
+
// Notes:
26
+
// GameObject -> CharacterStats -> Humanoid
27
+
28
+
29
+
30
+
31
+
// === GameObject ===
32
+
33
+
// function GameObject(GameObj) {
34
+
// this.createdAt = GameObj.createdAt;
35
+
// this.name = GameObj.name;
36
+
// this.dimensions = GameObj.dimensions; // (These represent the character's size in the video game)
37
+
// };
38
+
39
+
40
+
// GameObject Object Refactored:
41
+
42
+
classGameObject{
43
+
constructor(GameObj){
44
+
this.createdAt=GameObj.createdAt;
45
+
this.name=GameObj.name;
46
+
this.dimensions=GameObj.dimensions;
47
+
}
48
+
49
+
50
+
51
+
// GameObject.prototype.destroy = function() {
52
+
// return `${this.name} was removed from the game.`; // prototype method that returns: `${this.name} was removed from the game.`
console.log(archer.greet());// Lilith offers a greeting in Elvish.
196
+
console.log(mage.takeDamage());// Bruce took damage.
197
+
console.log(swordsman.destroy());// Sir Mustachio was removed from the game.
198
+
199
+
200
+
// Stretch task:
201
+
// * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function.
202
+
// * 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;
203
+
// * Create two new objects, one a villain and one a hero and fight it out with methods!
0 commit comments