refactor(game): add config for grid dimensions

This commit is contained in:
Kristofers Solo 2024-01-01 20:27:54 +02:00
parent 461c27e2d3
commit 70e0172ec7
3 changed files with 8 additions and 4 deletions

View File

@ -62,8 +62,8 @@ class Block(pygame.sprite.Sprite):
def _is_out_if_bounds(self, x: int, y: int) -> bool:
"""Return whether the block is out of bounds."""
return not (
0 <= x <= Config.WIDTH - Config.BLOCK_SIZE
and 0 <= y <= Config.HEIGHT - Config.BLOCK_SIZE
0 <= x <= Config.GRID_WIDTH - Config.BLOCK_SIZE
and 0 <= y <= Config.GRID_HEIGHT - Config.BLOCK_SIZE
)
def _has_collision(self, x: int, y: int) -> bool:

View File

@ -4,6 +4,8 @@ class Config:
GRID_SIZE = 4
BLOCK_SIZE = 50
WIDTH = GRID_SIZE * BLOCK_SIZE
HEIGHT = GRID_SIZE * BLOCK_SIZE
HEIGHT = GRID_SIZE * BLOCK_SIZE + 100
GRID_HEIGHT = GRID_SIZE * BLOCK_SIZE
GRID_WIDTH = GRID_SIZE * BLOCK_SIZE
INITIAL_BLOCK_COUNT = 2
BLOCK_VALUE_PROBABILITY = 0.9

View File

@ -16,7 +16,9 @@ class Game:
logger.info("Initializing game")
pygame.init()
self.screen: pygame.Surface = pygame.display.set_mode((Config.WIDTH, Config.HEIGHT))
self.screen: pygame.Surface = pygame.display.set_mode(
(Config.WIDTH, Config.HEIGHT)
)
pygame.display.set_caption("2048")
self.blocks = Board(self.screen)