Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Warriors solution in Clear category for The Warriors by DaI17
class Warrior:
def __init__(self):
self.health = 50
self.attack = 5
self.is_alive = True
def to_attack(self, target):
target.damage(self.attack)
def damage(self, point):
self.health -= point
self.check_alive()
def check_alive(self):
if self.health <= 0:
self.is_alive = False
else:
self.is_alive = True
class Knight(Warrior):
def __init__(self):
super().__init__()
self.attack = 7
def fight(unit_1, unit_2):
units = [unit_1, unit_2]
round = 0
while True:
attack_unit = units[round % 2]
defense_unit = units[(round+1) % 2]
attack_unit.to_attack(defense_unit)
if not defense_unit.is_alive:
break
round += 1
return unit_1.is_alive
Feb. 19, 2020