diff --git a/src/game/screens/game.py b/src/game/screens/game.py index 420ce2a..6836d6a 100644 --- a/src/game/screens/game.py +++ b/src/game/screens/game.py @@ -28,9 +28,9 @@ class Game(BaseScreen): """ def __init__(self, game_mode: GameMode) -> None: + self.game_mode = game_mode self._initialize_game_components() self._start_background_music() - self.game_mode = game_mode # TODO: use this def draw(self) -> None: """Update the display.""" @@ -60,8 +60,8 @@ class Game(BaseScreen): self.clock = pygame.time.Clock() self.next_figure: Figure = self._generate_next_figure() - self.tetris = Tetris(self._get_next_figure, self._update_score) - self.score = Score() + self.tetris = Tetris(self._get_next_figure, self._update_score, self.game_mode) + self.score = Score(self.game_mode) self.preview = Preview() def _update_score(self, lines: int, score: int, level: int) -> None: @@ -97,6 +97,7 @@ class Game(BaseScreen): def _start_background_music(self) -> None: """Start playing background music.""" - self.music = pygame.mixer.Sound(CONFIG.music.background) - self.music.set_volume(CONFIG.music.volume) - self.music.play(-1) + if self.game_mode is GameMode.PLAYER: + self.music = pygame.mixer.Sound(CONFIG.music.background) + self.music.set_volume(CONFIG.music.volume) + self.music.play(-1) diff --git a/src/game/screens/score.py b/src/game/screens/score.py index a63d373..903f318 100644 --- a/src/game/screens/score.py +++ b/src/game/screens/score.py @@ -1,5 +1,5 @@ import pygame -from utils import CONFIG, Size +from utils import CONFIG, GameMode, Size from game.log import log @@ -19,7 +19,8 @@ class Score(BaseScreen, SceenElement, TextScreen): increment_height: Height of each text element in the score. """ - def __init__(self) -> None: + def __init__(self, game_mode: GameMode) -> None: + self.game_mode = game_mode self._initialize_surface() self._initialize_rect() self._initialize_font() @@ -39,13 +40,14 @@ class Score(BaseScreen, SceenElement, TextScreen): score (int): Current game score. level (int): Current game level. """ - self.text: tuple[tuple[str, int], ...] = ( + self.text: list[tuple[str, int], ...] = [ ("Score", score), ("Level", level), ("Lines", lines), ("High Score", CONFIG.game.highscore), - ("Generations", 0), - ) + ] + if self.game_mode in (GameMode.AI_PLAYING, GameMode.AI_TRAINING): + self.text.append(("Generations", 0)) def draw(self) -> None: """Draw the score on the score surface.""" diff --git a/src/game/screens/tetris.py b/src/game/screens/tetris.py index 9a683bf..817503d 100644 --- a/src/game/screens/tetris.py +++ b/src/game/screens/tetris.py @@ -2,7 +2,7 @@ from typing import Any, Callable, Optional import numpy as np import pygame -from utils import CONFIG, Direction, Figure, Rotation +from utils import CONFIG, Direction, Figure, GameMode, Rotation from game.log import log from game.sprites.block import Block @@ -45,6 +45,7 @@ class Tetris(BaseScreen): self, get_next_figure: Callable[[], Figure], update_score: Callable[[int, int, int], None], + game_mode: GameMode, ) -> None: self._initialize_surface() self._initialize_rect() @@ -52,6 +53,7 @@ class Tetris(BaseScreen): self.get_next_figure = get_next_figure self.update_score = update_score + self.game_mode = game_mode self._initialize_grid_surface() self._initialize_field_and_tetromino() @@ -302,8 +304,9 @@ class Tetris(BaseScreen): def _initialize_sound(self) -> None: """Initialize game sounds.""" - self.landing_sound = pygame.mixer.Sound(CONFIG.music.landing) - self.landing_sound.set_volume(CONFIG.music.volume * 2) + if self.game_mode is GameMode.PLAYER: + self.landing_sound = pygame.mixer.Sound(CONFIG.music.landing) + self.landing_sound.set_volume(CONFIG.music.volume * 2) def _play_landing_sound(self) -> None: """Play the landing sound effect."""