diff --git a/src/py2048/block.py b/src/py2048/block.py index 354228a..823ad86 100644 --- a/src/py2048/block.py +++ b/src/py2048/block.py @@ -17,14 +17,14 @@ class Block(pygame.sprite.Sprite): self.font = pygame.font.SysFont(Config.FONT_FAMILY, Config.FONT_SIZE) self.update() - def draw_value(self) -> None: + def _draw_value(self) -> None: """Draw the value of the block""" text = self.font.render(str(self.value), True, COLORS.FG) text_rect = text.get_rect(center=self.image.get_rect().center) self.image.blit(text, text_rect) def move(self, dx: int, dy: int) -> None: - """Move the block by `dx` and `dy`""" + """Move the block by `dx` and `dy`.""" new_x = self.rect.x + dx new_y = self.rect.y + dy if 0 <= new_x <= Config.WIDTH - Config.BLOCK_SIZE and 0 <= new_y <= Config.HEIGHT - Config.BLOCK_SIZE: @@ -38,10 +38,10 @@ class Block(pygame.sprite.Sprite): def update(self) -> None: """Update the block""" - self.change_color() - self.draw_value() + self._change_color() + self._draw_value() - def change_color(self) -> None: + def _change_color(self) -> None: """Change the color of the block based on its value""" color_map = { 2: COLORS.BLUE, diff --git a/src/py2048/game.py b/src/py2048/game.py index 963f4b3..c75e01d 100644 --- a/src/py2048/game.py +++ b/src/py2048/game.py @@ -19,26 +19,26 @@ class Game: self.screen: pygame.Surface = pygame.display.set_mode((Config.WIDTH, Config.HEIGHT)) pygame.display.set_caption("2048") self.sprites = pygame.sprite.Group() - self.generate_random_block(Config.INITIAL_BLOCK_COUNT) + self._generate_random_block(Config.INITIAL_BLOCK_COUNT) def run(self) -> None: """Run the game loop.""" while True: - self.hande_events() - self.update() - self.render() + self._hande_events() + self._update() + self._render() - def update(self) -> None: + def _update(self) -> None: """Update the game.""" self.sprites.update() - def render(self) -> None: + def _render(self) -> None: """Render the game.""" self.screen.fill(COLORS.BG) self.sprites.draw(self.screen) pygame.display.flip() - def hande_events(self) -> None: + def _hande_events(self) -> None: """Handle pygame events.""" for event in pygame.event.get(): if event.type == pygame.QUIT: @@ -90,9 +90,9 @@ class Game: block.increase_value() self.sprites.remove(other_block) moved_blocks.add(block) - self.generate_random_block() + self._generate_random_block() - def generate_random_block(self, count: int = 1) -> None: + def _generate_random_block(self, count: int = 1) -> None: """Generate `count` number of random blocks.""" for _ in range(count): while True: