-
Notifications
You must be signed in to change notification settings - Fork 10
/
character.py
56 lines (44 loc) · 1.56 KB
/
character.py
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
# ------------ imports ------------
from weapon import fists
from health_bar import HealthBar
# ------------ parent class setup ------------
class Character:
def __init__(self,
name: str,
health: int,
) -> None:
self.name = name
self.health = health
self.health_max = health
self.weapon = fists
def attack(self, target) -> None:
target.health -= self.weapon.damage
target.health = max(target.health, 0)
target.health_bar.update()
print(f"{self.name} dealt {self.weapon.damage} damage to "
f"{target.name} with {self.weapon.name}")
# ------------ subclass setup ------------
class Hero(Character):
def __init__(self,
name: str,
health: int
) -> None:
super().__init__(name=name, health=health)
self.default_weapon = self.weapon
self.health_bar = HealthBar(self, color="green")
def equip(self, weapon) -> None:
self.weapon = weapon
print(f"{self.name} equipped a(n) {self.weapon.name}!")
def drop(self) -> None:
print(f"{self.name} dropped the {self.weapon.name}!")
self.weapon = self.default_weapon
# ------------ subclass setup ------------
class Enemy(Character):
def __init__(self,
name: str,
health: int,
weapon,
) -> None:
super().__init__(name=name, health=health)
self.weapon = weapon
self.health_bar = HealthBar(self, color="red")