Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Warriors by cheikhnamouna
class Warrior:
def __init__(self):
self.health = 50
self.attack = 5
@property
def is_alive(self):
return self.health > 0
class Knight(Warrior):
def __init__(self):
super().__init__()
self.attack = 7
def fight(u1, u2):
attacker, attacked = u1, u2
while u1.is_alive and u2.is_alive:
attacked.health -= attacker.attack
attacker = u2 if attacker == u1 else u1
attacked = u2 if attacked == u1 else u1
return u1.is_alive
Dec. 30, 2018