from tkinter import*
import time
import random
import tkinter.messagebox
tk=Tk()
tk.title("雷雷四子球小游戏")
tk.resizable(0,0)
tk.wm_attributes("-topmost",1)
canvas = Canvas(tk,width=700,height=700,bd=0,highlightthickness=0)
canvas.pack()
tk.update
class dlines:
def cff(self,canvas,i):
self.canvas=canvas
self.x=0
self.i=[100,200,300,400,500,600]
self.canvas.create_line(100,i,600,i)
self.canvas.create_line(i,100,i,600)
dlines=dlines()
dlines.cff(canvas,100)
dlines.cff(canvas,600)
dlines.cff(canvas,200)
dlines.cff(canvas,300)
dlines.cff(canvas,400)
dlines.cff(canvas,500)
class ball:
def __init__(self,y):
self.y=y
self.y0=10
def ass(self,idd,positiony):
for x in range(0,200):
position=canvas.coords(idd)
if(position[1]==positiony):
self.y0=0
canvas.move(idd,0,self.y0)
self.y+=10
tk.update()
time.sleep(0.05)
class clsposition:
def __init__(self,positon):
self.position=positon
self.positions=[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0] ]
self.colorx="blue"
'''
class downoval:
def down(idd):
balls=ball(40)
balls.ass(idd,400)
'''
clsposition=clsposition("0")
def action(event):
downx=0
if(clsposition.colorx=="blue"):
clsposition.colorx="red"
else:
clsposition.colorx="blue"
if(event.x>=100 and event.x<200):
idd=canvas.create_oval(100,40,200,140,fill=clsposition.colorx)
for x in range(4,-1,-1):
if (clsposition.positions[0][x]==0):
if(clsposition.colorx=="blue"):
clsposition.positions[0][x]=1
else:
clsposition.positions[0][x]=2
downx=x
break
if(event.x>=200 and event.x<300):
idd=canvas.create_oval(200,40,300,140,fill=clsposition.colorx)
for x in range(4,-1,-1):
if (clsposition.positions[1][x]==0):
if(clsposition.colorx=="blue"):
clsposition.positions[1][x]=1
else:
clsposition.positions[1][x]=2
downx=x
break
if(event.x>=300 and event.x<400):
idd=canvas.create_oval(300,40,400,140,fill=clsposition.colorx)
for x in range(4,-1,-1):
if (clsposition.positions[2][x]==0):
if(clsposition.colorx=="blue"):
clsposition.positions[2][x]=1
else:
clsposition.positions[2][x]=2
downx=x
break
if(event.x>=400 and event.x<500):
idd=canvas.create_oval(400,40,500,140,fill=clsposition.colorx)
for x in range(4,-1,-1):
if (clsposition.positions[3][x]==0):
if(clsposition.colorx=="blue"):
clsposition.positions[3][x]=1
else:
clsposition.positions[3][x]=2
downx=x
break
if(event.x>=500 and event.x<600):
idd=canvas.create_oval(500,40,600,140,fill=clsposition.colorx)
for x in range(4,-1,-1):
if (clsposition.positions[4][x]==0):
if(clsposition.colorx=="blue"):
clsposition.positions[4][x]=1
else:
clsposition.positions[4][x]=2
downx=x
break
balls=ball(40)
newdownx=downx*100+100
balls.ass(idd,newdownx)
canvas.bind('',action)