-
Notifications
You must be signed in to change notification settings - Fork 0
/
hero.py
117 lines (87 loc) · 2.72 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from weapon_and_spell import *
class Hero:
def __init__(
self,
name="Bron",
title="Dragonslayer",
health=160,
mana=100,
mana_regeneration_rate=2):
self.__name = name
self.__title = title
self.__start_health = health
self.__health = health
self.__start_mana = mana
self.__mana = mana
self.__mana_regeneration_rate = mana_regeneration_rate
self.__weapon = 0
self.__spell = 0
def known_as(self):
return "{} the {}".format(self.get_name(), self.get_title())
def get_name(self):
return self.__name
def get_title(self):
return self.__title
def get_health(self):
return self.__health
def get_mana(self):
return self.__mana
def get_mana_regeneration_rate(self):
return self.__mana_regeneration_rate
def is_alive(self):
if self.__health > 0:
return True
return False
def can_cast(self):
if self.__spell != 0:
if self.__mana >= self.__spell.get_mana_cost():
return True
return False
def get_cast_range(self):
if self.__spell:
return self__spell.get_cast_range()
else:
return 0
def take_damage(self, damage_points):
if self.__health < damage_points:
self.__health = 0
else:
self.__health = self.__health - damage_points
def take_healing(self, healing_points):
if self.is_alive() == False:
return False
a = self.__health + healing_points
if a > self.__start_health:
self.__health = self.__start_health
else:
self.__health = a
return True
def take_mana(self, mana_points):
a = self.__mana + mana_points
if a > self.__start_mana:
self.__mana = self.__start_mana
else:
self.__mana = a
def equip(self, weapon):
if isinstance(weapon, Weapon):
self.__weapon = weapon
else:
print("This is not a weapon")
return False
def learn(self, spell):
if isinstance(spell, Spell):
self.__spell = spell
else:
print("This is not a spell")
return False
def atack(self):
if self.can_cast():
return self.attack_helper(by="spell")
else:
return self.attack_helper(by="weapon")
def attack_helper(self, by=""):
if by == "weapon":
return self.__weapon.get_damage()
if by == "spell":
self.__mana -= self.__spell.get_mana_cost()
return self.__spell.get_damage()