diff --git a/README.md b/README.md index 1cbca72..38b94e5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Lab | Vikings (lab-data-vikings) + ## Introduction The Vikings and the Saxons are at War. Both are Soldiers but they have their own methods to fight. Vikings are ported to Python. YAY!! diff --git a/battle.py b/battle.py new file mode 100644 index 0000000..393c3ce --- /dev/null +++ b/battle.py @@ -0,0 +1 @@ +# Hacer una batalla entre vikingos: un projecto bonito. \ No newline at end of file diff --git a/vikingsClases.py b/vikingsClases.py index b51cd5f..7829cd8 100644 --- a/vikingsClases.py +++ b/vikingsClases.py @@ -3,22 +3,98 @@ 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): + super().__init__(health, strength) + self.name = name + + #def attack(self): + # super().attack() + + def receiveDamage(self, damage): + super().receiveDamage(damage) + if self.health > 0: + return "".join([self.name," has received ",str(damage)," points of damage"]) + else: + return "".join([self.name," has died in act of combat"]) + + def battleCry(self): + return 'Odin Owns You All!' + # Saxon -class Saxon: +class Saxon(Soldier): + def __init__(self, health, strength): + super().__init__(health, strength) + + def receiveDamage(self, damage): + super().receiveDamage(damage) + if self.health > 0: + return "".join(["A Saxon has received ",str(damage)," points of damage"]) + else: + return "A Saxon has died in combat" + pass # 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): + vikingAttacker = random.choice(self.vikingArmy) + dmg = vikingAttacker.attack() + saxonVictim = random.choice(self.saxonArmy) + result = saxonVictim.receiveDamage(dmg) + if saxonVictim.health <= 0: + self.saxonArmy.remove(saxonVictim) + return result + + #victimIndex = random.randint(0,sum(len(self.vikingArmy),-1)) + #result = self.saxonArmy[victimIndex].receiveDamage(dmg) + #if result == "A Saxon has died in combat": + #saxonArmy.remove(saxonArmy[victimIndex]) + #return result + pass + def saxonAttack(self): + saxonAttacker = random.choice(self.saxonArmy) + dmg = saxonAttacker.attack() + vikingVictim = random.choice(self.vikingArmy) + result = vikingVictim.receiveDamage(dmg) + if vikingVictim.health <= 0: + self.vikingArmy.remove(vikingVictim) + return result + + pass + def showStatus(self): + if self.saxonArmy == []: return "Vikings have won the war of the century!" + elif self.vikingArmy == []: return "Saxons have fought for their lives and survive another day..." + return "Vikings and Saxons are still in the thick of battle." +