-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDragons_Fight.py
More file actions
60 lines (47 loc) · 1.59 KB
/
Dragons_Fight.py
File metadata and controls
60 lines (47 loc) · 1.59 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
def main():
dragons = [
Dragon("Green Dragon", 0, 0, 1),
Dragon("Red Dragon", 2, 2, 2),
Dragon("Blue Dragon", 4, 3, 3),
Dragon("Black Dragon", 5, -1, 4),
]
# don't touch above this line
for dragon in dragons:
describe(dragon)
for dragon in dragons:
dragons_copy = dragons.copy()
del dragons_copy[dragons.index(dragon)]
dragon.breathe_fire(3, 3, dragons_copy)
# don't touch below this line
def describe(dragon):
print(f"{dragon.name} is at {dragon.pos_x}/{dragon.pos_y}")
class Unit:
def __init__(self, name, pos_x, pos_y):
self.name = name
self.pos_x = pos_x
self.pos_y = pos_y
def in_area(self, x_1, y_1, x_2, y_2):
return (
self.pos_x >= x_1
and self.pos_x <= x_2
and self.pos_y >= y_1
and self.pos_y <= y_2
)
class Dragon(Unit):
def __init__(self, name, pos_x, pos_y, fire_range):
super().__init__(name, pos_x, pos_y)
self.__fire_range = fire_range
def breathe_fire(self, x, y, units):
print("====================================")
print(f"{self.name} breathes fire at {x}/{y} with range {self.__fire_range}")
print("------------------------------------")
for unit in units:
in_area = unit.in_area(
x - self.__fire_range,
y - self.__fire_range,
x + self.__fire_range,
y + self.__fire_range,
)
if in_area:
print(f"{unit.name} is hit by the fire")
main()