jg
jgj
from tkinter import * # графическая библиотека
from random import shuffle # перемешать список suffle(A)
column = 3 # столбцы
row = 3 # строки
btn = []
playground = list('ЧТОЕСТЖУ ') # виртуальное игровое поле
def play(n): # функция обработчик нажатия на кнопку
m = playground.index(' ') # найти индекс пробела
if n in [m+1, m-1] and m // column == n // column or n in [m-column, m+column]:
playground[n], playground[m] = playground[m], playground[n]
btn[m].config(text=playground[m])
btn[n].config(text=playground[n])
for i in range(row):
f = Frame() # Фрейм
f.pack(expand=YES, fill=BOTH) # Вывод фрейма на экран
for j in range(column):
n = i * column + j
btn += [Button(f)]
btn[n].pack(expand=YES, fill=BOTH, side=LEFT)
btn[n].config(width=3, height=2)
btn[n].config(text=playground[n])
btn[n].config(command=lambda n=n: play(n))
mainloop() # главный цикл программы
Прог. 1.
from tkinter import * # графическая библиотека
from random import shuffle # перемешать список suffle(A)
column = 4 # столбцы
row = 4 # строки
btn = []
playground = list(range(1, row*column)) + [' '] # виртуальное игровое поле
def play(n): # функция обработчик нажатия на кнопку
m = playground.index(' ') # найти индекс пробела
if n in [m+1, m-1] and m // column == n // column or n in [m-column, m+column]:
playground[n], playground[m] = playground[m], playground[n]
btn[m].config(text=playground[m])
btn[n].config(text=playground[n])
for i in range(row):
f = Frame() # Фрейм
f.pack(expand=YES, fill=BOTH) # Вывод фрейма на экран
for j in range(column):
n = i * column + j
btn += [Button(f)]
btn[n].pack(expand=YES, fill=BOTH, side=LEFT)
btn[n].config(width=3, height=2)
btn[n].config(text=playground[n])
btn[n].config(command=lambda n=n: play(n))
mainloop() # главный цикл программы
Прог. 2.
# This is my version of the game, known as mines or Puzzle15.
#
# Created on October 21, 2023.
# Author: Diorditsa A.
#
# puzzle15.py is distributed in the hope that it will be useful, but
# WITHOUT WARRANTY OF ANY KIND; not even an implied warranty
# MARKETABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See. See the GNU General Public License for more information.
# You can get a copy of the GNU General Public License
# by link http://www.gnu.org/licenses/
from tkinter import * # графическая библиотека
from random import choice # перемешать список suffle(A)
column = 4 # столбцы
row = 4 # строки
btn = []
playground = list(range(1, row*column)) + [' '] # виртуальное игровое поле
def play(n): # функция обработчик нажатия на кнопку
m = playground.index(' ') # найти индекс пробела
if n in [m+1, m-1] and m // column == n // column or n in [m-column, m+column]:
playground[n], playground[m] = playground[m], playground[n]
btn[m].config(text=playground[m])
btn[n].config(text=playground[n])
for i in range(row):
f = Frame() # Фрейм
f.pack(expand=YES, fill=BOTH) # Вывод фрейма на экран
for j in range(column):
n = i * column + j
btn += [Button(f)]
btn[n].pack(expand=YES, fill=BOTH, side=LEFT)
btn[n].config(width=3, height=2)
btn[n].config(text=playground[n])
btn[n].config(command=lambda n=n: play(n))
for i in range(100000): # перемешать пазл
play(choice(range(row*column)))
mainloop() # главный цикл программы
Прог. 3. С перемешиванием цифр.
Рис. 1.