feat: add score, lines and level calc

This commit is contained in:
Giovani Rodriguez
2021-06-14 14:00:33 -04:00
parent bc8721e077
commit 0c8dff53e1
4 changed files with 39 additions and 22 deletions

View File

@@ -140,8 +140,8 @@ class Piece(Entity):
gravity_time = ConfigurationManager.get("engine", "piece-gravity-time")
set_time = ConfigurationManager.get("engine", "piece-set-time")
if Controller.key_pressed(pygame.K_DOWN):
self.gravity_time = gravity_time // 8
self.set_time = set_time // 8
self.gravity_time = max(1, gravity_time // 10)
self.set_time = max(1, set_time // 10)
if not Controller.key_pressed(pygame.K_DOWN):
self.gravity_time = gravity_time
self.set_time = set_time
@@ -151,7 +151,7 @@ class Piece(Entity):
# ghost piece
for square in self._get_ghost_piece_points(well, stack):
pygame.draw.polygon(surface, pygame.Color("#FFFFFF"), square, max(tile_size // 6, 1)) # TDOD change white to yaml
pygame.draw.polygon(surface, pygame.Color("#FFFFFF"), square, max(tile_size // 6, 1)) # TODO add white to the yaml
super().draw(surface)
@@ -297,12 +297,18 @@ class Stack(Entity):
def __init__(self, color: str, border_color: str):
super().__init__([], color, border_color)
self.rows_completed_count = 0
self.row_completion_sound = mixer.Channel(1)
self.lines_completed_count = 0
self.line_completed_sound = mixer.Channel(1)
def update(self, elapsed_time: int) -> None:
def update(self, elapsed_time: int, game: "Game") -> None:
super().update(elapsed_time)
self.rows_completed_count += self._complete_rows()
lines_completed = self._complete_rows()
current_level = game.get_level()
points_per_lines_completed = ConfigurationManager.get("engine", "points-per-lines-completed")
game.score += points_per_lines_completed[lines_completed] * (current_level + 1)
self.lines_completed_count += lines_completed
def add_piece(self, piece: Piece) -> None:
self.points += piece.points
@@ -327,7 +333,7 @@ class Stack(Entity):
if len(squares_to_exclude) == 0:
return 0
self._play_row_completion_sound()
self._play_line_completed_sound()
tile_size = ConfigurationManager.get("engine", "tile-size")
new_points = []
@@ -344,9 +350,9 @@ class Stack(Entity):
return len(rows_completed)
def _play_row_completion_sound(self) -> None:
row_completion_sound_file = ConfigurationManager.get("sound", "row-completion")
self.row_completion_sound.play(mixer.Sound(row_completion_sound_file))
def _play_line_completed_sound(self) -> None:
line_completed_sound_file = ConfigurationManager.get("sound", "row-completion")
self.line_completed_sound.play(mixer.Sound(line_completed_sound_file))
"""
TODO description