Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from random import randrange
- import copy
- #Массив заполненных точек
- all_block_points = []
- #Идентификатор анимации
- id_after = 0
- root = Tk()
- root.geometry("305x500+200+100")
- root.title("TETRIS")
- canv = Canvas(root, heigh=500, width=305, bg = 'white')
- canv.pack()
- def paint(type):
- global current_fig_points, current_fig_type
- for k in current_fig_points:
- canv.itemconfig(str(k[0])+"_"+str(k[1]),fill=type)
- def new_figure():
- global current_fig_points, current_fig_type
- anyfigure = randrange(1,4)
- if anyfigure == 1:
- current_fig_points = copy.deepcopy(palka)
- if anyfigure == 2:
- current_fig_points = copy.deepcopy(box)
- if anyfigure == 3:
- current_fig_points = copy.deepcopy(z_left)
- if anyfigure == 4:
- current_fig_points = copy.deepcopy(z_right)
- def left(event):
- #реализация функции влево
- global current_fig_points, current_fig_type
- paint("white")
- if current_fig_points[0][0] > 0 :
- for k in current_fig_points:
- k[0] -=1
- paint("black")
- def right(event):
- #реализация функции вправо
- global current_fig_points, current_fig_type
- paint("white")
- if current_fig_points[1][0] == 9:
- for k in current_fig_points:
- k[0] += 1
- paint("black")
- def down(event):
- #реализация функции спуска фигуры
- pass
- def rotate(event):
- #реализует поворот фигуры
- pass
- def pausing(event):
- #реализует паузу в игры
- pass
- box = [[3,0],[3,1],[4,0],[4,1]]
- palka = [[3,0],[4,0],[5,0],[6,0]]
- z_left = [[3,0],[4,0],[4,1],[5,1]]
- z_right = [[3,1],[4,1],[4,0],[5,0]]
- for i in range(10):
- for j in range(16):
- xn = i*30 + 2
- yn = j*30 + 2
- xk = xn + 30
- yk = yn + 30
- canv.create_rectangle(xn,yn,xk,yk,width=1,outline="gray",tag=str(i)+"_"+str(j))
- root.after(1000,down)
- root.bind("<Left>",left)
- root.bind("<Right>",right)
- root.bind("<Down>",down)
- root.bind("<Return>",rotate)
- root.bind("<Escape>",pausing)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement