diff --git a/fyle.py b/fyle.py new file mode 100644 index 0000000..29629ca --- /dev/null +++ b/fyle.py @@ -0,0 +1,26 @@ +""" +Create a game using the classes you defined. For this, you will need to: +- Create a new `file.py` +- Import the classes you defined earlier +- Define functions to create the workflow of the game: i.e. functions to create teams +(maybe you can create random teams with your classmates' names), run the game, etc. + +""" +from vikingsClasses import Soldier, Viking, Saxon, War + +soldado = input("Chose your team. Type VIKING or SAXON") +while soldado.upper() != "VIKING" and soldado.upper() != "SAXON": + soldado = input("Wrong team, choose again. Type VIKING or SAXON") + +if soldado.upper() == "VIKING": + name = input("Please, name your soldier, good luck: ") + +strength = input("Choose your strength wisely from 1-100:") + + + + + + + + \ No newline at end of file diff --git a/vikingsClasses.py b/vikingsClasses.py index b51cd5f..d948aeb 100644 --- a/vikingsClasses.py +++ b/vikingsClasses.py @@ -1,24 +1,78 @@ -# Soldier +import random +# Soldier +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 -= damage -class Soldier: - pass # Viking - - -class Viking: - pass - +class Viking(Soldier): + def __init__ (self, name, health, strength): + super().__init__(health, strength) + self.name = name + + def receiveDamage(self, damage): + self.health -= 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(Soldier): + def receiveDamage(self, damage): + self.health -= damage + if self.health>0: + return f"A Saxon has received {damage} points of damage" + else: + return f"A Saxon has died in combat" -class Saxon: - pass - # War +class War(): + def __init__(self): + self.vikingArmy = [] + self.saxonArmy = [] + + def addViking(self, viking): + self.vikingArmy.append(viking) - -class War: - pass + def addSaxon(self, saxon): + self.saxonArmy.append(saxon) + + def vikingAttack(self): + saxon_herido = random.choice(self.saxonArmy) + vikingo_ataca = random.choice(self.vikingArmy) + string = saxon_herido.receiveDamage(vikingo_ataca.strength) + if saxon_herido.health <= 0: + self.saxonArmy.remove(saxon_herido) + return string + + def saxonAttack(self): + vikingo_herido = random.choice(self.vikingArmy) + saxon_ataca = random.choice(self.saxonArmy) + string = vikingo_herido.receiveDamage(saxon_ataca.strength) + if vikingo_herido.health <= 0: + self.vikingArmy.remove(vikingo_herido) + return string + + def showStatus(self): + if self.saxonArmy == []: + return "Vikings have won the war of the century!" + if self.vikingArmy == []: + 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