mirror of
https://github.com/kristoferssolo/2048.git
synced 2025-10-21 15:20:35 +00:00
refactor(game): add config for grid dimensions
This commit is contained in:
parent
461c27e2d3
commit
70e0172ec7
@ -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:
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user