From d2f898358b03563339c1884190090b30e61dd7b0 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Sun, 31 Dec 2023 22:40:39 +0200 Subject: [PATCH] refactor(game): remove redundant debug messaged --- src/py2048/block.py | 8 +------- src/py2048/game.py | 4 ---- src/py2048/grid.py | 1 + 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/py2048/block.py b/src/py2048/block.py index 329d9f6..507cf5b 100644 --- a/src/py2048/block.py +++ b/src/py2048/block.py @@ -19,8 +19,6 @@ class Block(pygame.sprite.Sprite): self.rect = self.image.get_rect() self.rect.topleft = x, y - logger.debug(f"Generated block({id(self)}) at {self}") - self.value: int = value if value is not None else 2 if random.random() <= Config.BLOCK_VALUE_PROBABILITY else 4 self.font = pygame.font.SysFont(Config.FONT_FAMILY, Config.FONT_SIZE) self.update() @@ -39,7 +37,6 @@ class Block(pygame.sprite.Sprite): new_x, new_y = self._calc_new_pos(direction) if self._is_out_if_bounds(new_x, new_y): - logger.debug(f"Block({id(self)}) stayed at {self.pos()} (out of bounds)") return if self._has_collision(new_x, new_y): @@ -47,11 +44,9 @@ class Block(pygame.sprite.Sprite): if collided_block and collided_block.value == self.value: self._merge(collided_block) else: - logger.debug(f"Block({id(self)}) collided with another, stopped at {self.pos()}") return self.rect.topleft = new_x, new_y - logger.debug(f"Moving block({id(self)}): {self.pos()} => ({grid_pos(new_x)}, {grid_pos(new_y)})") def _calc_new_pos(self, direction: Direction) -> tuple[int, int]: """Calculate the new position of the block.""" @@ -69,14 +64,13 @@ class Block(pygame.sprite.Sprite): def _get_collided_block(self, x: int, y: int) -> Union["Block", None]: """Get the block that collides with the given block.""" - logger.error(list(block for block in self.groups()[0] if block != self and block.rect.collidepoint(x, y))) return next((block for block in self.groups()[0] if block != self and block.rect.collidepoint(x, y)), None) def _merge(self, other: "Block") -> None: """Merge the block with another block.""" self.value += other.value self.update() - logger.debug(f"Merging block({id(self)}) with block({id(other)}") + logger.debug(f"Merging block({id(self)}) with block({id(other)})") self.groups()[0].remove(other) def update(self) -> None: diff --git a/src/py2048/game.py b/src/py2048/game.py index 513c0c9..f0fcd5b 100644 --- a/src/py2048/game.py +++ b/src/py2048/game.py @@ -57,19 +57,15 @@ class Game: self.exit() def move_up(self) -> None: - logger.debug("Move up") self.blocks.move(Direction.UP) def move_down(self) -> None: - logger.debug("Move down") self.blocks.move(Direction.DOWN) def move_left(self) -> None: - logger.debug("Move left") self.blocks.move(Direction.LEFT) def move_right(self) -> None: - logger.debug("Move right") self.blocks.move(Direction.RIGHT) def exit(self) -> None: diff --git a/src/py2048/grid.py b/src/py2048/grid.py index 021503e..27412d8 100644 --- a/src/py2048/grid.py +++ b/src/py2048/grid.py @@ -18,6 +18,7 @@ class Grid(pygame.sprite.Group): blocks.sort(key=lambda block: block.rect.x, reverse=True) for block in blocks: + block: Block block.move(direction) self.generate_block()