From a3af569f664ebfc79a12e70530c0b98ea33beba3 Mon Sep 17 00:00:00 2001 From: prrrcl Date: Fri, 28 Jun 2019 17:09:01 +0200 Subject: [PATCH 1/2] Started --- .DS_Store | Bin 0 -> 6148 bytes starter-code/src/viking.js | 20 +- starter-code/tests/VikingSpec.js | 480 +++++++++++++++---------------- 3 files changed, 258 insertions(+), 242 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d8b46e69bcb015abc6d7636ab9e157d54a0ed235 GIT binary patch literal 6148 zcmeHK-D(p-6h4zi-9^P*6zt{P2)&5Xn$S{;u*78TOlHeuzj6#>qBOhlo75#+HxbH>UfwuUN~q zw1L8mF`|@S(1?;@zLL!if1?6=?R+Y+ZV@F|xyAaavp82VdiAfd58wP{3=z>Is;CB| zM46&|PG_XRPlx#u@B3|e@ua$N^Zke~@~o=2wtkA%TKnGp2cGYH{$u|`c&;X49o6G% z5S7Qeb{N&?v5Vg-l`rBbKFZR`NoW1FD(WaJ($bK#Bt^>mcUh6B$v};Zq%z}#w!=(x z(%G0!d%c~m?DhMzuAJ`f>~&@T&qth@3fp&SPW+SOHex&J}PQkN5D-XW|K10aoB&Q$X(z60R|D*jO}M2MY59 z0P1U`F~s`9s5#PM;IOfX9+>hK2D#t5`GHTrt=z$ l3km{r6eCw3#T#&AXqP$w1`ZpGXo2xXz{tP_EAU4ZxCY#haZmsN literal 0 HcmV?d00001 diff --git a/starter-code/src/viking.js b/starter-code/src/viking.js index 46a229138..f0bb1508b 100755 --- a/starter-code/src/viking.js +++ b/starter-code/src/viking.js @@ -1,8 +1,24 @@ // Soldier -function Soldier() {} +function Soldier(health, strength) { + this.health = health; + this.strength = strength; +} +Soldier.prototype.attack = function(){ + console.log('ataqueeee') + return this.strength; + +} +Soldier.prototype.receiveDamage = function(damage){ + console.log('maeshopupa ioeputa'); + this.health = this.health - damage; + +} // Viking -function Viking() {} +function Viking() { + Soldier.call(this); + +} // Saxon function Saxon() {} diff --git a/starter-code/tests/VikingSpec.js b/starter-code/tests/VikingSpec.js index ebaea7cfa..5cfc7c87d 100755 --- a/starter-code/tests/VikingSpec.js +++ b/starter-code/tests/VikingSpec.js @@ -8,50 +8,50 @@ describe("Soldier", function () { }); describe("constructor function", function () { - // it("should receive 2 arguments (health & strength)", function () { - // expect(Soldier.length).toEqual(2); - // }); + it("should receive 2 arguments (health & strength)", function () { + expect(Soldier.length).toEqual(2); + }); - // it("should receive the health property as its 1st argument", function () { - // expect(soldier.health).toEqual(health); - // }); + it("should receive the health property as its 1st argument", function () { + expect(soldier.health).toEqual(health); + }); - // it("should receive the strength property as its 2nd argument", function () { - // expect(soldier.strength).toEqual(strength); - // }); + it("should receive the strength property as its 2nd argument", function () { + expect(soldier.strength).toEqual(strength); + }); }); describe("attack() method", function () { - // it("should be a function", function () { - // expect(typeof(soldier.attack)).toBe("function"); - // }); + it("should be a function", function () { + expect(typeof(soldier.attack)).toBe("function"); + }); - // it("should receive 0 arguments", function () { - // expect(soldier.attack.length).toEqual(0); - // }); + it("should receive 0 arguments", function () { + expect(soldier.attack.length).toEqual(0); + }); - // it("should return the strength property of the Soldier", function () { - // expect(soldier.attack()).toEqual(strength); - // }); + it("should return the strength property of the Soldier", function () { + expect(soldier.attack()).toEqual(strength); + }); }); describe("receiveDamage() method", function () { - // it("should be a function", function () { - // expect(typeof(soldier.receiveDamage)).toBe("function"); - // }); - - // it("should receive 1 argument (the damage)", function () { - // expect(soldier.receiveDamage.length).toEqual(1); - // }); - - // it("should remove the received damage from the health property", function () { - // soldier.receiveDamage(50); - // expect(soldier.health).toEqual(health - 50); - // }); - - // it("shouldn't return anything", function () { - // expect(soldier.receiveDamage(50)).toEqual(undefined); - // }); + it("should be a function", function () { + expect(typeof(soldier.receiveDamage)).toBe("function"); + }); + + it("should receive 1 argument (the damage)", function () { + expect(soldier.receiveDamage.length).toEqual(1); + }); + + it("should remove the received damage from the health property", function () { + soldier.receiveDamage(50); + expect(soldier.health).toEqual(health - 50); + }); + + it("shouldn't return anything", function () { + expect(soldier.receiveDamage(50)).toEqual(undefined); + }); }); }); @@ -66,78 +66,78 @@ describe("Viking", function () { viking = new Viking(name, health, strength); }); - // it("should inherit from Soldier", function () { - // expect(viking instanceof Soldier).toEqual(true); - // }); + it("should inherit from Soldier", function () { + expect(viking instanceof Soldier).toEqual(true); + }); describe("constructor function", function () { - // it("should receive 3 arguments (name, health & strength)", function () { - // expect(Viking.length).toEqual(3); - // }); + it("should receive 3 arguments (name, health & strength)", function () { + expect(Viking.length).toEqual(3); + }); - // it("should receive the name property as its 1st argument", function () { - // expect(viking.name).toEqual(name); - // }); + it("should receive the name property as its 1st argument", function () { + expect(viking.name).toEqual(name); + }); - // it("should receive the health property as its 2nd argument", function () { - // expect(viking.health).toEqual(health); - // }); + it("should receive the health property as its 2nd argument", function () { + expect(viking.health).toEqual(health); + }); - // it("should receive the strength property as its 3rd argument", function () { - // expect(viking.strength).toEqual(strength); - // }); + it("should receive the strength property as its 3rd argument", function () { + expect(viking.strength).toEqual(strength); + }); }); describe("attack() method", function () { - // it("should be a function", function () { - // expect(typeof(viking.attack)).toBe("function"); - // }); + it("should be a function", function () { + expect(typeof(viking.attack)).toBe("function"); + }); - // it("should receive 0 arguments", function () { - // expect(viking.attack.length).toEqual(0); - // }); + it("should receive 0 arguments", function () { + expect(viking.attack.length).toEqual(0); + }); - // it("should return the strength property of the Viking", function () { - // expect(viking.attack()).toEqual(strength); - // }); + it("should return the strength property of the Viking", function () { + expect(viking.attack()).toEqual(strength); + }); }); describe("receiveDamage() method", function () { - // it("should be a function", function () { - // expect(typeof(viking.receiveDamage)).toBe("function"); - // }); - - // it("should receive 1 argument (the damage)", function () { - // expect(viking.receiveDamage.length).toEqual(1); - // }); - - // it("should remove the received damage from the health property", function () { - // viking.receiveDamage(50); - // expect(viking.health).toEqual(health - 50); - // }); - - // it("should return \"NAME has received DAMAGE points of damage\", if the Viking is still alive", function () { - // expect(viking.receiveDamage(50)).toEqual(name + " has received 50 points of damage"); - // expect(viking.receiveDamage(75)).toEqual(name + " has received 75 points of damage"); - // }); - - // it("should return \"NAME has died in act of combat\", if the Viking dies", function () { - // expect(viking.receiveDamage(health)).toEqual(name + " has died in act of combat"); - // }); + it("should be a function", function () { + expect(typeof(viking.receiveDamage)).toBe("function"); + }); + + it("should receive 1 argument (the damage)", function () { + expect(viking.receiveDamage.length).toEqual(1); + }); + + it("should remove the received damage from the health property", function () { + viking.receiveDamage(50); + expect(viking.health).toEqual(health - 50); + }); + + it("should return \"NAME has received DAMAGE points of damage\", if the Viking is still alive", function () { + expect(viking.receiveDamage(50)).toEqual(name + " has received 50 points of damage"); + expect(viking.receiveDamage(75)).toEqual(name + " has received 75 points of damage"); + }); + + it("should return \"NAME has died in act of combat\", if the Viking dies", function () { + expect(viking.receiveDamage(health)).toEqual(name + " has died in act of combat"); + }); }); describe("battleCry() method", function () { - // it("should be a function", function () { - // expect(typeof(viking.battleCry)).toBe("function"); - // }); + it("should be a function", function () { + expect(typeof(viking.battleCry)).toBe("function"); + }); - // it("should receive 0 arguments", function () { - // expect(viking.battleCry.length).toEqual(0); - // }); + it("should receive 0 arguments", function () { + expect(viking.battleCry.length).toEqual(0); + }); - // it("should return \"Odin Owns You All!\"", function () { - // expect(viking.battleCry()).toEqual("Odin Owns You All!"); - // }); + it("should return \"Odin Owns You All!\"", function () { + expect(viking.battleCry()).toEqual("Odin Owns You All!"); + }); }); }); @@ -151,60 +151,60 @@ describe("Saxon", function () { saxon = new Saxon(health, strength); }); - // it("should inherit from Soldier", function () { - // expect(saxon instanceof Soldier).toEqual(true); - // }); + it("should inherit from Soldier", function () { + expect(saxon instanceof Soldier).toEqual(true); + }); describe("constructor function", function () { - // it("should receive 2 arguments (health & strength)", function () { - // expect(Saxon.length).toEqual(2); - // }); + it("should receive 2 arguments (health & strength)", function () { + expect(Saxon.length).toEqual(2); + }); - // it("should receive the health property as its 1st argument", function () { - // expect(saxon.health).toEqual(health); - // }); + it("should receive the health property as its 1st argument", function () { + expect(saxon.health).toEqual(health); + }); - // it("should receive the strength property as its 2nd argument", function () { - // expect(saxon.strength).toEqual(strength); - // }); + it("should receive the strength property as its 2nd argument", function () { + expect(saxon.strength).toEqual(strength); + }); }); describe("attack() method", function () { - // it("should be a function", function () { - // expect(typeof(saxon.attack)).toBe("function"); - // }); + it("should be a function", function () { + expect(typeof(saxon.attack)).toBe("function"); + }); - // it("should receive 0 arguments", function () { - // expect(saxon.attack.length).toEqual(0); - // }); + it("should receive 0 arguments", function () { + expect(saxon.attack.length).toEqual(0); + }); - // it("should return the strength property of the Saxon", function () { - // expect(saxon.attack()).toEqual(strength); - // }); + it("should return the strength property of the Saxon", function () { + expect(saxon.attack()).toEqual(strength); + }); }); describe("receiveDamage() method", function () { - // it("should be a function", function () { - // expect(typeof(saxon.receiveDamage)).toBe("function"); - // }); - - // it("should receive 1 argument (the damage)", function () { - // expect(saxon.receiveDamage.length).toEqual(1); - // }); - - // it("should remove the received damage from the health property", function () { - // saxon.receiveDamage(50); - // expect(saxon.health).toEqual(health - 50); - // }); - - // it("should return \"A Saxon has received DAMAGE points of damage\", if the Saxon is still alive", function () { - // expect(saxon.receiveDamage(45)).toEqual("A Saxon has received 45 points of damage"); - // expect(saxon.receiveDamage(10)).toEqual("A Saxon has received 10 points of damage"); - // }); - - // it("should return \"A Saxon has died in combat\", if the Saxon dies", function () { - // expect(saxon.receiveDamage(health)).toEqual("A Saxon has died in combat"); - // }); + it("should be a function", function () { + expect(typeof(saxon.receiveDamage)).toBe("function"); + }); + + it("should receive 1 argument (the damage)", function () { + expect(saxon.receiveDamage.length).toEqual(1); + }); + + it("should remove the received damage from the health property", function () { + saxon.receiveDamage(50); + expect(saxon.health).toEqual(health - 50); + }); + + it("should return \"A Saxon has received DAMAGE points of damage\", if the Saxon is still alive", function () { + expect(saxon.receiveDamage(45)).toEqual("A Saxon has received 45 points of damage"); + expect(saxon.receiveDamage(10)).toEqual("A Saxon has received 10 points of damage"); + }); + + it("should return \"A Saxon has died in combat\", if the Saxon dies", function () { + expect(saxon.receiveDamage(health)).toEqual("A Saxon has died in combat"); + }); }); }); @@ -234,55 +234,55 @@ describe("War", function () { }); describe("constructor function", function () { - // it("should receive 0 arguments", function () { - // expect(War.length).toEqual(0); - // }); + it("should receive 0 arguments", function () { + expect(War.length).toEqual(0); + }); - // it("should assign an empty array to the vikingArmy property", function () { - // expect(war.vikingArmy).toEqual([]); - // }); + it("should assign an empty array to the vikingArmy property", function () { + expect(war.vikingArmy).toEqual([]); + }); - // it("should assign an empty array to the saxonArmy property", function () { - // expect(war.saxonArmy).toEqual([]); - // }); + it("should assign an empty array to the saxonArmy property", function () { + expect(war.saxonArmy).toEqual([]); + }); }); describe("addViking() method", function () { - // it("should be a function", function () { - // expect(typeof(war.addViking)).toBe("function"); - // }); - - // it("should receive 1 argument (a Viking object)", function () { - // expect(war.addViking.length).toEqual(1); - // }); - - // it("should add the received Viking to the army", function () { - // war.addViking(viking); - // expect(war.vikingArmy).toEqual([ viking ]); - // }); - - // it("shouldn't return anything", function () { - // expect(war.addViking(viking)).toEqual(undefined); - // }); + it("should be a function", function () { + expect(typeof(war.addViking)).toBe("function"); + }); + + it("should receive 1 argument (a Viking object)", function () { + expect(war.addViking.length).toEqual(1); + }); + + it("should add the received Viking to the army", function () { + war.addViking(viking); + expect(war.vikingArmy).toEqual([ viking ]); + }); + + it("shouldn't return anything", function () { + expect(war.addViking(viking)).toEqual(undefined); + }); }); describe("addSaxon() method", function () { - // it("should be a function", function () { - // expect(typeof(war.addSaxon)).toBe("function"); - // }); - - // it("should receive 1 argument (a Saxon object)", function () { - // expect(war.addSaxon.length).toEqual(1); - // }); - - // it("should add the received Saxon to the army", function () { - // war.addSaxon(saxon); - // expect(war.saxonArmy).toEqual([ saxon ]); - // }); - - // it("shouldn't return anything", function () { - // expect(war.addSaxon(saxon)).toEqual(undefined); - // }); + it("should be a function", function () { + expect(typeof(war.addSaxon)).toBe("function"); + }); + + it("should receive 1 argument (a Saxon object)", function () { + expect(war.addSaxon.length).toEqual(1); + }); + + it("should add the received Saxon to the army", function () { + war.addSaxon(saxon); + expect(war.saxonArmy).toEqual([ saxon ]); + }); + + it("shouldn't return anything", function () { + expect(war.addSaxon(saxon)).toEqual(undefined); + }); }); describe("Armies Attack", function () { @@ -292,81 +292,81 @@ describe("War", function () { }); describe("vikingAttack() method", function () { - // it("should be a function", function () { - // expect(typeof(war.vikingAttack)).toBe("function"); - // }); - - // it("should receive 0 arguments", function () { - // expect(war.vikingAttack.length).toEqual(0); - // }); - - // it("should make Saxon receiveDamage() equal to the strength of a Viking", function () { - // var oldHealth = saxon.health; - // war.vikingAttack(); - // expect(saxon.health).toEqual(oldHealth - viking.strength); - // }); - - // it("should remove dead saxons from the army", function () { - // war.vikingAttack(); - // expect(war.saxonArmy.length).toEqual(0); - // }); - - // it("should return result of calling receiveDamage() of a Saxon with the strength of a Viking", function () { - // expect(war.vikingAttack()).toEqual("A Saxon has died in combat"); - // }); + it("should be a function", function () { + expect(typeof(war.vikingAttack)).toBe("function"); + }); + + it("should receive 0 arguments", function () { + expect(war.vikingAttack.length).toEqual(0); + }); + + it("should make Saxon receiveDamage() equal to the strength of a Viking", function () { + var oldHealth = saxon.health; + war.vikingAttack(); + expect(saxon.health).toEqual(oldHealth - viking.strength); + }); + + it("should remove dead saxons from the army", function () { + war.vikingAttack(); + expect(war.saxonArmy.length).toEqual(0); + }); + + it("should return result of calling receiveDamage() of a Saxon with the strength of a Viking", function () { + expect(war.vikingAttack()).toEqual("A Saxon has died in combat"); + }); }); describe("saxonAttack() method", function () { - // it("should be a function", function () { - // expect(typeof(war.saxonAttack)).toBe("function"); - // }); - - // it("should receive 0 arguments", function () { - // expect(war.saxonAttack.length).toEqual(0); - // }); - - // it("should make a Viking receiveDamage() equal to the strength of a Saxon", function () { - // var oldHealth = viking.health; - // war.saxonAttack(); - // expect(viking.health).toEqual(oldHealth - saxon.strength); - // }); - - // it("should remove dead vikings from the army", function () { - // for (var i = 0; i < 12; i += 1) { - // war.saxonAttack(); - // } - // expect(war.vikingArmy.length).toEqual(0); - // }); - - // it("should return result of calling receiveDamage() of a Viking with the strength of a Saxon", function () { - // expect(war.saxonAttack()).toEqual(viking.name + " has received " + saxon.strength + " points of damage"); - // }); + it("should be a function", function () { + expect(typeof(war.saxonAttack)).toBe("function"); + }); + + it("should receive 0 arguments", function () { + expect(war.saxonAttack.length).toEqual(0); + }); + + it("should make a Viking receiveDamage() equal to the strength of a Saxon", function () { + var oldHealth = viking.health; + war.saxonAttack(); + expect(viking.health).toEqual(oldHealth - saxon.strength); + }); + + it("should remove dead vikings from the army", function () { + for (var i = 0; i < 12; i += 1) { + war.saxonAttack(); + } + expect(war.vikingArmy.length).toEqual(0); + }); + + it("should return result of calling receiveDamage() of a Viking with the strength of a Saxon", function () { + expect(war.saxonAttack()).toEqual(viking.name + " has received " + saxon.strength + " points of damage"); + }); }); describe("showStatus() method", function () { - // it("should be a function", function () { - // expect(typeof(war.showStatus)).toBe("function"); - // }); - - // it("should receive 0 arguments", function () { - // expect(war.showStatus.length).toEqual(0); - // }); - - // it("should return \"Vikings have won the war of the century!\", if the Saxons array is empty", function () { - // war.vikingAttack(); - // expect(war.showStatus()).toEqual("Vikings have won the war of the century!"); - // }); - - // it("should return \"Saxons have fought for their lives and survive another day...\", if the Vikings array is empty", function () { - // for (var i = 0; i < 12; i += 1) { - // war.saxonAttack(); - // } - // expect(war.showStatus()).toEqual("Saxons have fought for their lives and survive another day..."); - // }); - - // it("should return \"Vikings and Saxons are still in the thick of battle.\", if there are still both Vikings and Saxons", function () { - // expect(war.showStatus()).toEqual("Vikings and Saxons are still in the thick of battle."); - // }); + it("should be a function", function () { + expect(typeof(war.showStatus)).toBe("function"); + }); + + it("should receive 0 arguments", function () { + expect(war.showStatus.length).toEqual(0); + }); + + it("should return \"Vikings have won the war of the century!\", if the Saxons array is empty", function () { + war.vikingAttack(); + expect(war.showStatus()).toEqual("Vikings have won the war of the century!"); + }); + + it("should return \"Saxons have fought for their lives and survive another day...\", if the Vikings array is empty", function () { + for (var i = 0; i < 12; i += 1) { + war.saxonAttack(); + } + expect(war.showStatus()).toEqual("Saxons have fought for their lives and survive another day..."); + }); + + it("should return \"Vikings and Saxons are still in the thick of battle.\", if there are still both Vikings and Saxons", function () { + expect(war.showStatus()).toEqual("Vikings and Saxons are still in the thick of battle."); + }); }); }); }); From cc1d74f201533671d9cc41ae4c92844a3575556f Mon Sep 17 00:00:00 2001 From: prrrcl Date: Fri, 28 Jun 2019 20:12:37 +0200 Subject: [PATCH 2/2] BCN-FT-JAN-ADRI --- starter-code/src/viking.js | 109 +++++++++++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 5 deletions(-) diff --git a/starter-code/src/viking.js b/starter-code/src/viking.js index f0bb1508b..4380b2855 100755 --- a/starter-code/src/viking.js +++ b/starter-code/src/viking.js @@ -10,18 +10,117 @@ Soldier.prototype.attack = function(){ } Soldier.prototype.receiveDamage = function(damage){ console.log('maeshopupa ioeputa'); + this.health = this.health - damage; - + } // Viking -function Viking() { +function Viking(name, health, strength) { + Soldier.call(this); - + + this.name = name; + this.health = health; + this.strength = strength; + +} +Viking.prototype = Object.create(Soldier.prototype); +Viking.prototype.constructor = Viking; + +Viking.prototype.receiveDamage = function(damage){ + this.health = this.health - damage; + if(this.health > 0){ + return this.name + ' has received '+ damage +' points of damage'; + }else{ + return this.name + ' has died in act of combat'; + } +} +Viking.prototype.battleCry = function(){ + return 'Odin Owns You All!'; } // Saxon -function Saxon() {} +function Saxon(health, strength) { + Soldier.call(this); + this.health = health; + this.strength = strength; +} +Saxon.prototype = Object.create(Soldier.prototype); +Saxon.prototype.constructor = Saxon; + +Saxon.prototype.receiveDamage = function(damage){ + console.log('maeshopupa ioeputa'); + this.health = this.health - damage; + if (this.health > 0){ + return 'A Saxon has received '+ damage +' points of damage' + }else{ + return 'A Saxon has died in combat' + } +} // War -function War() {} +function War() { + + this.vikingArmy = []; + this.saxonArmy = []; + + War.prototype.addViking = function(viking){ + this.vikingArmy.push(viking); + }; + + War.prototype.addSaxon = function(saxon){ + this.saxonArmy.push(saxon); + } + + War.prototype.vikingAttack = function(){ + + function randomize(maximum){ + return Math.floor(Math.random() * maximum) + } + this.randomNumSaxon = randomize(this.saxonArmy.length); + this.saxon = this.saxonArmy[this.randomNumSaxon]; + this.randomNumViking = randomize(this.vikingArmy.length); + this.viking = this.vikingArmy[this.randomNumViking]; + + this.damaged = this.saxon.receiveDamage(this.viking.strength); + + if(this.saxon.health <= 0){ + this.saxonArmy.splice(this.randomNumSaxon,1); + } + + return this.damaged; + + } + + + War.prototype.saxonAttack = function(){ + + function randomize(maximum){ + return Math.floor(Math.random() * maximum) + } + this.randomNumSaxon = randomize(this.saxonArmy.length); + this.saxon = this.saxonArmy[this.randomNumSaxon]; + this.randomNumViking = randomize(this.vikingArmy.length); + this.viking = this.vikingArmy[this.randomNumViking]; + + this.damaged = this.viking.receiveDamage(this.saxon.strength); + + if(this.viking.health <= 0){ + this.vikingArmy.splice(this.randomNumSaxon,1); + } + + return this.damaged; + + } + + War.prototype.showStatus = function(){ + if(this.saxonArmy.length === 0){ + return 'Vikings have won the war of the century!'; + }; + if(this.vikingArmy.length === 0){ + return 'Saxons have fought for their lives and survive another day...'; + }; + return 'Vikings and Saxons are still in the thick of battle.'; + }; +};