diff --git a/configs/blocks_ADD_000.json b/configs/blocks_ADD_000.json index 78eb71f..59e5af7 100644 --- a/configs/blocks_ADD_000.json +++ b/configs/blocks_ADD_000.json @@ -3,6 +3,14 @@ "__type__": "EnumClass", "name": "BlockType", "members": { + "D": { + "name": "Dot", + "color": [255, 255, 100], + "min_score": 3500, + "shapes": [ + [[1]] + ] + }, "U": { "name": "U-Shape", "color": [135, 135, 135], diff --git a/das_tetris_gui.py b/das_tetris_gui.py index 9d18245..f77e9c1 100644 --- a/das_tetris_gui.py +++ b/das_tetris_gui.py @@ -63,15 +63,15 @@ class TetrisGame: # Initialize game self.spawn_piece() - def get_block_min_score(self, block_type: cfg.BlockType) -> int: + def get_block_min_score(self, block_type: BLOCK_TYPE) -> int: """Get minimal score of block to be shown""" return block_type.value['min_score'] - def get_block_shapes(self, block_type: cfg.BlockType) -> List[List[List[int]]]: + def get_block_shapes(self, block_type: BLOCK_TYPE) -> List[List[List[int]]]: """Get all rotation shapes for a block type""" return block_type.value['shapes'] - def get_block_color(self, block_type: cfg.BlockType) -> Tuple[int, int, int]: + def get_block_color(self, block_type: BLOCK_TYPE) -> Tuple[int, int, int]: """Get color for a block type""" return block_type.value['color'] @@ -97,18 +97,18 @@ class TetrisGame: self.current_block_rotation, self.current_block): self.game_over = True - def choice_random_block(self) -> cfg.BlockType: - block: cfg.BlockType = random.choice(list(cfg.BlockType)) + def choice_random_block(self) -> BLOCK_TYPE: + block: BLOCK_TYPE = random.choice(list(BLOCK_TYPE)) while self.get_block_min_score(block) > self.score: - block = random.choice(list(cfg.BlockType)) + block = random.choice(list(BLOCK_TYPE)) return block - def get_block_shape(self, block_type: cfg.BlockType, rotation: int) -> List[List[int]]: + def get_block_shape(self, block_type: BLOCK_TYPE, rotation: int) -> List[List[int]]: """Get the shape matrix for a block at specific rotation""" shapes = self.get_block_shapes(block_type) return shapes[rotation % len(shapes)] - def can_place_block(self, x: int, y: int, rotation: int, block_type: cfg.BlockType) -> bool: + def can_place_block(self, x: int, y: int, rotation: int, block_type: BLOCK_TYPE) -> bool: """Check if a block can be placed at given position""" shape = self.get_block_shape(block_type, rotation) @@ -130,7 +130,7 @@ class TetrisGame: return True - def place_block(self, x: int, y: int, rotation: int, block_type: cfg.BlockType, block_id: int): + def place_block(self, x: int, y: int, rotation: int, block_type: BLOCK_TYPE, block_id: int): """Place a block on the field""" shape = self.get_block_shape(block_type, rotation) @@ -176,7 +176,7 @@ class TetrisGame: # Block can't move down, place it self.place_block(self.current_block_x, self.current_block_y, self.current_block_rotation, self.current_block, - list(cfg.BlockType).index(self.current_block) + 1) + list(BLOCK_TYPE).index(self.current_block) + 1) # Check for complete lines self.clear_lines() @@ -348,7 +348,7 @@ class TetrisRenderer: for row_idx, row in enumerate(game.field): for col_idx, cell in enumerate(row): if cell != 0: - block_type = list(cfg.BlockType)[cell - 1] + block_type = list(BLOCK_TYPE)[cell - 1] color = game.get_block_color(block_type) x = self.field_x + col_idx * self.block_size y = self.field_y + row_idx * self.block_size diff --git a/tetris_config.py b/tetris_config.py index 113d55f..eb74825 100644 --- a/tetris_config.py +++ b/tetris_config.py @@ -23,6 +23,7 @@ class BlockType(Enum): """ Define block types with their shapes and colors All shapes draws starting in top left corner from left to right + Every line mean the share rotated in clockwise direction """ O = { 'name': 'Square', @@ -95,47 +96,6 @@ class BlockType(Enum): [[0, 1], [1, 1], [0, 1]] ] } - U = { - 'name': 'U-Shape', - 'color': (135, 135, 135), # Change color - 'min_score': 4500, - 'shapes': [ - [[1, 0, 1], [1, 1, 1]], - [[1, 1], [1, 0], [1, 1]], - [[1, 1, 1], [1, 0, 1]], - [[1, 1], [0, 1], [1, 1]] - ] - } - # T1 = { - # 'name': 'T-Shape+', - # 'color': (200, 200, 200), # Change color - # 'min_score': 10000, - # 'shapes': [ - # [[1, 1, 1], [0, 1, 0], [0, 1, 0]], - # [[0, 0, 1], [1, 1, 1], [0, 0, 1]], - # [[0, 1, 0], [0, 1, 0], [1, 1, 1]], - # [[1, 0, 0], [1, 1, 1], [1, 0, 0]] - # ] - # } - # U1 = { - # 'name': 'U-Shape+', - # 'color': (250, 250, 250), # Change color - # 'min_score': 10000, - # 'shapes': [ - # [[1, 1, 1], [1, 0, 1], [1, 0, 1]], - # [[1, 1, 1], [1, 0, 0], [1, 1, 1]], - # [[1, 0, 1], [1, 0, 1], [1, 1, 1]], - # [[1, 1, 1], [0, 0, 1], [1, 1, 1]] - # ] - # } - # X = { - # 'name': 'X-Shape', - # 'color': (250, 250, 250), # Change color - # 'min_score': 15000, - # 'shapes': [ - # [[0, 1, 0], [1, 1, 1], [0, 1, 0]] - # ] - # } BLOCK_TYPE = BlockType