# Chapter 27 example: Character class.

class Character:
    def __init__(self, name, hp):
        self.name = name
        self.hp = hp
        self.max_hp = hp

    def take_damage(self, amount):
        self.hp = self.hp - amount
        if self.hp < 0:
            self.hp = 0

    def heal(self, amount):
        self.hp = self.hp + amount
        if self.hp > self.max_hp:
            self.hp = self.max_hp

    def is_alive(self):
        return self.hp > 0

c = Character("Keiko", 100)
c.take_damage(30)
print(c.hp)           # 70
c.heal(50)
print(c.hp)           # 100  (capped)
print(c.is_alive())   # True
