Dec-13-2019, 11:43 PM
Maybe a different approach will help.
Like making simple framework interface.
Example. An idea how to start.
Like making simple framework interface.
Example. An idea how to start.
class EquipArmor: def __init__(self): self.head = None self.chest = None self.legs = None self.feet = None # Check if armor can be equip. def equip_chest(self, armor): if armor is None: self.chest = None return True if isinstance(armor, ChestArmor): self.chest = armor return True return False # Get total protection from all armor. def get_protection(self): protection = 0 for armor in vars(self).values(): if armor: protection += armor.protection return protection class Armor: library = {} def __init__(self, name, protection): # Make sure that all armor will have a name and protection variables. self.name = name self.protection = protection Armor.library[self.name] = self # Identify armor type class ChestArmor(Armor): def __init__(self, name, protection): Armor.__init__(self, name, protection) ChestArmor("Leather Chest Plate", 5) ChestArmor("Leather", 2) player = EquipArmor() print(player.get_protection()) player.equip_chest(Armor.library["Leather Chest Plate"]) print(player.get_protection()) player.equip_chest(Armor.library["Leather"]) print(player.get_protection())
99 percent of computer problems exists between chair and keyboard.