Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Vampires by wbl4126
class Warrior:
def __init__(self):
self.health = 50
self.attack = 5
self.defense = 0
self.vampirism = 0
@property
def is_alive(self):
return self.health > 0
class Knight(Warrior):
def __init__(self):
super().__init__()
self.attack = 7
class Defender(Warrior):
def __init__(self):
super().__init__()
self.health = 60
self.attack = 3
self.defense = 2
class Vampire(Warrior):
def __init__(self):
super().__init__()
self.health = 40
self.attack = 4
self.vampirism = 50
def fight(unit_1, unit_2):
def hit(attacker, defender):
defender.health -= (attacker.attack - defender.defense) * (defender.defense < attacker.attack)
if attacker.vampirism:
attacker.health += (attacker.attack - defender.defense) * (attacker.vampirism / 100)
while unit_1.is_alive and unit_2.is_alive:
hit(unit_1, unit_2)
if unit_2.is_alive:
hit(unit_2, unit_1)
return unit_1.is_alive
class Army:
def __init__(self):
self.units = []
def add_units(self, unit, num):
self.units += [unit() for _ in range(num)]
@property
def is_alive(self):
return bool(self.units)
class Battle:
def fight(self, army_1, army_2):
while army_1.is_alive and army_2.is_alive:
if fight(army_1.units[0], army_2.units[0]):
del army_2.units[0]
else:
del army_1.units[0]
return army_1.is_alive
March 19, 2020