代码如下:
#coding=utf-8
import random, sys, time
from Tkinter import *
def timing(out_prefix, func, *args, **kwargs):
print("%s:timing start..."%(out_prefix))
t1 = time.time()
r = func(*args, **kwargs)
t2 = time.time()
print("%s:%ss"%(out_prefix, t2 - t1))
return r
class UI:
def __init__(self, maze):
self.maze = maze
self.w, self.b = 1, 2
self.root, self.canvas = None, None
def output_cell(self, clac_func):
self.root = Tk()
self.root.title('MAZE')
self.canvas = Canvas(self.root, width=self.maze.width*self.w*4+self.w+self.b*2-4, height=self.maze.heigh*self.w*4+self.w+self.b*2-4)
self.canvas.create_rectangle(self.b, self.b, self.maze.width*self.w*4+self.w+self.b, self.b+self.w, fill='dimgray', width = 0)
self.canvas.create_rectangle(self.b, self.b, self.b+self.w, self.maze.heigh*self.w*4+self.w+self.b, fill='dimgray', width = 0)
for y in range(self.maze.heigh):
for x in range(self.maze.width):
if not self.maze.cells[x][y].is_open(Cell.EDGE_RIGHT):
self.canvas.create_rectangle(self.b+(x+1)*self.w*4, self.b+y*self.w*4, self.b+(x+1)*self.w*4+self.w, self.b+y*self.w*4+self.w*5, fill='dimgray', width = 0)
if not self.maze.cells[x][y].is_open(Cell.EDGE_BOTTOM):
self.canvas.create_rectangle(self.b+x*self.w*4, self.b+(y+1)*self.w*4, self.b+x*self.w*4+self.w*5, self.b+(y+1)*self.w*4+self.w, fill='dimgray', width = 0)
self.canvas.pack()
self.root.bind('<Button-1>', clac_func)
self.root.mainloop()
def output_path(self, paths, entrance, exit):
self.canvas.create_rectangle(self.b+entrance[0]*self.w*4+self.w, self.b+entrance[1]*self.w*4+self.w, self.b+entrance[0]*self.w*4+self.w+