该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import tkinterbrick=((1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1), (1,0,1,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1), (1,0,1,0,1,0,1,0,1,1,0,1,0,0,1,0,1,1,1,0,1,1,0,1), (1,0,1,0,0,0,1,0,1,0,0,0,0,1,1,0,0,0,0,0,0,1,0,1), (1,0,0,0,0,0,0,0,1,0,1,0,0,1,1,0,1,0,0,1,0,1,0,1), (1,0,1,1,1,0,1,0,0,0,0,1,0,1,1,0,1,0,0,0,0,0,0,1), (1,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,1,1,0,1), (1,1,0,1,0,1,1,0,0,1,0,1,0,0,0,0,1,0,0,0,0,0,0,1), (1,0,0,1,0,0,0,0,1,0,0,1,0,1,0,1,1,0,1,0,1,0,0,1), (1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1), (1,0,1,1,1,0,1,1,0,1,1,1,1,0,1,1,0,1,0,1,0,1,0,1), (1,0,1,0,0,0,1,0,0,0,0,0,1,0,1,1,0,1,0,1,0,1,0,1), (1,0,1,0,1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,1,0,1), (1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,1,1,1,0,1,0,1), (1,0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,0,0,0,0,0,0,0,1), (1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,1,0,1), (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1))b_w=26route=[((j+1)*b_w,(i+1)*b_w)for j in range(len(brick[0])) for i in range(len(brick)) if brick[i][j]==0]point_route=route[:]score_p=len(point_route)*10step=0x,y=route[0]Ai_pos=[route[-1],route[-15],route[13]]
def create_point(self,x,y,width=1,fill=None,tags=None): self.create_oval(x-width/2.0,y-width/2.0,x+width/2.0,y+width/2.0,fill=fill,outline=fill,tags=tags)tkinter.Canvas.create_point=create_point
def leave(event): root.destroy()
def map(): cv.create_rectangle(b_w/2,b_w/2,(len(brick[0])+0.5)*b_w,(len(brick)+0.5)*b_w,fill='gray') for i in range(len(brick)): for j in range(len(brick[0])): b_wm=(j+1)*b_w b_hm=(i+1)*b_w if brick[i][j]==1: cv.create_rectangle(b_wm-b_w/2,b_hm-b_w/2,b_wm+b_w/2,b_hm+b_w/2,fill='orange')
def point(): for i in cv.find_withtag('p'): cv.delete(i) global point_route,score,step try: point_route.remove((x,y)) except: pass for (point_x,point_y) in point_route: cv.create_point(point_x,point_y,width=b_w/2,fill='yellow',tags='p') step+=1 score=score_p-len(point_route)*10 cv.create_text((40,25),text='Score : %d\nStrp : %d'%(score,step),fill='blue',tags='p') if point_route==[]: print('Congratulation,you won!Your score is',score-step) root.quit() return None
def Ai(): global Ai_pos for i in range(len(Ai_pos)): if (x,y) in Ai_pos: print('You lose!Your score is',score-step) root.quit() return None Ai_route=[j for j in ((Ai_pos[i][0],Ai_pos[i][1]-b_w), (Ai_pos[i][0],Ai_pos[i][1]+b_w), (Ai_pos[i][0]-b_w,Ai_pos[i][1]), (Ai_pos[i][0]+b_w,Ai_pos[i][1])) if j in route] Ai_near=[(abs(j[0]-x),abs(j[1]-y)) for j in Ai_route] Ai_pos_old=Ai_pos[i] Ai_pos[i]=Ai_route[Ai_near.index(min(Ai_near))] Ai_x,Ai_y=(Ai_pos[i][0]-Ai_pos_old[0],Ai_pos[i][1]-Ai_pos_old[1]) if (x,y) in Ai_pos: print('You lose!Your score is',score-step) root.quit() return None cv.move(Ai_p[i],Ai_x,Ai_y)