Skip to content

Commit 83ac772

Browse files
author
littleknightgames
committed
ELANNNNNNNNNNNNN Sorry aman
1 parent 33d1564 commit 83ac772

1 file changed

Lines changed: 93 additions & 75 deletions

File tree

‎assignments/prototypes.js‎

Lines changed: 93 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*
22
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.
33
4-
In this file you will be creating three constructor functions: GameObject, CharacterStats, Humanoid.
4+
In this file you will be creating three constructor functions: GameObject, CharacterStats, Humanoid.
55
66
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-
7+
88
Each constructor function has unique properties and methods that are defined in their block comments below:
99
*/
10-
10+
1111
/*
1212
=== GameObject ===
1313
* createdAt
@@ -32,79 +32,97 @@
3232
* should inherit destroy() from GameObject through CharacterStats
3333
* should inherit takeDamage() from CharacterStats
3434
*/
35-
35+
3636
/*
37-
* Inheritance chain: GameObject -> CharacterStats -> Humanoid
38-
* Instances of Humanoid should have all of the same properties as CharacterStats and GameObject.
39-
* Instances of CharacterStats should have all of the same properties as GameObject.
40-
*/
37+
* Inheritance chain: GameObject -> CharacterStats -> Humanoid
38+
* Instances of Humanoid should have all of the same properties as CharacterStats and GameObject.
39+
* Instances of CharacterStats should have all of the same properties as GameObject.
40+
*/
4141

42-
// Test you work by un-commenting these 3 objects and the list of console logs below:
42+
// Test you work by un-commenting these 3 objects and the list of console logs below
4343

44-
/*
45-
const mage = new Humanoid({
46-
createdAt: new Date(),
47-
dimensions: {
48-
length: 2,
49-
width: 1,
50-
height: 1,
51-
},
52-
healthPoints: 5,
53-
name: 'Bruce',
54-
team: 'Mage Guild',
55-
weapons: [
56-
'Staff of Shamalama',
57-
],
58-
language: 'Common Tongue',
59-
});
60-
61-
const swordsman = new Humanoid({
62-
createdAt: new Date(),
63-
dimensions: {
64-
length: 2,
65-
width: 2,
66-
height: 2,
67-
},
68-
healthPoints: 15,
69-
name: 'Sir Mustachio',
70-
team: 'The Round Table',
71-
weapons: [
72-
'Giant Sword',
73-
'Shield',
74-
],
75-
language: 'Common Tongue',
76-
});
77-
78-
const archer = new Humanoid({
79-
createdAt: new Date(),
80-
dimensions: {
81-
length: 1,
82-
width: 2,
83-
height: 4,
84-
},
85-
healthPoints: 10,
86-
name: 'Lilith',
87-
team: 'Forest Kingdom',
88-
weapons: [
89-
'Bow',
90-
'Dagger',
91-
],
92-
language: 'Elvish',
93-
});
94-
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-
*/
44+
const GameObject = {
45+
createdAt: "",
46+
name: "",
47+
dimensions: "",
48+
destroy: function() {
49+
return `${this.name} was removed from the game.`;
50+
}
51+
};
52+
53+
const CharacterStats = {
54+
healthPoints: 100,
55+
takeDamage: function() {
56+
return "<object name> took damage.";
57+
},
58+
destroy: Object.create(GameObject.destroy())
59+
};
60+
61+
const Humanoid = {
62+
team: "",
63+
weapons: "",
64+
language: "",
65+
greet: function() {
66+
return "<object name> offers a greeting in <object language>.";
67+
},
68+
destroy: Object.create(CharacterStats.destroy()),
69+
takeDamage: Object.create(CharacterStats.takeDamage())
70+
};
71+
72+
const mage = new Humanoid({
73+
createdAt: new Date(),
74+
dimensions: {
75+
length: 2,
76+
width: 1,
77+
height: 1
78+
},
79+
healthPoints: 5,
80+
name: "Bruce",
81+
team: "Mage Guild",
82+
weapons: ["Staff of Shamalama"],
83+
language: "Common Tongue"
84+
});
85+
86+
const swordsman = new Humanoid({
87+
createdAt: new Date(),
88+
dimensions: {
89+
length: 2,
90+
width: 2,
91+
height: 2
92+
},
93+
healthPoints: 15,
94+
name: "Sir Mustachio",
95+
team: "The Round Table",
96+
weapons: ["Giant Sword", "Shield"],
97+
language: "Common Tongue"
98+
});
99+
100+
const archer = new Humanoid({
101+
createdAt: new Date(),
102+
dimensions: {
103+
length: 1,
104+
width: 2,
105+
height: 4
106+
},
107+
healthPoints: 10,
108+
name: "Lilith",
109+
team: "Forest Kingdom",
110+
weapons: ["Bow", "Dagger"],
111+
language: "Elvish"
112+
});
113+
114+
console.log(mage.createdAt); // Today's date
115+
console.log(archer.dimensions); // { length: 1, width: 2, height: 4 }
116+
console.log(swordsman.healthPoints); // 15
117+
console.log(mage.name); // Bruce
118+
console.log(swordsman.team); // The Round Table
119+
console.log(mage.weapons); // Staff of Shamalama
120+
console.log(archer.language); // Elvish
121+
console.log(archer.greet()); // Lilith offers a greeting in Elvish.
122+
console.log(mage.takeDamage()); // Bruce took damage.
123+
console.log(swordsman.destroy()); // Sir Mustachio was removed from the game.
106124

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!
125+
// Stretch task:
126+
// * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function.
127+
// * 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;
128+
// * Create two new objects, one a villain and one a hero and fight it out with methods!

0 commit comments

Comments
 (0)