feat(game): add is_full method

This commit is contained in:
Kristofers Solo 2024-01-01 20:02:23 +02:00
parent fe127ae01c
commit 0ebea765e2

View File

@ -32,6 +32,7 @@ class Board(pygame.sprite.Group):
for block in blocks: for block in blocks:
block.move(direction) block.move(direction)
if not self._is_full():
self.generate_random_block() self.generate_random_block()
def generate_initial_blocks(self) -> None: def generate_initial_blocks(self) -> None:
@ -57,9 +58,16 @@ class Board(pygame.sprite.Group):
y = random.randint(0, 3) * Config.BLOCK_SIZE y = random.randint(0, 3) * Config.BLOCK_SIZE
block = Block(x, y, self) block = Block(x, y, self)
colliding_blocks = pygame.sprite.spritecollide(block, self, False) # check for collisions colliding_blocks = pygame.sprite.spritecollide(
block, self, False
) # check for collisions
if not colliding_blocks: if not colliding_blocks:
self.add(block) self.add(block)
logger.debug(f"Created block at {block.pos}") logger.debug(f"Created block at {block.pos}")
break break
def _is_full(self) -> bool:
"""Check if the board is full."""
return len(self.sprites()) == Config.GRID_SIZE**2