diff --git a/vikingsClases.py b/vikingsClases.py index b51cd5f..514fd47 100644 --- a/vikingsClases.py +++ b/vikingsClases.py @@ -3,22 +3,100 @@ class Soldier: - pass + def __init__(self, health, strength): + self.health = health + self.strength = strength + + def attack(self): + return self.strength + + def receiveDamage(self, damage): + self.health -= damage + + + # Viking -class Viking: - pass +class Viking(Soldier): + + def __init__(self, name, health, strength): + self.name = name + super().__init__(health, strength) + + def attack(self): + return super().attack() + + def receiveDamage(self, damage): + self.health -= damage + + if self.health > 0: + return self.name + " has received " + str(damage) + " points of damage" + else: + return 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) -# War + def attack(self): + return super().attack() + + def receiveDamage(self, damage): + self.health -= damage + + if self.health > 0: + return "A Saxon has received " + str(damage) + " points of damage" + else: + return "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): + viking = random.choice(self.vikingArmy) + saxon = random.choice(self.saxonArmy) + result_v = saxon.receiveDamage(viking.attack()) + if saxon.health <= 0: + self.saxonArmy.remove(saxon) + return result_v + + + def saxonAttack(self): + viking = random.choice(self.vikingArmy) + saxon = random.choice(self.saxonArmy) + result_s = viking.receiveDamage(saxon.attack()) + if viking.health <= 0: + self.vikingArmy.remove(viking) + return result_s + + def showStatus(self): + if len(self.vikingArmy) == 0: + return "Saxons have fought for their lives and survive another day..." + elif len(self.saxonArmy) == 0: + return "Vikings have won the war of the century!" + else: + return "Vikings and Saxons are still in the thick of battle." +