-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity_class.py
71 lines (56 loc) · 1.71 KB
/
entity_class.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
class CantCastError(Exception):
pass
class Entity():
def __init__(self, health, mana, damage):
self.health = health
self.mana = mana
self.damage = damage
self.weapon = None
self.spell = None
def get_health(self):
return int(self.health)
def get_mana(self):
return int(self.mana)
def is_alive(self):
if self.health == 0:
return False
else:
return True
def can_cast(self):
if self.mana == 0:
return False
else:
return True
def take_healing(self, healing_points):
if self.health == 0:
return False
self.health += healing_points
if self.health >= 100:
self.health = 100
def take_mana(self, mana_points):
if self.mana + mana_points > 100:
self.mana = 100
else:
self.mana += mana_points
def take_damage(self, damage_points):
self.health -= damage_points
if self.health < 0:
self.health = 0
return self.health
def equip(self, weapon):
self.weapon = weapon
def learn(self, spell):
self.spell = spell
def attack(self, by="None"):
if by == "weapon":
return self.damage + self.weapon.get_weapon_damage()
if by == "magic":
if self.mana < self.spell.get_spell_damage():
raise CantCastError
else:
self.mana -= self.spell.get_spell_mana_cost()
return self.damage + self.spell.get_spell_damage()
def has_weapon(self):
return self.weapon is not None
def has_spell(self):
return self.spell is not None