Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Lancers by bravebug
class Warrior():
health = 50
attack = 5
defense = 0
is_alive = True
def isalive(self):
self.is_alive = self.health > 0
return self.is_alive
class Knight(Warrior):
attack = 7
class Defender(Warrior):
health = 60
attack = 3
defense = 2
class Vampire(Warrior):
health = 40
attack = 4
vampirism = 50
class Lancer(Warrior):
attack = 6
class Army():
def __init__(self):
self.army = []
def add_units(self, unit_type, quantity):
for n in range(quantity):
self.army.append(unit_type())
class Battle():
def fight(self, army_1, army_2):
while army_1.army and army_2.army:
if fight(army_1.army[0], army_2.army[0]):
army_2.army.pop(0)
else:
army_1.army.pop(0)
return bool(army_1.army)
def fight(unit_1, unit_2):
def attack(assaulter, defending):
damage = assaulter.attack - defending.defense if assaulter.attack > defending.defense else 0
temp = defending.health
defending.health = defending.health - damage if defending.health > damage else 0
if isinstance(assaulter, Vampire):
assaulter.health += (temp - defending.health) * assaulter.vampirism / 100
while unit_1.isalive() and unit_2.isalive():
attack(unit_1, unit_2)
if unit_2.health > 0:
attack(unit_2, unit_1)
return unit_1.health >= unit_2.health
March 17, 2021