<reponame>lienchewei/DesignPattern<filename>StrategyPattern/hero.py
from exceptions import MpNotEnoughException


class Hero:
    def __init__(self, name, skill):
        self.name = name
        self._hp = 500
        self.mp = 200
        self.strength = 150
        self.wisdom = 80
        self.defense = 50
        self.skill = skill

    def attack(self, target_hero):
        injury = self.skill.attack(self, target_hero)
        print("{}使用了{}，傷害值為{}。".format(self.name, self.skill, injury))
        print("{}的HP剩下{}。".format(target_hero.name, target_hero.hp))
        if not target_hero.is_alive:
            print("{}已陣亡。".format(target_hero.name))

    @property
    def is_alive(self):
        return self._hp > 0

    @property
    def hp(self):
        return 0 if self._hp <= 0 else self._hp

    @hp.setter
    def hp(self, hp):
        self._hp = hp

    def lost_hp(self, hp):
        self._hp = self._hp - hp

    def lost_mp(self, mp):
        if self.mp < mp:
            raise MpNotEnoughException("Mp is not enough!")
        self.mp = self.mp - mp

from exceptions import MpNotEnoughException


class Hero:
    def __init__(self, name, skill):
        self.name = name
        self._hp = 500
        self.mp = 200
        self.strength = 150
        self.wisdom = 80
        self.defense = 50
        self.skill = skill

    def attack(self, target_hero):
        injury = self.skill.attack(self, target_hero)
        print("{}使用了{}，傷害值為{}。".format(self.name, self.skill, injury))
        print("{}的HP剩下{}。".format(target_hero.name, target_hero.hp))
        if not target_hero.is_alive:
            print("{}已陣亡。".format(target_hero.name))

    @property
    def is_alive(self):
        return self._hp > 0

    @property
    def hp(self):
        return 0 if self._hp <= 0 else self._hp

    @hp.setter
    def hp(self, hp):
        self._hp = hp

    def lost_hp(self, hp):
        self._hp = self._hp - hp

    def lost_mp(self, mp):
        if self.mp < mp:
            raise MpNotEnoughException("Mp is not enough!")
        self.mp = self.mp - mp