врывр
аппраер
from tkinter import *
from random import choice
class Peg():
playground = [0]*49
for i in (0, 1, 5, 6, 7, 8, 12, 13, 35, 36, 40, 41, 42, 43, 47, 48):
playground[i]=-1
SIZE = 50
COLORES = ('#aa9', '#776', '#ccd') # Цвета поля
tk = Tk()
FILE = ('red.png', 'yellow.png', 'gold.png', 'green.png', 'emerald.png',
'cyan.png', 'blue.png', 'pink.png', 'azure.png', 'bronze.png',
'purple.png', 'scarlet.png', 'steel.png', 'silver.png')
img = [PhotoImage(file=i) for i in FILE]
cnv = None
def create_window():
Peg.cnv = Canvas(width=Peg.SIZE*7, height=Peg.SIZE*7)
for n in range(49):
x = (n % 7) * Peg.SIZE
y = (n // 7) * Peg.SIZE
Peg.cnv.create_rectangle(x, y, x+Peg.SIZE, y+Peg.SIZE, width=1,
fill=Peg.COLORES[0 if Peg.playground[n] == 0 else 1], outline=Peg.COLORES[2])
Peg.cnv.pack()
def __init__(self, n):
if Peg.cnv == None: Peg.create_window()
x = (n % 7) * Peg.SIZE + Peg.SIZE / 2
y = (n // 7) * Peg.SIZE + Peg.SIZE / 2
self.num = Peg.cnv.create_image(x, y, image=choice(Peg.img), anchor=CENTER, tag='allBalls')
Peg.playground[n] = self.num
Peg.cnv.tag_bind(self.num, '<Button-1>', self.play)
def play(self, event):
Peg.cnv.tkraise(self.num)
Peg.cnv.bind("<B1-Motion>", self.motion)
def motion(self, event):
x = event.x-Peg.cnv.coords(self.num)[0]
y = event.y-Peg.cnv.coords(self.num)[1]
Peg.cnv.move(self.num, x, y)
def newgame(A=[10, 16, 17, 18, 24, 31]):
for i in A:
this = Peg(i)
Peg.SIZE = 70
Peg.tk.title("Игра Peg")
newgame()
mainloop()
Лист. 1.