def heal(self, heal_by=2, full_healing=True):
        """Heal the unit replenishing all the hit points"""
        # try:
        #     assert (self.health_meter + heal_by <= self.max_hp)
        #     if self.health_meter == self.max_hp:
        #         return
        #
        #     if full_healing:
        #         self.health_meter = self.max_hp
        #     else:
        #         # TODO: Do you see a bug here? it can exceed max hit points!
        #         self.health_meter += heal_by
        # except AssertionError:
        #     print("Invaild Input, heal_by: %s"%str(heal_by))
        #     return

        if self.health_meter == self.max_hp:
            return
        if full_healing:
            self.health_meter = self.max_hp
        else:
            self.health_meter += heal_by

        #raise a custom exception
        if self.health_meter > self.max_hp:
            raise HealthMeterException("health_meter > max_hp!")

        print_bold("You are HEALED!", end=' ')
        self.show_health(bold=True)
示例#2
0
    def heal(self, heal_by=2, full_healing=True):
        """Heal the unit replenishing all the hit points"""
        if self.health_meter == self.max_hp:
            return

        if full_healing:
            self.health_meter = self.max_hp
        else:
            self.health_meter += heal_by

        # raise a custom exception
        if self.health_meter > self.max_hp:
            raise HealthMeterException("health_meter > max_hp!")

        print_bold("You are HEALED!", end=' ')
        self.show_health(bold=True)
示例#3
0
    def heal(self, heal_by=2, full_healing=True):
        """Heal the unit replenishing all the hit points"""
        if self.health_meter == self.max_hp:
            return
        if full_healing:
            self.health_meter = self.max_hp
        else:
            self.health_meter += heal_by
        # -------------------------------------------------------------------
        # raise a custom exception. Refer to chapter on exception handling
        # -------------------------------------------------------------------
        if self.health_meter > self.max_hp:
            raise HealthMeterException("health_meter > max_hp!")

        print(bold(f"You are HEALED!"), end=" ")
        self.show_health(bold_str=True, end='\r\n')
    def heal(self, heal_by=2, full_healing=True):
        """Heal the unit replenishing all the hit points"""
        if self.health_meter == self.max_hp:
            return

        if full_healing:
            self.health_meter = self.max_hp
        else:
            # TODO: Do you see a bug here? it can exceed max hit points!
            self.health_meter += heal_by

        if self.health_meter > self.max_hp:
            raise HealthMeterException("health_meter > max_hp!")

        print_bold("You are HEALED!", end=' ')
        self.show_health(bold=True)