From 0070ff0fbb79e9460f5ef2e848e8d6bc1fbf0bae Mon Sep 17 00:00:00 2001 From: Sergio Otero Date: Tue, 21 Oct 2025 20:48:05 +0200 Subject: [PATCH 1/6] feat: iteration 00 completed --- src/viking.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/viking.js b/src/viking.js index 9017bfc8a..fe2f4abc1 100755 --- a/src/viking.js +++ b/src/viking.js @@ -1,5 +1,7 @@ // Soldier -class Soldier {} +class Soldier { + constructor(health, strength) {} +} // Viking class Viking {} From 5a6d09cf953a4c336634c719ee042be9fff4974c Mon Sep 17 00:00:00 2001 From: Sergio Otero Date: Tue, 21 Oct 2025 20:51:13 +0200 Subject: [PATCH 2/6] feat: iteration 01 completed --- src/viking.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/viking.js b/src/viking.js index fe2f4abc1..8b9259832 100755 --- a/src/viking.js +++ b/src/viking.js @@ -1,6 +1,17 @@ // Soldier class Soldier { - constructor(health, strength) {} + constructor(health, strength) { + this.health = health; + this.strength = strength; + } + + attack() { + return this.strength; + } + + receiveDamage(damage) { + this.health - damage; + } } // Viking From 0cfd4b2fd03cf1becd814c458d058df97707be8b Mon Sep 17 00:00:00 2001 From: Sergio Otero Date: Tue, 21 Oct 2025 21:00:31 +0200 Subject: [PATCH 3/6] feat: iteration 02 completed --- src/viking.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/viking.js b/src/viking.js index 8b9259832..77fdfe12a 100755 --- a/src/viking.js +++ b/src/viking.js @@ -10,12 +10,30 @@ class Soldier { } receiveDamage(damage) { - this.health - damage; + this.health = this.health - damage; } } // Viking -class Viking {} +class Viking extends Soldier { + constructor(name, health, strength) { + super(health, strength); + this.name = name; + } + + receiveDamage(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`; + } + } + + battleCry() { + return "Odin Owns You All!"; + } +} // Saxon class Saxon {} From 6230ab1dc112650f829643e107bf3d30d2d53a20 Mon Sep 17 00:00:00 2001 From: Sergio Otero Date: Tue, 21 Oct 2025 21:03:29 +0200 Subject: [PATCH 4/6] feat: iteration 03 completed --- src/viking.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/viking.js b/src/viking.js index 77fdfe12a..6d5a7a7f6 100755 --- a/src/viking.js +++ b/src/viking.js @@ -36,7 +36,17 @@ class Viking extends Soldier { } // Saxon -class Saxon {} +class Saxon extends Soldier{ + + receiveDamage(damage) { + 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 class War {} From d52f1d902c0d5fcec71e81368840fb97b30e57fa Mon Sep 17 00:00:00 2001 From: Sergio Otero Date: Tue, 21 Oct 2025 21:32:03 +0200 Subject: [PATCH 5/6] feat: iteration 04 completed --- src/viking.js | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/viking.js b/src/viking.js index 6d5a7a7f6..08540c6bc 100755 --- a/src/viking.js +++ b/src/viking.js @@ -49,4 +49,52 @@ class Saxon extends Soldier{ } // War -class War {} +class War { + + constructor(){ + this.vikingArmy = []; + this.saxonArmy = []; + } + + addViking(viking) { + this.vikingArmy.push(viking); + } + + addSaxon(saxon) { + this.saxonArmy.push(saxon); + } + + vikingAttack() { + const numRandom = Math.floor(Math.random() * this.saxonArmy.length) + const viking = this.vikingArmy[numRandom]; + const saxon = this.saxonArmy[numRandom]; + const result = saxon.receiveDamage(viking.attack()); + + + if(saxon.health <= 0) { + this.saxonArmy.splice(numRandom, 1); + return result; + } else{ + return result; + } + } + + saxonAttack() { + const numRandom = Math.floor(Math.random() * this.saxonArmy.length) + const viking = this.vikingArmy[numRandom]; + const saxon = this.saxonArmy[numRandom]; + const result = viking.receiveDamage(saxon.attack()); + + + if(viking.health <= 0) { + this.vikingArmy.splice(numRandom, 1); + return result; + } else{ + return result; + } + } + + showStatus() { + + } +} From 5b521d4f6e4d22a75bcb36ca079ba4793bc1fcdc Mon Sep 17 00:00:00 2001 From: Sergio Otero Date: Tue, 21 Oct 2025 21:39:18 +0200 Subject: [PATCH 6/6] feat: iteration 05 (bonus) completed --- src/viking.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/viking.js b/src/viking.js index 08540c6bc..6649feb90 100755 --- a/src/viking.js +++ b/src/viking.js @@ -95,6 +95,12 @@ class War { } showStatus() { - + if(this.saxonArmy.length === 0){ + return "Vikings have won the war of the century!"; + } else if (this.vikingArmy.length === 0){ + return "Saxons have fought for their lives and survived another day..."; + } else if(this.saxonArmy.length > 0 && this.vikingArmy.length > 0) { + return "Vikings and Saxons are still in the thick of battle."; + } } }