Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for The Warriors by Tinus_Trotyl
class Warrior:
def __init__(self):
self.health = 50
self.attack = 5
self.is_alive = True
def set_health(self, gain):
self.health = max(self.health + gain, 0)
self.is_alive = bool(self.health)
def strike(self, unit):
unit.set_health(-self.attack)
class Knight(Warrior):
def __init__(self):
super(Knight, self).__init__()
self.attack = 7
def fight(unit_1, unit_2):
a, b = unit_1, unit_2
while a.is_alive and b.is_alive:
a.strike(b)
a, b = b, a
return unit_1.is_alive
May 12, 2022