def heal(self, heal_by=2, full_healing=True): """Heal the unit replenishing all the hit points This method is called when you (the player) enters a friendly hut. :param heal_by: `health_meter`will be updated by this amount if full healing is not requested. :param full_healing: Fully heal this unit by resetting the `heal_meter`to the maximum limit. .. seealso:: :py:meth:`Knigth.acquire_hut` """ if self.health_meter == self.max_hp: return if full_healing: self.health_meter = self.max_hp else: self.health_meter += heal_by if self.health_meter > self.max_hp: raise GameUnitError("health_meter > max_hp!") print_bold("You are HEALED!", end=' ') self.show_health(bold=True)
def heal(self, heal_by=2, full_healing=True): """Heal the unit replenishing its hit points This method is called when you (the player) enters a friendly hut. :param heal_by: `health_meter` will be updated by this amount if full healing is not requested/ :param full_healing: Fully heal this unit by resetting the `heal_meter` to the maximum limit. .. seealso:: :py:meth:`Knight.acquire_hut` .. todo:: Add exception handling code , assert heal_by amount is within limits! (exercise) """ # Do not continue if the game unit already has full health 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 GameUnitError("health_meter > max_hp!", 101) print_bold("You are HEALED!", end=' ') self.show_health(bold=True)
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 if self.health_meter > self.max_hp: raise GameUnitError("Healh_meter > max_hp!", 101) print_bold("You are HEALED!", end=' ') self.show_health(bold=True)
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 GameUnitError("health_meter > max_hp!", 101) print_bold("You are HEALED!", end=' ') self.show_health(bold=True)
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 else: print_bold("需要治疗:", end='') self.show_health() print_bold("治疗中.........", end='\n') if full_healing: self.health_meter = self.max_hp else: self.health_meter += heal_by if self.health_meter > self.max_hp: raise GameUnitError('治疗恢复值无效, 超过最大允许值', code=101) print_bold("已被治疗!", end=' ') self.show_health(bold=True)