-
Notifications
You must be signed in to change notification settings - Fork 0
/
utility.py
60 lines (45 loc) · 1.99 KB
/
utility.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import pygame
from config import *
from random import randint
def image_load(path, size, alpha=True):
image = pygame.image.load(path)
image = pygame.transform.scale(image, size)
if alpha:
image = image.convert_alpha()
else:
image = image.convert()
return image
def draw_grid(display, x: int, y: int) -> None:
pygame.draw.rect(display, GRID_COLOR,
pygame.Rect(LEFT + x * BLOCK_SIZE, y * BLOCK_SIZE + TOP, BLOCK_SIZE, BLOCK_SIZE), 1)
def draw_new_grid(display) -> None:
pygame.draw.rect(display, GRID_COLOR,
pygame.Rect(LEFT + 11 * BLOCK_SIZE, 1 * BLOCK_SIZE + TOP, BLOCK_SIZE * 4, BLOCK_SIZE * 4), 2)
def draw_figure(display, x: int, y: int, color: str) -> None:
pygame.draw.rect(display, color, pygame.Rect(LEFT + x * BLOCK_SIZE, y * BLOCK_SIZE + TOP, BLOCK_SIZE, BLOCK_SIZE))
pygame.draw.rect(display, GRID_COLOR,
pygame.Rect(LEFT + x * BLOCK_SIZE, y * BLOCK_SIZE + TOP, BLOCK_SIZE, BLOCK_SIZE), 2)
def draw_blocks(display, x: int, y: int) -> None:
pygame.draw.rect(display, BLOCKS_COLOR,
pygame.Rect(LEFT + x * BLOCK_SIZE, y * BLOCK_SIZE + TOP, BLOCK_SIZE, BLOCK_SIZE))
pygame.draw.rect(display, GRID_COLOR,
pygame.Rect(LEFT + x * BLOCK_SIZE, y * BLOCK_SIZE + TOP, BLOCK_SIZE, BLOCK_SIZE), 2)
def line_go_down(ind: int, lst: list) -> list:
for i in range(0, ind):
if i in lst:
lst[lst.index(i)] += 10
return lst
def check_break_lines(lst: list, g: int, score: int, lines: int) -> [list, int, int, int]:
lst = sorted(lst)
cnt = 0
for i in range(0, 191, 10):
if (i + 9 in lst and i in lst) and lst.index(i + 9) - lst.index(i) == 9:
# CLEAR_LINE_SOUND.play()
for j in range(i, i + 10):
lst.remove(j)
line_go_down(i, lst)
cnt += 1
lines += 1
g = 1.75 + lines // 30
score += POINTS[cnt]
return lst, g, score, lines