-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.py
More file actions
82 lines (59 loc) · 3.02 KB
/
action.py
File metadata and controls
82 lines (59 loc) · 3.02 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#base class for actions that characters can perform in the game
class Action:
def __init__(self, name: str, stamina_cost: int):
self.name = name
self.stamina_cost = stamina_cost
def can_execute(self, actor):
return actor.stamina >= self.stamina_cost
def execute(self, actor, target):
raise NotImplementedError("Execute method must be implemented by subclasses")
def get_details(self):
return (f"(Cost: {self.stamina_cost} ST)")
#class to execute an attack action, which reduces the target's health and consumes the actor's stamina
class AttackAction(Action):
def __init__(self, name: str, damage: int, stamina_cost: int):
super().__init__(name, stamina_cost)
self.damage = damage
def execute(self, actor, target):
if not self.can_execute(actor):
return f"{actor.name} tried to attack but has no stamina!"
target.take_damage(self.damage)
actor.use_stamina(self.stamina_cost)
return f"{actor.name} attacks {target.name} for {self.damage} damage!"
def get_details(self):
return (f"(Damage: {self.damage}, Cost: {self.stamina_cost} ST)")
#class to execute a jheal action, which restores the actor's health and consumes stamina
class HealAction(Action):
def __init__(self, name: str, heal_amount: int, stamina_cost: int):
super().__init__(name, stamina_cost)
self.heal_amount = heal_amount
def execute(self, actor, target=None):
if not self.can_execute(actor):
return f"{actor.name} tried to heal but has no stamina!"
actor.heal(self.heal_amount)
actor.use_stamina(self.stamina_cost)
return f"{actor.name} heals for {self.heal_amount} health!"
def get_details(self):
return (f"(Heal: {self.heal_amount}, Cost: {self.stamina_cost} ST)")
#class to execute a defend action, which reduces incoming damage for the next turn and consumes stamina
class DefendAction(Action):
def __init__(self, name: str, stamina_cost: int):
super().__init__(name, stamina_cost)
def execute(self, actor, target=None):
if not self.can_execute(actor):
return f"{actor.name} tried to defend but has no stamina!"
actor.is_defending = True
actor.use_stamina(self.stamina_cost)
return f"{actor.name} raises their shield to defend!"
def get_details(self):
return (f"(Cost: {self.stamina_cost} ST)")
#clas to execute stamina recovery action, which restores the actor's stamina
class StaminaRecoveryAction(Action):
def __init__(self, name: str, recovery_amount: int):
super().__init__(name, stamina_cost=0) # No stamina cost for recovery
self.recovery_amount = recovery_amount
def execute(self, actor, target=None):
actor.recover_stamina(self.recovery_amount)
return f"{actor.name} recovers {self.recovery_amount} stamina!"
def get_details(self):
return (f"(Recover: {self.recovery_amount} ST)")