mirror of
https://github.com/kristoferssolo/2048.git
synced 2025-10-21 15:20:35 +00:00
feat(game): add log output
import logger
This commit is contained in:
parent
b533946471
commit
56f32f7b4a
@ -1,6 +1,7 @@
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
from .colors import COLORS
|
from .colors import COLORS
|
||||||
from .config import Config
|
from .config import Config
|
||||||
@ -28,13 +29,11 @@ class Block(pygame.sprite.Sprite):
|
|||||||
new_x = self.rect.x + dx
|
new_x = self.rect.x + dx
|
||||||
new_y = self.rect.y + dy
|
new_y = self.rect.y + dy
|
||||||
if 0 <= new_x <= Config.WIDTH - Config.BLOCK_SIZE and 0 <= new_y <= Config.HEIGHT - Config.BLOCK_SIZE:
|
if 0 <= new_x <= Config.WIDTH - Config.BLOCK_SIZE and 0 <= new_y <= Config.HEIGHT - Config.BLOCK_SIZE:
|
||||||
|
logger.debug(f"Moving block({id(self)}): ({self.rect.x}, {self.rect.y}) => ({new_x}, {new_y})")
|
||||||
self.rect.x = new_x
|
self.rect.x = new_x
|
||||||
self.rect.y = new_y
|
self.rect.y = new_y
|
||||||
|
else:
|
||||||
def increase_value(self, num: int = 2) -> None:
|
logger.debug("Move blocked: out of bounds")
|
||||||
"""Increase the value of the block `num` times"""
|
|
||||||
self.value *= num
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
def update(self) -> None:
|
def update(self) -> None:
|
||||||
"""Update the block"""
|
"""Update the block"""
|
||||||
|
|||||||
@ -104,6 +104,7 @@ class Game:
|
|||||||
|
|
||||||
if not colliding_blocks:
|
if not colliding_blocks:
|
||||||
self.sprites.add(block)
|
self.sprites.add(block)
|
||||||
|
logger.debug(f"Generated block({id(block)}) at ({x}, {y})")
|
||||||
break
|
break
|
||||||
|
|
||||||
def exit(self) -> None:
|
def exit(self) -> None:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user