почему при запуске появляется не одна моделька, а бесконечное количество

r4tafa

Новичок
Пользователь
Мар 4, 2023
1
0
1
import pygame
import random
import copy
pygame.init()
I_max = 11
J_max = 21
screen_x = 300
screen_y = 600
screen = pygame.display.set_mode((screen_x, screen_y))
clock = pygame.time.Clock()
pygame.display.set_caption("Tetris Pixel Game")
dx = screen_x/(I_max - 1)
dy = screen_y/(J_max - 1)
fps = 60
grid = []

details = [
[[-2, 0], [-1, 0], [0, 0], [1, 0]],
[[-1, 1], [-1, 0], [0, 0], [1, 0]],
[[1, 1], [-1, 0], [0, 0], [1, 0]],
[[-1, 1], [0, 1], [0, 0], [-1, 0]],
[[1, 0], [1, 1], [0, 0], [-1, 0]],
[[0, 1], [-1, 0], [0, 0], [1, 0]],
[[-1, 1], [0, 1], [0, 0], [1, 0]],
]
det = [[],[],[],[],[],[],[]]
for i in range(0, len(details)):
for j in range(0, 4):
det.append(pygame.Rect(details[j][0]*dx + dx*(I_max//2), details[j][1]*dy, dx, dy))


game = True
rotate = False
while game:
detail = pygame.Rect(0, 0, dx, dy)
det_choice = (random.choice(det))
count = 0
delta_x = 0
delta_y = 1
for i in range(0, I_max):
grid.append([])
for j in range(0, J_max):
grid.append([1])
for i in range(0, I_max):
for j in range(0, J_max):
grid[j].append(pygame.Rect(i*dx, j*dy, dx, dy))
grid[j].append(pygame.Color("Green"))

for event in pygame.event.get():
if event.type == pygame.QUIT:
game = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
delta_x = -1
elif event.key == pygame.K_RIGHT:
delta_x = 1
elif event.key == pygame.K_UP:
rotate = True
key = pygame.key.get_pressed()
if key[pygame.K_DOWN]:
count = 31 * fps
screen.fill(pygame.Color("Black"))
for i in range(0, I_max):
for j in range(0, J_max):
pygame.draw.rect(screen, grid[j][2], grid[j][1], grid[j][0])
for i in range(4):
if ((det_choice.x + delta_x * dx < 0) or (det_choice.x + delta_x * dx >= screen_x)):
delta_x = 0
if ((det_choice.y + dy >= screen_y) or (grid[int(det_choice.x//dx)][int(det_choice.y//dy) + 1][0] == 0)):
delta_y = 0
for i in range(4):
x = int(det_choice.x // dx)
y = int(det_choice.y // dy)
grid[x][y][0] = 0
grid[x][y][1] = pygame.Color("White")
detail.x = 0
detail.y = 0
det_choice = (random.choice(det))
for i in range(4):
det_choice.x += delta_x*dx
count = 1
if count > 30 * fps:
for i in range(4):
det_choice.y += 0
count = 0
for i in range(4):
detail.x = det_choice.x
detail.y = det_choice.y
pygame.draw.rect(screen, pygame.Color("White"), detail)
C = det_choice[2]
if rotate == True:
for i in range(4):
x = det_choice.y - C.y
y = det_choice.x - C.x
det_choice.x = C.x - x
det_choice.y = C.y + y
rotate = False
for j in range(J_max - 1, -1, -1):
count_cells = 0
for i in range(0, I_max):
if grid[j][0] == 0:
count_cells += 1
elif grid[j][0] == 1:
break
if count_cells == (I_max - 1):
for l in range(0, I_max):
grid[l][0][0] = 1
for k in range(j, -1, -1):
for l in range(0, I_max):
grid[l][k][0] = grid[l][k-1][0]
pygame.display.flip()
clock.tick(fps)
 

4olshoy_blen

Популярный
Пользователь
Ноя 13, 2022
372
107
43
Потому что для начала надо код вставлять как код, с отступами
 
  • Мне нравится
Реакции: regnor

Форум IT Специалистов