Hey, guys!
Please help me find where is a problem. I stopped at fight no. 5.
My code set wife.is_alive = True, but it should be False.
Here is my code:
class Warrior:
def __init__(self):
self.health = 50
self.attack = 5
self.health_list = [50]
self.is_alive = (self.health_list[-1] >= 0)
class Knight(Warrior):
def __init__(self):
Warrior.__init__(self)
self.health = 50
self.attack = 7
self.health_list = [50]
self.is_alive = (self.health_list[-1] >= 0)
def fight(unit_1, unit_2):
r = 2
while unit_1.health > 0 and unit_2.health > 0:
if r % 2 == 0: #round 1
unit_2.health -= unit_1.attack
unit_2.health_list.append(unit_2.health)
r += 1
else: #round 2
unit_1.health -= unit_2.attack
unit_1.health_list.append(unit_1.health)
r += 1
if (unit_1.health > 1):
return True
else:
return False
Created at: 2019/03/25 22:20; Updated at: 2019/03/26 17:48
The question is resolved.