Some improvements and corrections. Added 'Dot' 1x1 sape
This commit is contained in:
+11
-11
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user