Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.22 KB | None | 0 0
  1. from tkinter import *
  2. from random import randrange
  3. import copy
  4.  
  5.  
  6. #Массив заполненных точек
  7. all_block_points = []
  8. #Идентификатор анимации
  9. id_after = 0
  10.  
  11.  
  12.  
  13. root = Tk()
  14. root.geometry("305x500+200+100")
  15. root.title("TETRIS")
  16.  
  17. canv = Canvas(root, heigh=500, width=305, bg = 'white')
  18. canv.pack()
  19.  
  20. def paint(type):
  21.     global current_fig_points, current_fig_type
  22.     for k in current_fig_points:
  23.         canv.itemconfig(str(k[0])+"_"+str(k[1]),fill=type)
  24.  
  25. def new_figure():
  26.     global current_fig_points, current_fig_type
  27.     anyfigure = randrange(1,4)
  28.     if anyfigure == 1:
  29.         current_fig_points = copy.deepcopy(palka)
  30.     if anyfigure == 2:
  31.         current_fig_points = copy.deepcopy(box)
  32.     if anyfigure == 3:
  33.         current_fig_points = copy.deepcopy(z_left)
  34.     if anyfigure == 4:
  35.         current_fig_points = copy.deepcopy(z_right)
  36.  
  37.  
  38. def left(event):
  39.     #реализация функции влево
  40.     global current_fig_points, current_fig_type
  41.     paint("white")
  42.     if current_fig_points[0][0] > 0 :
  43.         for k in current_fig_points:
  44.             k[0] -=1
  45.     paint("black")
  46.  
  47. def right(event):
  48.     #реализация функции вправо
  49.     global current_fig_points, current_fig_type
  50.     paint("white")
  51.     if current_fig_points[1][0] == 9:
  52.         for k in current_fig_points:
  53.             k[0] += 1
  54.     paint("black")
  55.  
  56. def down(event):
  57.     #реализация функции спуска фигуры
  58.     pass
  59.  
  60. def  rotate(event):
  61.     #реализует поворот фигуры
  62.     pass
  63.  
  64. def pausing(event):
  65.     #реализует паузу в игры
  66.     pass
  67.  
  68.  
  69.  
  70. box = [[3,0],[3,1],[4,0],[4,1]]
  71. palka = [[3,0],[4,0],[5,0],[6,0]]
  72. z_left = [[3,0],[4,0],[4,1],[5,1]]
  73. z_right = [[3,1],[4,1],[4,0],[5,0]]
  74.  
  75. for i in range(10):
  76.     for j in range(16):
  77.         xn = i*30 + 2
  78.         yn = j*30 + 2
  79.         xk = xn + 30
  80.         yk = yn + 30
  81.         canv.create_rectangle(xn,yn,xk,yk,width=1,outline="gray",tag=str(i)+"_"+str(j))
  82.  
  83. root.after(1000,down)
  84.  
  85. root.bind("<Left>",left)
  86. root.bind("<Right>",right)
  87. root.bind("<Down>",down)
  88. root.bind("<Return>",rotate)
  89. root.bind("<Escape>",pausing)
  90.  
  91. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement