diff --git a/src/game/game.py b/src/game/game.py index 873cd97..537785e 100644 --- a/src/game/game.py +++ b/src/game/game.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Callable, Optional import numpy as np import pygame @@ -11,13 +11,15 @@ from .timer import Timer, Timers class Game: - def __init__(self) -> None: + def __init__(self, get_next_shape: Callable[[], Figure]) -> None: self.surface = pygame.Surface(CONFIG.game.size) self.dispaly_surface = pygame.display.get_surface() self.rect = self.surface.get_rect(topleft=CONFIG.game.pos) self.sprites: pygame.sprite.Group[Block] = pygame.sprite.Group() + self.get_next_shape = get_next_shape + self._create_grid_surface() self.field = self._generate_empty_field() @@ -91,6 +93,7 @@ class Game: self.sprites, self.create_new_tetromino, self.field, + self.get_next_shape(), ) def _create_grid_surface(self) -> None: diff --git a/src/game/main.py b/src/game/main.py index 9d818bf..a21bf40 100644 --- a/src/game/main.py +++ b/src/game/main.py @@ -1,11 +1,13 @@ import sys import pygame -from utils import CONFIG +from utils import CONFIG, Figure from .game import Game +from .log import log from .preview import Preview from .score import Score +from .tetromino import Tetromino class Main: @@ -16,7 +18,9 @@ class Main: self.display_surface.fill(CONFIG.colors.bg) self.clock = pygame.time.Clock() - self.game = Game() + self.next_shapes = self._generate_next_shapes() + + self.game = Game(self._get_next_shape) self.score = Score() self.preview = Preview() @@ -46,3 +50,11 @@ class Main: def exit(self) -> None: pygame.quit() sys.exit() + + def _generate_next_shapes(self, amount: int = 3) -> list[Figure]: + return [Figure.random() for _ in range(amount)] + + def _get_next_shape(self) -> Figure: + next_shape = self.next_shapes.pop(0) + self.next_shapes.append(Figure.random()) + return next_shape