Skip to content

Commit ce6196c

Browse files
committed
stretch goal added villian and hero had a battle
1 parent 21505c3 commit ce6196c

1 file changed

Lines changed: 115 additions & 5 deletions

File tree

assignments/prototypes.js

Lines changed: 115 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ CharacterStats.prototype.takeDamage = function () {
6565

6666
//Test you work by uncommenting these 3 objects and the list of console logs below:
6767
function Humanoid(humanoidAttributes){
68-
this.faction = humanoidAttributes.faction;
69-
this.weapons = humanoidAttributes.weapons;
70-
this.language = humanoidAttributes.language;
71-
CharacterStats.call(this,humanoidAttributes);
68+
this.faction = humanoidAttributes.faction;
69+
this.weapons = humanoidAttributes.weapons;
70+
this.language = humanoidAttributes.language;
71+
CharacterStats.call(this,humanoidAttributes);
7272
}
7373

7474
Humanoid.prototype = Object.create(CharacterStats.prototype);
@@ -95,6 +95,7 @@ const mage = new Humanoid({
9595
language: 'Common Toungue',
9696
});
9797

98+
9899
const swordsman = new Humanoid({
99100
createdAt: new Date(),
100101
dimensions: {
@@ -128,8 +129,96 @@ const archer = new Humanoid({
128129
],
129130
language: 'Elvish',
130131
});
132+
// new constructor
133+
function Villian(villianAttributes){
134+
Humanoid.call(this, villianAttributes);
135+
this.badBreath = villianAttributes.badBreath;
136+
this.opponentHealth = villianAttributes.opponentHealth;
137+
}
138+
//inherit
139+
Villian.prototype = Object.create(Humanoid.prototype);
140+
141+
//methods
142+
Villian.prototype.evilLaugh = function () {
143+
this.opponentHealth -= 10;
144+
return `The villian ${this.name} lets out an evil laugh you will fail because I am ${this.name}`;
145+
}
146+
// const failure = new Villian({
147+
// createdAt: new Date(),
148+
// dimensions: {
149+
// length: 1,
150+
// width: 2,
151+
// height: 4,
152+
// },
153+
// hp: 10,
154+
// name: 'Failure',
155+
// faction: 'Forest Kingdom',
156+
// weapons: [
157+
// 'doubt','low confidence'
158+
// ],
159+
// language: 'Marlarkey',
160+
// badBreath: 'Extremely Funky'
161+
// });
162+
163+
function Hero (heroAttributes){
164+
this.goodLooks = heroAttributes.goodlooks;
165+
this.opponentHealth = heroAttributes.opponentHealth;
131166

167+
Humanoid.call(this, heroAttributes);
168+
}
169+
170+
Hero.prototype = Object.create(Humanoid.prototype);
132171

172+
Hero.prototype.studyHard = function () {
173+
this.opponentHealth -=20;
174+
console.log(this.opponent);
175+
return `The hero ${this.name} studies hard`;
176+
}
177+
Hero.prototype.workHard = function () {
178+
this.opponentHealth -=50;
179+
return `The hero ${this.name} works hard`
180+
}
181+
Hero.prototype.flawlessVictory = function() {
182+
this.opponentHealth-= 30;
183+
return `The hero learns to program using his weapons ${this.weapons}... and defeats the villian`;
184+
}
185+
186+
187+
const jonathan = new Hero({
188+
createdAt: new Date(),
189+
dimensions: {
190+
length: 1,
191+
width: 2,
192+
height: 4,
193+
},
194+
hp: 10,
195+
name: 'Jonathan',
196+
faction: 'Forest Kingdom',
197+
weapons: [
198+
'determination', 'work ethic', 'great instructors', 'supporters', 'the list goes on and on...seriously'
199+
],
200+
language: 'JavaScript',
201+
goodLooks: 'High',
202+
opponentHealth: 100
203+
});
204+
205+
failure = new Villian({
206+
createdAt: new Date(),
207+
dimensions: {
208+
length: 1,
209+
width: 2,
210+
height: 4,
211+
},
212+
hp: 10,
213+
name: 'Failure',
214+
faction: 'Forest Kingdom',
215+
weapons: [
216+
'doubt','low confidence'
217+
],
218+
language: 'Marlarkey',
219+
badBreath: 'Extremely Funky',
220+
opponentHealth: 100
221+
});
133222

134223
console.log(mage.createdAt); // Today's date
135224
console.log(archer.dimensions); // { length: 1, width: 2, height: 4 }
@@ -143,7 +232,28 @@ console.log(mage.takeDamage()); // Bruce took damage.
143232
console.log(swordsman.destroy()); // Sir Mustachio was removed from the game.
144233

145234

235+
console.log("A new battle is about to begin")
236+
console.log(`The match ${jonathan.name} vs ${failure.name} has begun.`);
237+
console.log(`The villian has the following weapons ${failure.weapons}`);
238+
console.log(`The hero has the following weapons ${jonathan.weapons}`);
239+
console.log(`The villian has the following extra attribute ${failure.badBreath} breath`);
240+
console.log(`The villian speaks the following language ${failure.language}`);
241+
console.log(`The hero speaks the following language ${jonathan.language}`);
242+
console.log(failure.evilLaugh());
243+
console.log(`${jonathan.name} has been reduced, ${jonathan.name} now has ${failure.opponentHealth}`);
244+
console.log(jonathan.studyHard());
245+
console.log(`${failure.name} has been reduced, ${failure.name} now has ${failure.opponentHealth}`);
246+
console.log(jonathan.workHard());
247+
console.log(`${failure.name} has been reduced, ${failure.name} now has ${jonathan.opponentHealth}`) ;
248+
console.log(jonathan.flawlessVictory());
249+
console.log(`${failure.name} has been reduced, ${jonathan.opponentHealth} now has ${jonathan.opponentHealth}`);
250+
console.log(`${jonathan.name} WINS GETS A NEW JOB WITH HIGH PAY!`);
251+
146252
// Stretch task:
147253
// * Create Villian and Hero constructor functions that inherit from the Humanoid constructor function.
148254
// * Give the Hero and Villians 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;
149-
// * Create two new objects, one a villian and one a hero and fight it out with methods!
255+
// * Create two new objects, one a villian and one a hero and fight it out with methods!
256+
257+
console.log(failure.opponent);
258+
console.log(jonathan.opponent);
259+
this.opponentHealth

0 commit comments

Comments
 (0)