diff --git a/src/game/screens/button.py b/src/game/screens/button.py index 426022c..acf36b2 100644 --- a/src/game/screens/button.py +++ b/src/game/screens/button.py @@ -37,7 +37,7 @@ class Button(BaseButton, BaseScreen, SceenElement, TextScreen): pass def update(self) -> None: - """Update the button.""" + pass def draw(self, surface: pygame.Surface, pos: tuple[float, float]) -> None: """Draw the button on the button surface.""" diff --git a/src/game/screens/game.py b/src/game/screens/game.py index 19d127a..a429796 100644 --- a/src/game/screens/game.py +++ b/src/game/screens/game.py @@ -1,11 +1,8 @@ from typing import Any import pygame -from loguru import logger from utils import CONFIG, Figure, GameMode -from game.sprites import Tetromino - from .base import BaseScreen from .preview import Preview from .score import Score @@ -16,7 +13,12 @@ class Game(BaseScreen): """ Game class. + Args: + mode: The game mode to start with. + Attributes: + game_mode: The game mode. + settings: The game settings. display_surface: Pygame display surface. clock: Pygame clock. music: Pygame music. @@ -30,7 +32,6 @@ class Game(BaseScreen): def __init__(self, game_mode: GameMode, settings: dict[str, Any]) -> None: self.game_mode = game_mode self.settings = settings - self.paused = False self._initialize_game_components() self._start_background_music() diff --git a/src/game/screens/main.py b/src/game/screens/main.py index 95cc4a4..cf7b622 100644 --- a/src/game/screens/main.py +++ b/src/game/screens/main.py @@ -11,6 +11,13 @@ from .game import Game class Main(BaseScreen, SceenElement, TextScreen): + """ + Main class. + + Args: + mode: The game mode to start with. + """ + def __init__(self, mode: GameMode) -> None: logger.info("Initializing the game") self._initialize_pygame() @@ -29,9 +36,11 @@ class Main(BaseScreen, SceenElement, TextScreen): self._draw_text() def update(self) -> None: + """Update the display.""" pygame.display.update() def handle_events(self) -> None: + """Handle pygame events.""" for event in pygame.event.get(): if event.type == pygame.QUIT: self.exit() @@ -47,10 +56,12 @@ class Main(BaseScreen, SceenElement, TextScreen): button.on_hover(event) def run(self) -> None: + """Run the game loop continuously.""" while True: self.run_game_loop() def run_game_loop(self) -> None: + """Run a single iteration of the game loop.""" if not self.game: self.draw() @@ -62,17 +73,19 @@ class Main(BaseScreen, SceenElement, TextScreen): self.update() def exit(self) -> None: - """Exit the game.""" + """Exit.""" logger.info("Exiting the game") pygame.quit() sys.exit() def play(self) -> "Main": + """Start a the game.""" self._draw_background() self.game = Game(self.game_mode, self.settings) return self def _set_buttons(self) -> None: + """Initialize and set up buttons.""" self.buttons: list[Button] = [ Button("Play", self.play), Button("AI", None), @@ -86,12 +99,14 @@ class Main(BaseScreen, SceenElement, TextScreen): pygame.display.set_caption(CONFIG.window.title) def _draw_background(self) -> None: + """Draw the background on the display surface.""" self.display_surface.fill(CONFIG.colors.bg) def _draw_border(self) -> None: - pass + """Draw a border (not implemented).""" def _initialize_surface(self) -> None: + """Initialize the display surface.""" self.display_surface = pygame.display.set_mode(CONFIG.window.size) def _initialize_rect(self) -> None: @@ -99,7 +114,7 @@ class Main(BaseScreen, SceenElement, TextScreen): self.rect = self.display_surface.get_rect(topright=(0, 0)) def _update_display_surface(self) -> None: - """Do nothing. Not needed in this class.""" + """Update display surface (not implemented).""" def _initialize_increment_height(self) -> None: """Initialize the increment height for positioning text elements/buttons.""" diff --git a/src/game/screens/tetris.py b/src/game/screens/tetris.py index e4da33a..126bf26 100644 --- a/src/game/screens/tetris.py +++ b/src/game/screens/tetris.py @@ -8,7 +8,7 @@ from utils import CONFIG, Direction, Figure, GameMode, Rotation from game.sprites import Block, Tetromino from game.timer import Timer, Timers -from .base import BaseScreen, SceenElement +from .base import BaseScreen class Tetris(BaseScreen): @@ -18,12 +18,15 @@ class Tetris(BaseScreen): Args: get_next_figure: A function to get the next figure. update_score: A function to update the score. + mode: The game mode to start with. Attributes: surface: Surface representing the game. dispaly_surface: Surface representing the display. rect: Rect representing the game surface. sprites: Sprite group for managing blocks. + settings: The game settings. + game_mode: The game mode. get_next_figure: A function to get the next figure. update_score: A function to update the score. grid_surface: Surface representing the grid. diff --git a/src/game/sprites/block.py b/src/game/sprites/block.py index 13b245d..747b88f 100644 --- a/src/game/sprites/block.py +++ b/src/game/sprites/block.py @@ -2,8 +2,7 @@ from typing import Any, Optional import numpy as np import pygame -from loguru import logger -from utils import CONFIG, Rotation, Size +from utils import CONFIG, Rotation class Block(pygame.sprite.Sprite): diff --git a/src/game/sprites/tetromino.py b/src/game/sprites/tetromino.py index 13bc961..ff82bda 100644 --- a/src/game/sprites/tetromino.py +++ b/src/game/sprites/tetromino.py @@ -2,8 +2,7 @@ from typing import Any, Callable, Optional import numpy as np import pygame -from loguru import logger -from utils import CONFIG, Direction, Figure, Rotation, Size +from utils import CONFIG, Direction, Figure, Rotation from .block import Block diff --git a/src/utils/colors/tokyonight/base.py b/src/utils/colors/tokyonight/base.py index 6b27579..b0be0c2 100644 --- a/src/utils/colors/tokyonight/base.py +++ b/src/utils/colors/tokyonight/base.py @@ -1,7 +1,5 @@ from abc import ABC, ABCMeta -from attrs import define - class Color(ABC, metaclass=ABCMeta): bg: str diff --git a/src/utils/figure.py b/src/utils/figure.py index 34de17a..578d180 100644 --- a/src/utils/figure.py +++ b/src/utils/figure.py @@ -1,10 +1,8 @@ import random from enum import Enum -from pathlib import Path from typing import NamedTuple import pygame -from attr import define from pygame import Vector2 as Vec2 from .colors import TokyoNightNight diff --git a/src/utils/settings.py b/src/utils/settings.py index 1514308..1b065c0 100644 --- a/src/utils/settings.py +++ b/src/utils/settings.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import Any, Optional +from typing import Any import toml from loguru import logger diff --git a/src/utils/tuples.py b/src/utils/tuples.py index d545952..9cdacf0 100644 --- a/src/utils/tuples.py +++ b/src/utils/tuples.py @@ -1,7 +1,5 @@ from typing import NamedTuple, Union -from .enum import Direction - class Size(NamedTuple): width: int | float