-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentity.py
More file actions
160 lines (138 loc) · 3.78 KB
/
entity.py
File metadata and controls
160 lines (138 loc) · 3.78 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
"""
COMP 1510 Assignment - Entity Class
"""
# Kevin Mark
# A01067248
# Nov 19, 2018
class Entity:
def __init__(self, hp) -> None:
""" Initialize an Entity Object
PARAM: hp, a positive integer > 0
PRECONDITION: Hp must have a health value greater than 1
POSTCONDITION: Create an entity object with health points
RETURN: None
"""
self.hp = hp
self.dead = False
def reduce_hp_by(self, damage: int) -> None:
""" Reduce entity healthy by 'damage' amount
Note reducing the entities hp below 0 is possible and will kill the entity
PARAM: damage, a integer
PRECONDITION: n/a
POSTCONDITION: n/a
RETURN: None
>>> instance = Entity(10)
>>> instance.reduce_hp_by(5)
>>> instance.get_hp()
5
"""
self.hp -= damage
def hp_less_than_zero(self) -> bool:
""" Return true if HP <= 0
PARAM: n/a
PRECONDITION: n/a
POSTCONDITION: n/a
RETURN: bool
>>> instance = Entity(10)
>>> instance.set_hp(0)
>>> instance.hp_less_than_zero()
True
>>> instance = Entity(10)
>>> instance.set_hp(-1)
>>> instance.hp_less_than_zero()
True
>>> instance = Entity(10)
>>> instance.set_hp(5)
>>> instance.hp_less_than_zero()
False
"""
return self.hp <= 0
def hp_more_than_zero(self) -> bool:
""" Return true if HP > 0
PARAM: n/a
PRECONDITION: n/a
POSTCONDITION: n/a
RETURN: bool
>>> instance = Entity(10)
>>> instance.set_hp(0)
>>> instance.hp_more_than_zero()
False
>>> instance = Entity(10)
>>> instance.set_hp(-1)
>>> instance.hp_more_than_zero()
False
>>> instance = Entity(10)
>>> instance.set_hp(5)
>>> instance.hp_more_than_zero()
True
"""
return self.hp > 0
def add_one_to_hp(self) -> None:
""" Add one to Hp
PARAM: n/a
PRECONDITION: n/a
POSTCONDITION: n/a
RETURN: None
>>> instance = Entity(10)
>>> instance.set_hp(5)
>>> instance.add_one_to_hp()
>>> instance.get_hp()
6
"""
self.hp += 1
def hp_btw_zero_n_ten(self) -> bool:
""" Return true is hp is between 0 and 10, not inclusive
PARAM: n/a
PRECONDITION: n/a
POSTCONDITION: n/a
RETURN: bool
>>> instance = Entity(10)
>>> instance.hp_btw_zero_n_ten()
False
>>> instance = Entity(10)
>>> instance.set_hp(0)
>>> instance.hp_btw_zero_n_ten()
False
>>> instance = Entity(10)
>>> instance.set_hp(5)
>>> instance.hp_btw_zero_n_ten()
True
"""
return 0 < self.hp < 10
# setters/getters
def get_hp(self) -> int:
"""
Return the instance hp
PARAM: n/a
PRECONDITION: n/a
POSTCONDITION: n/a
RETURN: int
"""
return self.hp
def set_hp(self, hp: int) -> None:
"""
Set the instance hp
PARAM: hp, an int
PRECONDITION: You cannot set the instance to zero or less than zero
POSTCONDITION: Set the instance hp
RETURN: None
"""
self.hp = hp
def set_dead(self, dead: bool) -> None:
"""
Set the instance dead status
PARAM: dead, a bool
PRECONDITION: n/a
POSTCONDITION: n/a
RETURN: n/a
"""
self.dead = dead
def get_dead(self) -> bool:
"""
Return the instance dead variable
PARAM: n/a
PRECONDITION: n/a
POSTCONDITION: n/a
RETURN: bool
"""
return self.dead