diff options
Diffstat (limited to 'cameltris/screens/in_game.py')
-rw-r--r-- | cameltris/screens/in_game.py | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/cameltris/screens/in_game.py b/cameltris/screens/in_game.py index 5596ddb..87b080a 100644 --- a/cameltris/screens/in_game.py +++ b/cameltris/screens/in_game.py @@ -8,6 +8,7 @@ import pygame from .screen import Screen from ..piece import * +from ..playfield import PlayField from ..controller import Input, Controller, KeyboardController, JoystickController from ..misc import Pause @@ -25,7 +26,7 @@ right_pane_canvas.fill((255, 255, 255)) class Player: def __init__(self, controller: Controller, starting_level: int): self.controller = controller - self.grid = [[None for _ in range(10)] for _ in range(20)] + self.playfield = PlayField() self.current_piece, self.current_piece_position = self.generate_piece() self.next_piece, self.next_piece_position = self.generate_piece() @@ -54,23 +55,10 @@ class Player: break initial_y_position = -row_id - initial_x_position = (len(self.grid[0]) // 2) - (len(piece.elements[0]) // 2) + initial_x_position = (len(self.playfield.grid[0]) // 2) - (len(piece.elements[0]) // 2) return (piece, [initial_y_position, initial_x_position]) - def burn_rows(self) -> int: - rows_to_burn = list() - - for row in self.grid: - if all(map(lambda element: element is not None, row)): - rows_to_burn.append(row) - - for row in rows_to_burn: - self.grid.insert(0, [None for _ in range(10)]) - self.grid.remove(row) - - return len(rows_to_burn) - def lock_piece(self) -> None: if self.has_collision(self.current_piece_position[0], self.current_piece_position[1]): raise WouldCollide() @@ -79,9 +67,9 @@ class Player: for col_id, element in enumerate(row): if element is None: continue - self.grid[row_id + self.current_piece_position[0]][col_id + self.current_piece_position[1]] = element + self.playfield.grid[row_id + self.current_piece_position[0]][col_id + self.current_piece_position[1]] = element - count = self.burn_rows() + count = self.playfield.burn_rows() if count == 1: print("Single") @@ -121,7 +109,7 @@ class Player: if col_id + x < 0: return True - if self.grid[row_id + y][col_id + x] is not None: + if self.playfield.grid[row_id + y][col_id + x] is not None: return True except IndexError: @@ -223,7 +211,7 @@ class Player: def refresh_grid_canvas(self) -> None: self.grid_canvas.fill(black) - for row_idx, row in enumerate(self.grid): + for row_idx, row in enumerate(self.playfield.grid): for col_idx, element in enumerate(row): if element is not None: self.grid_canvas.blit(element, (col_idx * 50 + 1, row_idx * 50 + 1)) |