forked from nyjc-computing/j1-summary-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharacter.py
More file actions
52 lines (37 loc) · 1.07 KB
/
character.py
File metadata and controls
52 lines (37 loc) · 1.07 KB
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
import random
class Character:
def __init__(self, _type, health, damage = 0):
self._type = _type
self.health = health
self.damage = damage
def attack(self, character):
"""
Deal damage to another character object
"""
character.receive_damage(self.damage)
# print("Die")
def receive_damage(self, damage):
"""
Remove health
"""
self.health -= damage
# print("Ouch")
def isdead(self):
"""
Returns status of character (dead or alive)
"""
return self.health <= 0
def get_health(self):
return self.health
def get_type(self):
return self._type
class Player(Character):
def __init__(self, health, damage):
super().__init__("Player", health, damage)
class Soldier(Character):
def __init__(self, health):
super().__init__("Soldier", health)
self.damage = random.randint(2,7)
class Princess(Character):
def __init__(self, health):
super().__init__("Princess", health)