diff --git a/1-testsSoldier.py b/1-testsSoldier.py index ab6095a..d5ff3db 100644 --- a/1-testsSoldier.py +++ b/1-testsSoldier.py @@ -45,4 +45,4 @@ def testCanReceiveDamage(self): if __name__ == '__main__': - unittest.main() + unittest.main() \ No newline at end of file diff --git a/__pycache__/vikingsClasses.cpython-311.pyc b/__pycache__/vikingsClasses.cpython-311.pyc new file mode 100644 index 0000000..a8969a7 Binary files /dev/null and b/__pycache__/vikingsClasses.cpython-311.pyc differ diff --git a/vikingsClasses.py b/vikingsClasses.py index b51cd5f..43566d8 100644 --- a/vikingsClasses.py +++ b/vikingsClasses.py @@ -2,23 +2,122 @@ # Soldier -class Soldier: - pass +class Soldier(): + + def __init__(self, health, strength): + self.health = health + self.strength = strength + + + def attack(self): + return self.strength + + def receiveDamage(self, damage): + self.health = self.health - damage + + # Viking -class Viking: - pass +class Viking(Soldier): + + def __init__(self, name, health, strength): + super().__init__(health,strength) + self.name = name + self.health = health + self.strength = strength + + + def receiveDamage(self, damage): + super().receiveDamage(damage) + + if self.health > 0: + return f"{self.name} has received {damage} points of damage" + else: + return f"{self.name} has died in act of combat" + + def battleCry(self): + return "Odin Owns You All!" + # Saxon -class Saxon: - pass +class Saxon(Soldier): + + def __init__(self, health, strength): + super().__init__(health,strength) + + self.health = health + self.strength = strength + + def receiveDamage(self, damage): + super().receiveDamage(damage) + + if self.health > 0: + return f"A Saxon has received {damage} points of damage" + else: + return f"A Saxon has died in combat" # War +import random class War: - pass + + def __init__(self): + self.vikingArmy = [] + self.saxonArmy = [] + + def addViking(self, Viking): + self.vikingArmy.append(Viking) + + def addSaxon(self,Saxon): + self.saxonArmy.append(Saxon) + + def vikingAttack(self): + + if self.saxonArmy: + random_saxon = random.choice(self.saxonArmy) + random_viking = random.choice(self.vikingArmy) + + damage = random_viking.attack() + result = random_saxon.receiveDamage(damage) + + if random_saxon.health <= 0: + self.saxonArmy.remove(random_saxon) + + return result + return None + + def saxonAttack(self): + + if self.vikingArmy: + + random_viking = random.choice(self.vikingArmy) + random_saxon = random.choice(self.saxonArmy) + + damage = random_saxon.attack() + result = random_viking.receiveDamage(damage) + + if random_viking.health <= 0: + self.vikingArmy.remove(random_viking) + + return result + return None + + + + def showStatus(self): + + if len(self.saxonArmy) == 0: + return "Vikings have won the war of the century!" + elif len(self.vikingArmy) == 0: + return "Saxons have fought for their lives and survive another day..." + else: + return "Vikings and Saxons are still in the thick of battle." + + + + \ No newline at end of file