From d842968b2e16a289cf252e9a23ebbf76242b039e Mon Sep 17 00:00:00 2001 From: ppt527xkf <528893182@qq.com> Date: Sun, 2 Jun 2024 22:23:41 +0800 Subject: [PATCH] ADD file via upload --- character.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 character.py diff --git a/character.py b/character.py new file mode 100644 index 0000000..5a98ee3 --- /dev/null +++ b/character.py @@ -0,0 +1,29 @@ +class Character: + def __init__(self): + self.health = 100 + self.energy = 50 + self.position = (0, 0) + + def move(self, direction): + if direction == 'forward': + self.position = (self.position[0], self.position[1] + 1) + elif direction == 'backward': + self.position = (self.position[0], self.position[1] - 1) + elif direction == 'left': + self.position = (self.position[0] - 1, self.position[1]) + elif direction == 'right': + self.position = (self.position[0] + 1, self.position[1]) + + def attack(self): + print("攻击!") + + def heal(self, amount): + self.health += amount + if self.health > 100: + self.health = 100 + + def take_damage(self, amount): + self.health -= amount + if self.health < 0: + self.health = 0 +