diff --git a/src/py2048/block.py b/src/py2048/block.py index 8d004c3..01f8900 100644 --- a/src/py2048/block.py +++ b/src/py2048/block.py @@ -8,12 +8,7 @@ from loguru import logger from .colors import COLORS from .config import Config -from .utils import Direction - - -def _grid_pos(pos: int) -> int: - """Return the position in the grid.""" - return pos // Config.BLOCK_SIZE + 1 +from .utils import Direction, grid_pos class Block(pygame.sprite.Sprite): @@ -52,7 +47,7 @@ class Block(pygame.sprite.Sprite): 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)})") + 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.""" @@ -109,4 +104,4 @@ class Block(pygame.sprite.Sprite): def pos(self) -> tuple[int, int]: """Return the position of the block""" - return _grid_pos(self.rect.x), _grid_pos(self.rect.y) + return grid_pos(self.rect.x), grid_pos(self.rect.y) diff --git a/src/py2048/utils.py b/src/py2048/utils.py index 1c50cd4..3de342c 100755 --- a/src/py2048/utils.py +++ b/src/py2048/utils.py @@ -1,5 +1,12 @@ from enum import Enum +from .config import Config + + +def grid_pos(pos: int) -> int: + """Return the position in the grid.""" + return pos // Config.BLOCK_SIZE + 1 + class Direction(Enum): UP = (0, -1)