"""Lecture 6, slide 31. Two instances share a class, not their health.

Run this file with Python 3. The web demo uses nonnegative integer damage
inputs. That is a demo control, not validation performed by this class.
"""


class PlayerCharacter:
    def __init__(self, name, max_health):
        self.name = name
        self.max_health = max_health
        self.health = max_health
        self.is_defeated = False
        print(self.name, "has entered the game!")

    def take_damage(self, amount):
        if self.is_defeated:
            print(self.name, "is already defeated.")
            return
        self.health -= amount
        print(self.name, "takes", amount, "damage.")
        if self.health <= 0:
            self.health = 0
            self.is_defeated = True
            print(self.name, "has been defeated!")

    def show_status(self):
        print("Name", self.name)
        print("HP", self.health, "/", self.max_health)


if __name__ == "__main__":
    player1 = PlayerCharacter("Grog", 100)
    player2 = PlayerCharacter("Vex", 80)
    player1.show_status()
    player2.show_status()
    player1.take_damage(30)
    player2.take_damage(50)
    player1.take_damage(70)
    player1.show_status()
    player2.show_status()
