Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Healers by katnic
'''
CLASS WARRIOR
'''
class Warrior:
def __init__(self):
self.health = 50
self.attack = 5
self.defense = 0
self.vampirism = 0
self.hit_next = 0
self.healing = False
self.maxhealth = self.health
@property
def is_alive(self):
return self.health > 0
def hit(self, other):
other.loss(self.attack)
self.health += other.damage(self.attack) * (self.vampirism / 100)
def loss(self, attack):
self.health -= self.damage(attack)
def damage(self, attack):
return attack - self.defense if attack > self.defense else 0
def damage_next(self, unit_1, unit_2):
self.health -= (unit_2.damage(unit_1.attack)) * (unit_1.hit_next / 100)
def get_help(self):
if self.healing:
self.health = min(self.maxhealth, self.health + 2)
'''
CHILD CLASS
'''
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
class Lancer(Warrior):
def __init__(self):
super().__init__()
self.attack = 6
self.hit_next = 50
class Healer(Warrior):
def __init__(self):
super().__init__()
self.health = 60
self.attack = 0
def heal(self, unit):
unit.health = min(unit.maxhealth, unit.health + 2)
'''
UNITS FIGHT
'''
def fight(unit_1, unit_2):
while True:
if unit_1.is_alive:
unit_1.hit(unit_2)
unit_1.get_help
else: return False
if unit_2.is_alive:
unit_2.hit(unit_1)
unit_2.get_help
else: return True
def print_health(unit):
print("{} with {} hp".format(unit, unit.health))
'''
CLASS ARMY
'''
class Army:
def __init__(self):
self.units = []
@property
def is_alive(self):
return len(self.units) > 0
@property
def first(self):
for unit in self.units:
if not unit.is_alive or isinstance(unit, Healer): self.units.remove(unit)
else: return unit
def add_units(self, unit, count):
for _ in range(count):
self.units.append(unit())
def hit(self, unit_1, unit_2):
if self.first: self.first.damage_next(unit_1, unit_2)
def get_help(self):
if len(self.units) > 1 and type(self.units[1]) == Healer and self.units[1].is_alive:
self.first.healing = True
'''
ARMYS BATTLE
'''
class Battle:
@staticmethod
def fight(army_1, army_2):
while army_1.is_alive and army_2.is_alive:
unit_1, unit_2 = army_1.first, army_2.first
army_1.get_help()
army_2.get_help()
if fight(unit_1, unit_2): army_2.hit(unit_1, unit_2)
else: army_1.hit(unit_2, unit_1)
return army_1.is_alive
Aug. 31, 2021