-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharacter.py
More file actions
40 lines (30 loc) · 1.15 KB
/
character.py
File metadata and controls
40 lines (30 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Character:
def __init__(self, name: str, health: int, stamina: int, actions: list):
self.name = name
self.health = health
self.health_max = health
self.stamina = stamina
self.stamina_max = stamina
self.actions = list(actions) if actions else [] # List of actions objects (e.g., AttackAction, HealAction)
self.is_defending = False
def take_damage(self, amount):
if self.is_defending:
amount = amount // 2
self.is_defending = False
self.health -= amount
self.health = max(self.health, 0)
def use_stamina(self, amount):
self.stamina -= amount
self.stamina = max(self.stamina, 0)
def heal(self, amount):
self.health += amount
self.health = min(self.health, self.health_max)
def recover_stamina(self, amount):
self.stamina += amount
self.stamina = min(self.stamina, self.stamina_max)
def is_alive(self):
return self.health > 0
def get_action(self, index):
if 0 <= index < len(self.actions):
return self.actions[index]
return None