add type hints

This commit is contained in:
Kristofers Solo 2023-12-27 23:49:28 +02:00
parent 0bfba71735
commit 678b955309
2 changed files with 4 additions and 4 deletions

View File

@ -13,7 +13,7 @@ class Block(pygame.sprite.Sprite):
self.image.fill(COLORS.ERROR)
self.rect = self.image.get_rect()
self.rect.topleft = (x, y)
self.value = 2 if random.random() <= Config.BLOCK_VALUE_PROBABILITY else 4
self.value: int = 2 if random.random() <= Config.BLOCK_VALUE_PROBABILITY else 4
self.draw_value()
def draw_value(self) -> None:

View File

@ -11,7 +11,7 @@ from .config import Config
class Game:
def __init__(self) -> None:
pygame.init()
self.screen = 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.sprites = pygame.sprite.Group()
self.generate_random_block(Config.INITIAL_BLOCK_COUNT)
@ -47,7 +47,8 @@ class Game:
self.exit()
def move_blocks(self, dx: int, dy: int) -> None:
moved_blocks = pygame.sprite.Group()
moved_blocks = pygame.sprite.Group() # Keep track of moved blocks to avoid double merging
for block in self.sprites:
block.move(dx, dy)
@ -59,7 +60,6 @@ class Game:
block.increase_value()
self.sprites.remove(other_block)
moved_blocks.add(block)
self.update()
self.generate_random_block()
def generate_random_block(self, count: int = 1) -> None: