Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
nearly unchanged from previous mission... solution in Clear category for The Defenders by tokyoamado
class Warrior:
def __init__(self):
self.health = 50
self.attack = 5
self.defence = 0
self.is_alive = True
class Knight(Warrior):
def __init__(self):
super().__init__()
self.attack = 7
class Defender(Warrior):
def __init__(self):
super().__init__()
self.health = 60
self.attack = 3
self.defence = 2
class Rookie(Warrior):
def __init__(self):
super().__init__()
self.attack = 1
class Army():
def __init__(self):
self.members = []
def add_units(self, unit, num):
self.members.extend(unit() for _ in range(num))
class Battle():
def fight(self, home, away):
booth1 = home.members.pop(0)
booth2 = away.members.pop(0)
while True:
if not booth1.is_alive:
if not home.members:
return False
else:
booth1 = home.members.pop(0)
if not booth2.is_alive:
if not away.members:
return True
else:
booth2 = away.members.pop(0)
fight(booth1, booth2)
def fight(unit_1, unit_2):
while True:
unit_2.health -= max(0, unit_1.attack - unit_2.defence)
if unit_2.health <= 0:
unit_2.is_alive = False
return True
unit_1.health -= max(0, unit_2.attack - unit_1.defence)
if unit_1.health <= 0:
unit_1.is_alive = False
return False
June 2, 2019
Comments: