class Monster(Character): @classmethod def get_monster_kind(cls): return cls.__name__.replace('Monster', '') def __init__(self, name='Monster', hp=50, power=5): super().__init__(name, hp, power) self.name = self.get_monster_kind() + name self.attack_kind = AttackKindFactory(self.get_monster_kind()) def attack(self, other, a_kind): if self.attack_kind.get_kind() == a_kind: other.get_damage(self.power, a_kind) self.attack_kind.attack() def get_damage(self, power, a_kind): if a_kind == self.attack_kind.get_kind(): self.hp += power else: self.hp -= power def get_attack_kind(self): return self.attack_kind @abstractmethod def generate_gold(self): pass
class Monster(Character): @classmethod def get_monster_kind(cls): return cls.__name__.replace('Monster', '') def __init__(self, name='Monster', hp=50, power=5): super().__init__(name, hp, power) self.name = self.get_monster_kind() + name self.attack_kind = AttackKindFactory(self.get_monster_kind()) # AttackKindFactory가 하는 일? 역할은 무엇인가? 중요성을 느끼는 게 중요! # 얻을 수 있는 이점은?? # other = 플레이어 def attack(self, other, a_kind): if a_kind == self.attack_kind.get_kind(): # 다른 객체의 상태 정보를 변경할 때 # message passing other.get_damage(self.power, a_kind) self.attack_kind.attack() # 데미지를 입는다 def get_damage(self, power, a_kind): if a_kind == self.attack_kind.get_kind(): self.hp += power else: self.hp -= power def get_attack_kind(self): return self.attack_kind.get_kind() @abstractmethod def generate_gold(self): pass