• Help

 

unit1 = Defender() unit2 = Rookie() fight(unit1, unit2) unit_1.health

class Warrior:
def __init__(self):
    self.health=50
    self.attack=5
    self.defense=0
@property
def is_alive(self):
    return self.health>0

class Knight(Warrior):
def __init__(self):
    super().__init__()
    self.attack=7

class Defender(Warrior):
def __init__(self):
    super().__init__()
    self.defense=2
    self.attack=3
    self.health=60

def fight(u1, u2):
while u1.is_alive and u2.is_alive:
    u2.health-=u1.attack-u2.defense
    if not u2.is_alive: return True
    u1.health-=u2.attack-u1.defense
    if not u1.is_alive: return False

class Army:
def __init__(self):
    self.units=[]

@property
def is_alive(self):
    return len(self.units)>0

def add_units(self,units,count):
    while count>0:
        self.units.append(units())
        count-=1

class Battle:
def fight(self,army1,army2):
    u1=army1.units[0];u2=army2.units[0]
    while army1.is_alive and army2.is_alive:
        if not fight(u1,u2):
            army1.units.remove(u1)
            if army1.is_alive: u1=army1.units[0]     
        else:
            army2.units.remove(u2)
            if army2.is_alive: u2=army2.units[0]
    return army1.is_alive