У меня есть код игры парные картинки и у меня возник вопрос, как же мне перемешать их, что было классно.
Вот код
root = Tk()
root.geometry('400x400')
root.title("GAMEXXXXXXXXXXXXXXXX")
def click(event,n,m):
global k,x,y,win,img0,color,count,buttons,img,imgS,imgW,img1
if buttons[n][m]['state']!=DISABLED:
buttons[n][m]['image']=img0[n][m]
root.update()
if k==0:
x=n
y=m
k+=1
return
if k==1 and (n!=x or m!=y):
if str(img[n][m])==str(img[x][y]):
win+=2
time.sleep(0.1)
buttons[n][m]['image']=imgW
buttons[x][y]['image']=imgW
buttons[n][m]['state']=DISABLED
buttons[x][y]['state']=DISABLED
k=0
x=5
y=5
count+=1
if win==16:
time.sleep(1)
won()
return
time.sleep(0.1)
buttons[n][m]['image']=imgS
buttons[x][y]['image']=imgS
k=0
x=5
y=5
count+=1
return
def won():
global img0,color,buttons,img,imgS,imgW,img1,k,win,count
canv1 = Canvas(root,bg='black',width=600, height=500)
canv1.place(x=0,y=0)
l = Label(canv1,text='Ура! Вы победили.\nКоличество ходов: '+str(count),bg = 'green',fg='white',font = 'Arial 14')
l.place(x=50,y=50)
while TRUE:
for i in range(50):
r = random.randint(10,50)
x = random.randint(0, 600)
y = random.randint(0, 500)
canv1.create_oval(x - r, y - r, x + r, y + r, fill=color[random.randint(0, 6)], width=1)
time.sleep(0.001)
canv1.update()
canv1.delete(ALL)
time.sleep(1.5)
def data():
global img0,color,buttons,img,imgS,imgW,img1,k,win,count,f
f=1
img = [ ["1_2.gif","1_3.gif","1_4.gif","1_5.gif"],
["1_6.gif","1_7.gif","1_8.gif","1_9.gif"],
["1_2.gif","1_3.gif","1_4.gif","1_5.gif"],
["1_6.gif","1_7.gif","1_8.gif","1_9.gif"]]
for i in range(4):
img0 = []
buttons = []
k=0
x=5
y=5
win=0
count=0
color=['black','white','brown','blue','red','yellow','green']
imgS=PhotoImage(file="back.gif")
imgW=PhotoImage(file="2f.gif")
for i in range(4):
buttons.append([])
img0.append([])
for j in range(4):
img1=PhotoImage(file=str(img[i][j]))
img0[i].append(img1)
button = Button(root, width = 65, height = 90, image = imgS)
buttons[i].append(button)
buttons[i][j].grid(row = i, column = j)
buttons[i][j].bind('<Button-1>',lambda event, i = i, j = j : click(event, i, j))
def exit_click():
root.destroy()
def help_click():
messagebox.showinfo("Help", "Бог в помощь")
def menu():
main_menu = Menu()
main_menu.add_cascade(label="Игра", command=data)
main_menu.add_cascade(label="Выход", command=exit_click)
main_menu.add_cascade(label="Помощь", command=help_click)
root.config(menu=main_menu)
def check():
global img0,color,buttons,img,imgS,imgW,img1,k,win,count,f
f=0
vx = 2
vy = 1
i=0
j=0
while True:
if f!=1:
t=random.randint(0,1)
g=random.randint(50,150)
h=random.randint(50,250)
for i in range(20):
if f==1:
return
time.sleep(0.04)
g+=vx
h+=vy
if g > 100:
vx *= -1
if h > 200:
vy *= -1.5
h = 200
root.update()
if t==1:
g+=5
else:
g-=5
h+=1
vy += 1
else:
return
menu()
check()
root.mainloop()