Repository navigation
Expand file tree
/
Copy pathFire.py
More file actions
127 lines (113 loc) · 7.39 KB
/
Copy pathFire.py
File metadata and controls
127 lines (113 loc) · 7.39 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
from vertices_and_edges import VerticesAndEdges
class Fire:
def __init__(self, fire_list, all_tiles_list, all_tiles_dict, canvas, width, height):
self.fire_list = fire_list
self.all_tiles_list = all_tiles_list
self.all_tiles_dict = all_tiles_dict
self.dataset = VerticesAndEdges(self.all_tiles_list, self.all_tiles_dict)
self.canvas = canvas
self.width = width
self.height = height
# self.fire_values = fire_values
def get_fire_list(self):
return self.fire_list
def spread_fire(self):
fire_list2 = []
for tile in self.fire_list:
x = tile.x
y = tile.y
tile.set_on_fire(self.canvas, x * self.width, y * self.height, self.width, self.height, "red2")
# print(x, y)
# print(tile.flammable)
# top left cell
if x - 1 >= 0 and y - 1 >= 0 and self.all_tiles_dict[x - 1][y - 1] is not None and \
self.all_tiles_dict[x - 1][
y - 1].flammable == "Yes":
# print("past1")
self.all_tiles_dict[x - 1][y - 1].set_on_fire(self.canvas,
self.all_tiles_dict[x - 1][y - 1].x * self.width,
self.all_tiles_dict[x - 1][y - 1].y * self.height,
self.width, self.height, "tomato")
# top up same column
if y - 1 >= 0 and self.all_tiles_dict[x][y - 1] is not None and self.all_tiles_dict[x][
y - 1].flammable == "Yes":
# print("past2")
self.all_tiles_dict[x][y - 1].set_on_fire(self.canvas,
self.all_tiles_dict[x][y - 1].x * self.width,
self.all_tiles_dict[x][y - 1].y * self.height,
self.width,
self.height, "gold")
fire_list2.append(self.all_tiles_dict[x][y - 1])
# top right
if x + 1 <= 99 and y - 1 >= 0 and self.all_tiles_dict[x + 1][y - 1] is not None and \
self.all_tiles_dict[x + 1][
y - 1].flammable == "Yes":
# print("past3")
self.all_tiles_dict[x + 1][y - 1].set_on_fire(self.canvas,
self.all_tiles_dict[x + 1][y - 1].x * self.width,
self.all_tiles_dict[x + 1][y - 1].y * self.height,
self.width, self.height, "burlywood4")
var = self.all_tiles_dict[x + 1][y - 1].x
var2 = self.all_tiles_dict[x + 1][y - 1].y
fire_list2.append(self.all_tiles_dict[x + 1][y - 1])
# self.canvas.create_rectangle((x+1)*self.width, (y-1)*self.height, (x+1)*self.width + self.width, (y-1)*self.height + self.height, fill="Cyan2", outline="OrangeRed2")
# same level left
if x - 1 >= 0 and self.all_tiles_dict[x - 1][y] is not None and self.all_tiles_dict[x - 1][
y].flammable == "Yes":
# rint("past4")
self.all_tiles_dict[x - 1][y].set_on_fire(self.canvas,
self.all_tiles_dict[x - 1][y].x * self.width,
self.all_tiles_dict[x - 1][y].y * self.height,
self.width,
self.height, "indian red")
fire_list2.append(self.all_tiles_dict[x - 1][y])
# same level right
if x + 1 <= 99 and self.all_tiles_dict[x + 1][y] is not None and self.all_tiles_dict[x + 1][
y].flammable == "Yes":
# print("past5")
self.all_tiles_dict[x + 1][y].set_on_fire(self.canvas,
self.all_tiles_dict[x + 1][y].x * self.width,
self.all_tiles_dict[x + 1][y].y * self.height,
self.width,
self.height, "orange")
fire_list2.append(self.all_tiles_dict[x + 1][y])
# bottom left
if x - 1 >= 0 and y + 1 <= 99 and self.all_tiles_dict[x - 1][y + 1] is not None and \
self.all_tiles_dict[x - 1][
y + 1].flammable == "Yes":
# print("past6")
self.all_tiles_dict[x - 1][y + 1].set_on_fire(self.canvas,
self.all_tiles_dict[x - 1][y + 1].x * self.width,
self.all_tiles_dict[x - 1][y + 1].y * self.height,
self.width, self.height, "hot pink")
fire_list2.append(self.all_tiles_dict[x - 1][y + 1])
# same column bottom down
if y + 1 <= 99 and self.all_tiles_dict[x][y + 1] is not None and self.all_tiles_dict[x][
y + 1].flammable == "Yes":
# print("past7")
self.all_tiles_dict[x][y + 1].set_on_fire(self.canvas,
self.all_tiles_dict[x][y + 1].x * self.width,
self.all_tiles_dict[x][y + 1].y * self.height,
self.width,
self.height, "dark violet")
fire_list2.append(self.all_tiles_dict[x][y + 1])
# bottom right
if x + 1 <= 99 and y + 1 <= 99 and self.all_tiles_dict[x + 1][y + 1] is not None and \
self.all_tiles_dict[x + 1][
y + 1].flammable == "Yes":
# print("past8")
self.all_tiles_dict[x + 1][y + 1].set_on_fire(self.canvas,
self.all_tiles_dict[x + 1][y + 1].x * self.width,
self.all_tiles_dict[x + 1][y + 1].y * self.height,
self.width, self.height, "khaki")
fire_list2.append(self.all_tiles_dict[x + 1][y + 1])
# for tile in self.fire_list:
# print(tile.x, tile.y,)
# for tile in fire_list2:
# print(tile.x, tile.y, )
self.fire_list.clear()
# print(self.fire_list)
self.fire_list.extend(fire_list2)
# print(self.fire_list)
if len(self.fire_list) != 0:
self.spread_fire()