-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHuman-Inheritance_multi-child.py
More file actions
42 lines (30 loc) · 959 Bytes
/
Human-Inheritance_multi-child.py
File metadata and controls
42 lines (30 loc) · 959 Bytes
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
class Hero:
def __init__(self, name, health):
self.__name = name
self.__health = health
def get_name(self):
return self.__name
def get_health(self):
return self.__health
def take_damage(self, damage):
self.__health -= damage
class Archer(Hero):
def __init__(self, name, health, num_arrows):
super().__init__(name, health)
self.__num_arrows = num_arrows
def shoot(self, target):
if self.__num_arrows <= 0:
raise Exception("not enough arrows")
self.__num_arrows -= 1
target.take_damage(10)
# don't touch above this line
class Wizard(Hero):
def __init__(self, name, health, mana):
super().__init__(name, health)
self.__mana = mana
def cast(self, target):
if self.__mana < 25:
raise Exception("not enough mana")
else:
self.__mana -= 25
target.take_damage(25)