python 吃豆人_用tkinter编写的伪吃豆人

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值