Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Dont Know Why or How passed the Check, But certainly I am Strong At OOP solution in Clear category for The Lancers by Stensen
class Warrior:
def __init__(self): self.health = 50; self.attack = 5
@property
def is_alive(self): return self.health > 0
def strike(self, first, second=None): first.health -= first.damage(self.attack)
def damage(self, enemy_attack): return enemy_attack
class Knight(Warrior):
def __init__(self): super().__init__(); self.attack = 7
class Defender(Warrior):
def __init__(self): self.health = 60; self.attack = 3; self.defense = 2
def damage(self, enemy_attack): return max(0, enemy_attack - self.defense)
class Vampire(Warrior):
def __init__(self):
self.health = 40; self.attack = 4; self.vampirism = 0.5
def strike(self, enemy):
super().strike(enemy)
self.health += enemy.damage(self.attack) * self.vampirism
def fight(agonist, enemy):
while True:
agonist.strike(enemy)
if enemy.health <= 0: return True
enemy.strike(agonist)
if agonist.health <= 0: return False
class Lancer(Warrior):
def __init__(self):
super().__init__(); self.attack = 6
def strike(self, first, second=None):
super().strike(first)
if second: second.health -= second.damage(self.attack / 2)
class Army:
def __init__(self): self.army = []
def add_units(self, unit, q): self.army += [unit() for _ in range(q)]
@property
def survived_unit(self):
for unit in self.army:
if unit.is_alive: return unit;break
@property
def is_alive(self): return self.survived_unit is not None
class Battle:
@staticmethod
def fight(army1, army2):
assert type(army1) == Army; assert type(army2) == Army
while army1.is_alive and army2.is_alive:
fight(army1.survived_unit, army2.survived_unit)
return army1.is_alive
Oct. 12, 2020