Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
@property and inner take_hit() solution in Clear category for The Warriors by ludek.reif
class Warrior:
def __init__(self):
self.health = 50
self.strength = 5
def make_hit(self, enemy):
enemy.take_hit(self.strength)
def take_hit(self, strength):
self.health -= strength
@property
def is_alive(self):
return self.health > 0
class Knight(Warrior):
def __init__(self):
super().__init__()
self.strength = 7
def fight(unit_1, unit_2):
while True:
unit_1.make_hit(unit_2)
if not unit_2.is_alive:
return True
unit_2.make_hit(unit_1)
if not unit_1.is_alive:
return False
Sept. 19, 2019
Comments: