Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simple class solution in Clear category for The Warriors by a-zoshchuk
class Warrior:
is_alive = True
health = 50
def __init__(self):
self.attack = 5
def is_alive(self):
return self.health > 0
def take_damage(self, damage):
self.health -= damage
self.is_alive = self.health > 0
class Knight(Warrior):
def __init__(self):
self.attack = 7
pass
def fight(unit_1, unit_2):
while unit_2.health > 0 and unit_1.health > 0:
unit_2.take_damage(unit_1.attack)
if unit_2.health > 0:
unit_1.take_damage(unit_2.attack)
return unit_1.health > 0
Sept. 20, 2018