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 9ab9e21
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
-
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
+
At the bottom of this file are 3 objects that all end up inheriting from Humanoid.
8
+
Use the objects at the bottom of the page to test your constructor functions.
7
9
8
10
Each constructor function has unique properties and methods that are defined in their block comments below:
9
11
*/
10
-
12
+
11
13
/*
12
14
=== GameObject ===
13
15
* createdAt
14
16
* name
15
17
* dimensions (These represent the character's size in the video game)
16
18
* destroy() // prototype method that returns: `${this.name} was removed from the game.`
17
19
*/
20
+
functionGameObject(attributes){
21
+
this.createdAt=attributes.createdAt;
22
+
this.name=attributes.name;
23
+
this.dimensions=attributes.dimensions;
24
+
}
25
+
26
+
GameObject.prototype.destroy=function(){
27
+
return`${this.name} was removed from the game.`;
28
+
}
29
+
30
+
letnewGame=newGameObject({
31
+
createdAt: '8th May',
32
+
name: 'pascal',
33
+
dimensions: {
34
+
length: 50,
35
+
widht: 30,
36
+
}
37
+
38
+
});
18
39
19
40
/*
20
41
=== CharacterStats ===
21
42
* healthPoints
22
43
* takeDamage() // prototype method -> returns the string '<object name> took damage.'
23
44
* should inherit destroy() from GameObject's prototype
console.log(archer.greet());// Lilith offers a greeting in Elvish.
171
+
console.log(mage.takeDamage());// Bruce took damage.
172
+
console.log(swordsman.destroy());// Sir Mustachio was removed from the game.
173
+
106
174
107
175
// Stretch task:
108
176
// * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function.
109
177
// * 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!
178
+
// * Create two new objects, one a villain and one a hero and fight it out with methods!
0 commit comments