-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMap.py
63 lines (40 loc) · 1.71 KB
/
Map.py
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
from tkinter import *
class Map:
def __init__(self, cvs):
self.cvs = cvs
self.gen = cvs.create_text(1300, 700,text = "Generation: " + str(1), fill="darkblue",font="Times 20 italic bold")
self.map_lines = [] #Koordinates
self.lines = [] #Line objects
self.starts = []
self.goals = []
def print_map(self, index):
for line in self.map_lines[index]:
l = self.cvs.create_line(line[0][0], line[0][1], line[1][0], line[1][1], width = 3)
self.lines.append(l)
l = self.cvs.create_line(self.goals[index][0] - 70, self.goals[index][1], self.goals[index][0] + 70, self.goals[index][1], width = 5, fill = 'green')
self.lines.append(l)
def erase_map(self):
for line in self.lines:
self.cvs.delete(line)
self.lines.clear()
def generation_control(self, num):
self.cvs.delete(self.gen)
self.gen = self.cvs.create_text(1300, 700,text = "Generation: " + str(num), fill="darkblue",font="Times 20 italic bold")
def load_maps(self, path):
file = open(path, "r")
Lines = file.readlines()
for line in Lines:
line = line.split("-")
temp_list = []
for x in line:
x = x.split('|')
x[0] = x[0].split(',')
x[1] = x[1].split(',')
tup1 = (int(x[0][0]), int(x[0][1]))
tup2 = (int(x[1][0]), int(x[1][1]))
temp_list.append([tup1, tup2])
self.starts.append(temp_list[-1][0])
self.goals.append(temp_list[-1][1])
temp_list.pop(-1)
self.map_lines.append(temp_list)
file.close()