Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Army Units by Dima_Shul_chevskij
class Army:
def train_swordsman(self, name):
return Swordsman(name, self.SWORDSMAN, self.ARMY)
def train_lancer(self, name):
return Lancer(name, self.LANCER, self.ARMY)
def train_archer(self, name):
return Archer(name, self.ARCHER, self.ARMY)
class Warrior:
def __init__(self, name, category, army):
self.name = name
self.category = category
self.army = army
def introduce(self):
return f"{self.category} {self.name}, {self.army} {self.WARRIOR_TYPE}"
class Swordsman(Warrior):
WARRIOR_TYPE = "swordsman"
class Lancer(Warrior):
WARRIOR_TYPE = "lancer"
class Archer(Warrior):
WARRIOR_TYPE = "archer"
class AsianArmy(Army):
ARMY = "Asian"
SWORDSMAN = "Samurai"
LANCER = "Ronin"
ARCHER = "Shinobi"
class EuropeanArmy(Army):
ARMY = "European"
SWORDSMAN = "Knight"
LANCER = "Raubritter"
ARCHER = "Ranger"
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
my_army = EuropeanArmy()
enemy_army = AsianArmy()
soldier_1 = my_army.train_swordsman("Jaks")
soldier_2 = my_army.train_lancer("Harold")
soldier_3 = my_army.train_archer("Robin")
soldier_4 = enemy_army.train_swordsman("Kishimoto")
soldier_5 = enemy_army.train_lancer("Ayabusa")
soldier_6 = enemy_army.train_archer("Kirigae")
assert soldier_1.introduce() == "Knight Jaks, European swordsman"
assert soldier_2.introduce() == "Raubritter Harold, European lancer"
assert soldier_3.introduce() == "Ranger Robin, European archer"
assert soldier_4.introduce() == "Samurai Kishimoto, Asian swordsman"
assert soldier_5.introduce() == "Ronin Ayabusa, Asian lancer"
assert soldier_6.introduce() == "Shinobi Kirigae, Asian archer"
print("Coding complete? Let's try tests!")
March 25, 2019