-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreading_building_plan.py
More file actions
117 lines (87 loc) · 3.69 KB
/
Copy pathreading_building_plan.py
File metadata and controls
117 lines (87 loc) · 3.69 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
import threading
from tkinter import *
import pickle
from Fire import Fire
from Person import Person
f = open("temp_for_file_name.txt", "r")
name = f.read()
# print(name)
f.close()
root = Tk()
root.title("")
width = root.winfo_screenwidth() # width of screen
height = root.winfo_screenheight() # height of screen
divisions = 100
width_of_tile = width / divisions
height_of_tile = height / divisions
totalSurvivors = 0
casualities = 0
fire_list = []
fire_values = {}
humans_list = []
root.winfo_toplevel().geometry("%dx%d%+d%+d" % (width, height, 0, 0))
radio_selection = "human"
var = StringVar()
human_button = Radiobutton(root, text="Human", variable=var, value="human")
human_button.pack(side=TOP, padx=10)
fire_button = Radiobutton(root, text="Fire", variable=var, value="fire")
fire_button.pack(side=TOP, padx=10)
def fire_thread_task():
global fire_list, all_tiles_dict, all_tiles_list, fire_values
spreader = Fire(fire_list, all_tiles_list, all_tiles_dict, my_canvas, width_of_tile, height_of_tile, fire_values)
spreader.spread_fire()
human_count = 0
def human_thread_task():
global humans_list, all_tiles_dict, all_tiles_list, human_count, humans_list
humans_list[human_count].makeNextMove()
human_count += 1
def submit():
global humans_list, all_tiles_dict, all_tiles_list, humans_list, my_canvas, width_of_tile, height_of_tile
root.unbind("<Button-1>")
human_button.destroy()
fire_button.destroy()
subButton.destroy()
for tile in all_tiles_list:
print(tile.cost_imposed_on_weight)
# start fire thread
fire_thread = threading.Thread(target=fire_thread_task)
fire_thread.start()
# make multiple threads for humans
for human in humans_list:
person = Person(human[0], human[1], all_tiles_list, all_tiles_dict, my_canvas, width_of_tile, height_of_tile, fire_values)
person.start()
subButton = Button(root, text="Submit", command=submit)
subButton.pack()
my_canvas = Canvas(root, width=width, height=height)
my_canvas.pack()
with open(name, "rb") as file:
data = pickle.load(file)
all_tiles_list = data["list"]
all_tiles_dict = data["dictionary"]
# print("Canvas Dimensions:", my_canvas.winfo_width(), my_canvas.winfo_height())
# print(width, height)
for tile in all_tiles_list:
location = tile.get_location()
my_canvas.create_rectangle(location[0] * width_of_tile, location[1] * height_of_tile,
location[0] * width_of_tile + width_of_tile,
location[1] * height_of_tile + height_of_tile, fill=tile.color, outline=tile.color)
def on_click(event):
global radio_selection, fire_list, all_tiles_list, all_tiles_dict, my_canvas, width_of_tile, height_of_tile
x, y = event.x, event.y
x_coord = int(x / width_of_tile)
y_coord = int(y / height_of_tile)
radio_selection = var.get()
if radio_selection == "human":
all_tiles_dict[x_coord][y_coord].increment_population()
my_canvas.create_rectangle(x_coord * width_of_tile, y_coord * height_of_tile,
x_coord * width_of_tile + width_of_tile,
y_coord * height_of_tile + height_of_tile, fill="maroon",
outline="black")
humans_list.append([x_coord, y_coord])
#Person(x_coord, y_coord, all_tiles_list, all_tiles_dict, my_canvas, width_of_tile, height_of_tile))
else:
all_tiles_dict[x_coord][y_coord].set_on_fire(my_canvas, x, y, width_of_tile, height_of_tile, "firebrick1", all_tiles_dict)
fire_list.append(all_tiles_dict[x_coord][y_coord])
fire_values[all_tiles_dict[x_coord][y_coord]] = 3000;
root.bind("<Button-1>", on_click)
root.mainloop()