-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenemy.py
76 lines (62 loc) · 1.98 KB
/
enemy.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class Enemy:
def __init__(self, health, mana, damage):
self.health = health
self.mana = mana
self.damage = damage
self.max_health = health
self.max_mana = mana
self.weapon = None
self.spell = None
def is_alive(self):
if self.health > 0:
return True
else:
return False
def can_cast(self):
if self.spell is None:
return False
else:
if self.mana - self.spell.mana_cost >= 0:
return True
if self.mana - self.spell.mana_cost < 0:
return False
def get_health(self):
return self.health
def get_mana(self):
return self.mana
def take_healing(self, healing_points):
if self.health == 0:
return False
elif self.health + healing_points >= self.max_health:
self.health = self.max_health
return True
elif self.health + healing_points < self.max_health:
self.health += healing_points
return True
def take_mana(self, mana_points):
if self.mana + mana_points >= self.max_mana:
self.mana = self.max_mana
elif self.mana + mana_points <= 0:
self.mana = 0
elif self.mana + mana_points < self.max_mana:
self.mana += mana_points
def take_damage(self, damage_points):
if self.health <= damage_points:
self.health = 0
elif self.health > damage_points:
self.health -= damage_points
def equip(self, weapon):
self.weapon = weapon
def learn(self, spell):
self.spell = spell
def attack(self, by=""):
if by == "weapon":
if self.weapon is not None:
return self.weapon.damage
else:
return 0
elif by == "spell":
if self.spell is not None:
return self.spell.damage
else:
return 0