mirror of
https://github.com/kristoferssolo/Tetris.git
synced 2025-10-21 20:00:35 +00:00
fix(game): duplicate tetromino on restart
This commit is contained in:
parent
48d5e1d705
commit
cbe01b3951
@ -161,15 +161,18 @@ class Tetris(BaseScreen):
|
|||||||
"""
|
"""
|
||||||
return self.tetromino.drop()
|
return self.tetromino.drop()
|
||||||
|
|
||||||
def create_new_tetromino(self, shape: Optional[Figure] = None) -> Tetromino:
|
def create_new_tetromino(
|
||||||
|
self, shape: Optional[Figure] = None
|
||||||
|
) -> Optional[Tetromino]:
|
||||||
"""Create a new tetromino and perform necessary actions."""
|
"""Create a new tetromino and perform necessary actions."""
|
||||||
self._play_landing_sound()
|
self._play_landing_sound()
|
||||||
self._check_finished_rows()
|
self._check_finished_rows()
|
||||||
self.phantom_tetromino.kill()
|
self.phantom_sprites.empty()
|
||||||
|
|
||||||
self.game_over: bool = self._check_game_over()
|
self.game_over: bool = self._check_game_over()
|
||||||
if self.game_over:
|
if self.game_over:
|
||||||
self.restart()
|
self.restart()
|
||||||
|
return None
|
||||||
|
|
||||||
self.tetromino = Tetromino(
|
self.tetromino = Tetromino(
|
||||||
self.sprites,
|
self.sprites,
|
||||||
@ -186,6 +189,7 @@ class Tetris(BaseScreen):
|
|||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
self.phantom_tetromino.drop()
|
self.phantom_tetromino.drop()
|
||||||
|
logger.debug(f"Created: {self.tetromino.figure.name}")
|
||||||
|
|
||||||
return self.tetromino
|
return self.tetromino
|
||||||
|
|
||||||
@ -204,10 +208,8 @@ class Tetris(BaseScreen):
|
|||||||
|
|
||||||
def restart(self) -> None:
|
def restart(self) -> None:
|
||||||
"""Restart the game."""
|
"""Restart the game."""
|
||||||
logger.info("Restarting the game")
|
logger.info(f"Restarting the game. Score was {self.score}")
|
||||||
self._reset_game_state()
|
self._reset_game_state()
|
||||||
self._initialize_field_and_tetromino()
|
|
||||||
self.game_over = False
|
|
||||||
|
|
||||||
def mute(self) -> None:
|
def mute(self) -> None:
|
||||||
"""Mute the game."""
|
"""Mute the game."""
|
||||||
@ -348,6 +350,8 @@ class Tetris(BaseScreen):
|
|||||||
self.tetromino.figure,
|
self.tetromino.figure,
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
logger.debug(f"Created: {self.tetromino.figure.name}")
|
||||||
self.phantom_tetromino.drop()
|
self.phantom_tetromino.drop()
|
||||||
|
|
||||||
def _initialize_timers(self) -> None:
|
def _initialize_timers(self) -> None:
|
||||||
|
|||||||
@ -29,7 +29,7 @@ class Tetromino:
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
group: pygame.sprite.Group,
|
group: pygame.sprite.Group,
|
||||||
create_new: Optional[Callable[[Optional[Figure]], "Tetromino"]],
|
create_new: Optional[Callable[[Optional[Figure]], Optional["Tetromino"]]],
|
||||||
field: np.ndarray[Optional[Block], Any],
|
field: np.ndarray[Optional[Block], Any],
|
||||||
shape: Optional[Figure] = None,
|
shape: Optional[Figure] = None,
|
||||||
phantom: bool = False,
|
phantom: bool = False,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user