Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for The Healers by vperinova
class Warrior:
def __init__(self):
self.health = 50
self.attack = 5
self.following = 0
self.health_max = self.health
@property
def is_alive(self):
if self.health > 0:
return True
return False
def take_hit(self, attack):
self.health -= attack if attack <= self.health else self.health
def heal(self, mate):
pass
def do_attack(self, enemy):
enemy.take_hit(self.attack)
if self.following:
self.following.heal(self)
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.deffence = 2
def take_hit(self, attack):
super().take_hit(max(attack - self.deffence, 0))
class Vampire(Warrior):
def __init__(self):
super().__init__()
self.health = 40
self.attack = 4
self.vampirism = 0.5
def do_attack(self, enemy):
h1 = enemy.health
super().do_attack(enemy)
h2 = enemy.health
self.health += (h1 - h2) * self.vampirism
class Lancer(Warrior):
def __init__(self):
super().__init__()
self.attack = 6
def do_attack(self, enemy):
super().do_attack(enemy)
if enemy.following:
enemy.following.take_hit(self.attack // 2)
class Healer(Warrior):
def __init__(self):
super().__init__()
self.health = 60
self.attack = 0
self.cure = 2
def heal(self, mate):
mate.health = min(mate.health + self.cure, mate.health_max)
def fight(unit_1, unit_2, unit_1b = 0, unit_2b = 0):
while True:
if unit_1.is_alive:
unit_1.do_attack(unit_2)
else:
return False
if unit_2.is_alive:
unit_2.do_attack(unit_1)
else:
return True
class Army:
def __init__(self):
self.units = []
def add_units(self, unit, count):
for i in range(count):
new_unit = unit()
self.units.append(new_unit)
if len(self.units) > 1:
self.units[-2].following = new_unit
class Battle:
def fight(self, army_1, army_2):
while True:
if fight(army_1.units[0], army_2.units[0]):
del army_2.units[0]
if not army_2.units:
return True
else:
del army_1.units[0]
if not army_1.units:
return False
Oct. 10, 2018
Comments: