Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
army_units solution in Clear category for Army Units by dannedved
class Army:
def __init__(self, army_type, swordsman, lancer, archer):
self.army_type = army_type
self.soldier_types = {
"swordsman": swordsman,
"lancer": lancer,
"archer": archer}
def train_swordsman(self, name):
return Swordsman(self, name)
def train_lancer(self, name):
return Lancer(self, name)
def train_archer(self, name):
return Archer(self, name)
# In this solution, Swordsman, Lancer, and Archer are subclasses of 'Soldier'.
class Soldier:
def __init__(self, soldier_type, army, name):
self.soldier_type = soldier_type
self.army = army
self.name = name
def introduce(self):
return F"{self.army.soldier_types[self.soldier_type]} {self.name}, {self.army.army_type} {self.soldier_type}"
class Swordsman(Soldier):
def __init__(self, army, name):
Soldier.__init__(self, "swordsman", army, name)
class Lancer(Soldier):
def __init__(self, army, name):
Soldier.__init__(self, "lancer", army, name)
class Archer(Soldier):
def __init__(self, army, name):
Soldier.__init__(self, "archer", army, name)
class AsianArmy(Army):
def __init__(self):
Army.__init__(self, "Asian", "Samurai", "Ronin", "Shinobi")
class EuropeanArmy(Army):
def __init__(self):
Army.__init__(self, "European", "Knight", "Raubritter", "Ranger")
June 22, 2020
Comments: