From a0a2eedf4c14f3b46fff20e6d7b947381fac641c Mon Sep 17 00:00:00 2001 From: SiyaM108 Date: Sat, 13 Sep 2025 09:33:55 +0100 Subject: [PATCH 1/6] complete iteration 0 --- src/viking.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/viking.js b/src/viking.js index fe1febf..cea0da8 100644 --- a/src/viking.js +++ b/src/viking.js @@ -1,5 +1,10 @@ // Soldier -class Soldier {} +class Soldier { + constructor(health, strength) { + this.health = health; + this.strength = strength; + } +} // Viking class Viking {} From d2f57b892e7e438c5e4295668739110792f0a026 Mon Sep 17 00:00:00 2001 From: SiyaM108 Date: Sat, 13 Sep 2025 09:35:44 +0100 Subject: [PATCH 2/6] complete iteration 1 --- src/viking.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/viking.js b/src/viking.js index cea0da8..adf3bd7 100644 --- a/src/viking.js +++ b/src/viking.js @@ -4,6 +4,13 @@ class Soldier { this.health = health; this.strength = strength; } + + attack() { + return this.strength; + } + receiveDamage(damage) { + this.health -= damage; + } } // Viking From dad246fdadc0c7244254978f7d210aeb0bd73d0b Mon Sep 17 00:00:00 2001 From: SiyaM108 Date: Sat, 13 Sep 2025 09:43:57 +0100 Subject: [PATCH 3/6] complete iteration 2: Viking --- src/viking.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/viking.js b/src/viking.js index adf3bd7..7a5accc 100644 --- a/src/viking.js +++ b/src/viking.js @@ -14,7 +14,25 @@ class Soldier { } // Viking -class Viking {} +class Viking { + constructor(name, health, strength) { + super(health, strength); + this.name = name; + } + + receiveDamage(damage) { + 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 8fea6fc56fcf42cdbdcfdbf2aa700a2071284021 Mon Sep 17 00:00:00 2001 From: SiyaM108 Date: Sat, 13 Sep 2025 09:54:39 +0100 Subject: [PATCH 4/6] complete iteration 3: Saxon --- src/viking.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/viking.js b/src/viking.js index 7a5accc..d010337 100644 --- a/src/viking.js +++ b/src/viking.js @@ -35,7 +35,20 @@ class Viking { } // Saxon -class Saxon {} +class Saxon { + constructor(health, strength) { + super(health, strength); + } + + receiveDamage(damage) { + 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 c58d69ada6ebb9a02d20972ab3fe0999fff5c4f6 Mon Sep 17 00:00:00 2001 From: SiyaM108 Date: Sat, 13 Sep 2025 09:56:17 +0100 Subject: [PATCH 5/6] complete iteration 4: War --- src/viking.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/viking.js b/src/viking.js index d010337..000c8c8 100644 --- a/src/viking.js +++ b/src/viking.js @@ -51,7 +51,59 @@ class Saxon { } // War -class War {} +class War { + constructor() { + this.vikingArmy = []; + this.saxonArmy = []; + } + + addViking(viking) { + this.vikingArmy.push(viking); + } + + addSaxon(saxon) { + this.saxonArmy.push(saxon); + } + + vikingAttack() { + const randomSaxonIndex = Math.floor(Math.random() * this.saxonArmy.length); + const randomVikingIndex = Math.floor(Math.random() * this.vikingArmy.length); + const randomSaxon = this.saxonArmy[randomSaxonIndex]; + const randomViking = this.vikingArmy[randomVikingIndex]; + const damage = randomViking.attack(); + const result = randomSaxon.receiveDamage(damage); + + if (randomSaxon.health <= 0) { + this.saxonArmy.splice(randomSaxonIndex, 1); + } + + return result; + } + + saxonAttack() { + const randomSaxonIndex = Math.floor(Math.random() * this.saxonArmy.length); + const randomVikingIndex = Math.floor(Math.random() * this.vikingArmy.length); + const randomSaxon = this.saxonArmy[randomSaxonIndex]; + const randomViking = this.vikingArmy[randomVikingIndex]; + const damage = randomSaxon.attack(); + const result = randomViking.receiveDamage(damage); + + if (randomViking.health <= 0) { + this.vikingArmy.splice(randomVikingIndex, 1); + } + + return result; + } + + 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 { + return 'Vikings and Saxons are still in the thick of battle.'; + } +} From 1be3ecc04dd51ac0aa08f141d48c908441282076 Mon Sep 17 00:00:00 2001 From: SiyaM108 Date: Sat, 13 Sep 2025 09:58:35 +0100 Subject: [PATCH 6/6] correct showStatus - missing bracket --- src/viking.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/viking.js b/src/viking.js index 000c8c8..9d38a06 100644 --- a/src/viking.js +++ b/src/viking.js @@ -103,6 +103,7 @@ class War { } else { return 'Vikings and Saxons are still in the thick of battle.'; } + } }