/
hero.py
85 lines (67 loc) · 2.19 KB
/
hero.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
77
78
79
80
81
82
83
84
85
class Hero:
def __init__(self, name, title, health, mana, mana_regeneration_rate):
self.name = name
self.title = title
self.health = health
self.curr_health = health
self.damage = 0
self.curr_mana = mana
self.max_mana = mana
self.mana_regeneration_rate = mana_regeneration_rate
self.spell = None
self.weapon = None
def get_name(self):
return self.name
def __str__(self):
return "{} {} with health {}, mana {} and damage {}".format(self.name, self.title, self.curr_health, self.curr_mana, self.damage)
def __repr__(self):
return self.__str__()
def known_as(self):
return "{} {}".format(self.name, self.title)
def get_health(self):
return self.curr_health
def get_mana(self):
return self.curr_mana
def get_weapon(self):
return self.weapon
def get_spell(self):
return self.spell
def set_position(self):
pass
def is_alive(self):
if self.health > 0:
return True
else:
return False
def can_cast(self, other):
if self.mana > other.mana:
return True
else:
return False
def take_damage(self, damage_points):
if self.curr_health > damage_points:
self.curr_health -= damage_points
else:
self.curr_health = 0
def take_healing(self, healing_points):
if self.curr_health == 0:
raise Exception
elif self.curr_health + healing_points > self.max_health:
self.curr_health = self.max_health
else:
self.curr_health += healing_points
def take_mana(self, mana_points):
if self.curr_mana + mana_points > self.max_mana:
self.curr_mana = self.max_mana
else:
self.curr_mana += mana_points
def equip(self, weapon):
self.damage = weapon.get_damage()
self.weapon = weapon
def get_damage(self):
return self.damage
def learn(self, spell):
self.damage = spell.get_damage()
self.spell = spell
def attack(self, by="weapon"):
return "{}".format(by).get_damage()