diff --git a/src/game/game.py b/src/game/game.py index 27e45c0..5a64dd2 100644 --- a/src/game/game.py +++ b/src/game/game.py @@ -15,7 +15,7 @@ class Game: self._create_grid_surface() self.sprites = pygame.sprite.Group() - self.tetromino = Tetromino(group=self.sprites) + self.tetromino = Tetromino(self.sprites, self.create_new_tetromino) self.timers = Timers( Timer(CONFIG.game.initial_speed, True, self.move_down), @@ -62,6 +62,9 @@ class Game: def move_right(self) -> None: self.tetromino.move_horizontal(Direction.RIGHT) + def create_new_tetromino(self) -> None: + self.tetromino = Tetromino(self.sprites, self.create_new_tetromino) + def _create_grid_surface(self) -> None: self.grid_surface = self.surface.copy() self.grid_surface.fill("#00ff00") diff --git a/src/game/tetromino.py b/src/game/tetromino.py index f20c773..e4d6725 100644 --- a/src/game/tetromino.py +++ b/src/game/tetromino.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Callable, Optional import pygame from utils import CONFIG, Direction, Figure, FigureConfig, Size @@ -8,11 +8,15 @@ from .block import Block class Tetromino: def __init__( - self, group: pygame.sprite.Group, shape: Optional[Figure] = None + self, + group: pygame.sprite.Group, + func: Callable[[None], None], + shape: Optional[Figure] = None, ) -> None: self.figure: FigureConfig = shape.value if shape else Figure.random().value self.block_positions: list[pygame.Vector2] = self.figure.shape self.color: str = self.figure.color + self.create_new = func self.blocks = [ Block(group=group, pos=pos, color=self.color) @@ -23,6 +27,8 @@ class Tetromino: if not self._check_horizontal_collision(self.blocks, Direction.DOWN): for block in self.blocks: block.pos.y += 1 + else: + self.create_new() def move_horizontal(self, direction: Direction) -> None: if not self._check_vertical_collision(self.blocks, direction):