diff options
-rw-r--r-- | cameltris/color.py | 13 | ||||
-rw-r--r-- | cameltris/piece.py | 26 | ||||
-rw-r--r-- | cameltris/screens/in_game.py | 13 |
3 files changed, 29 insertions, 23 deletions
diff --git a/cameltris/color.py b/cameltris/color.py new file mode 100644 index 0000000..3fc2f9d --- /dev/null +++ b/cameltris/color.py @@ -0,0 +1,13 @@ +from enum import Enum + + +class Color(Enum): + black = (0, 0, 0) + white = (0xff, 0xff, 0xff) + brown = (163, 75, 31) + blue = (30, 34, 164) + green = (30, 164, 59) + red = (164, 30, 30) + purple = (126, 30, 164) + yellow = (164, 164, 30) + cyan = (30, 164, 150) diff --git a/cameltris/piece.py b/cameltris/piece.py index 1bbe2c4..d8e7b63 100644 --- a/cameltris/piece.py +++ b/cameltris/piece.py @@ -2,18 +2,10 @@ import pygame +from .color import Color -square_template = pygame.Surface((48, 48)) -black = (0, 0, 0) -white = (0xff, 0xff, 0xff) -brown = (163, 75, 31) -blue = (30, 34, 164) -green = (30, 164, 59) -red = (164, 30, 30) -purple = (126, 30, 164) -yellow = (164, 164, 30) -cyan = (30, 164, 150) +square_template = pygame.Surface((48, 48)) class Piece: @@ -37,7 +29,7 @@ class ZPiece(Piece): def __init__(self): super().__init__() - self.square.fill(blue) + self.square.fill(Color.blue.value) self.elements = (self.square, self.square, None), (None, self.square, self.square), (None, None, None) self.vertical = False @@ -60,7 +52,7 @@ class SPiece(Piece): def __init__(self): super().__init__() - self.square.fill(green) + self.square.fill(Color.green.value) self.elements = (None, None, None), (None, self.square, self.square), (self.square, self.square, None) self.vertical = False @@ -83,7 +75,7 @@ class SquarePiece(Piece): def __init__(self): super().__init__() - self.square.fill(brown) + self.square.fill(Color.brown.value) self.elements = ((self.square, self.square), (self.square, self.square)) @@ -91,7 +83,7 @@ class IPiece(Piece): def __init__(self): super().__init__() - self.square.fill(red) + self.square.fill(Color.red.value) self.elements = (None, None, None, None), (None, None, None, None), (self.square, self.square, self.square, self.square), (None, None, None, None) self.vertical = False @@ -114,7 +106,7 @@ class LPiece(Piece): def __init__(self): super().__init__() - self.square.fill(cyan) + self.square.fill(Color.cyan.value) self.elements = (None, None, None), (self.square, self.square, self.square), (None, None, self.square) @@ -122,7 +114,7 @@ class JPiece(Piece): def __init__(self): super().__init__() - self.square.fill(purple) + self.square.fill(Color.purple.value) self.elements = (None, None, None), (self.square, self.square, self.square), (self.square, None, None) @@ -130,5 +122,5 @@ class TPiece(Piece): def __init__(self): super().__init__() - self.square.fill(yellow) + self.square.fill(Color.yellow.value) self.elements = (None, None, None), (self.square, self.square, self.square), (None, self.square, None) diff --git a/cameltris/screens/in_game.py b/cameltris/screens/in_game.py index 87b080a..1ae20de 100644 --- a/cameltris/screens/in_game.py +++ b/cameltris/screens/in_game.py @@ -6,6 +6,7 @@ from typing import Callable, NoReturn, Optional import pygame +from ..color import Color from .screen import Screen from ..piece import * from ..playfield import PlayField @@ -186,7 +187,7 @@ class Player: self.pressing_down_countdown = None def refresh_piece_preview_canvas(self) -> None: - self.piece_preview_canvas.fill(black) + self.piece_preview_canvas.fill(Color.black.value) non_empty_rows = list() for row in self.next_piece.elements: @@ -209,7 +210,7 @@ class Player: self.piece_preview_canvas.blit(element, ((col_idx + x_offset) * 50 + 1, (row_idx + y_offset) * 50 + 1)) def refresh_grid_canvas(self) -> None: - self.grid_canvas.fill(black) + self.grid_canvas.fill(Color.black.value) for row_idx, row in enumerate(self.playfield.grid): for col_idx, element in enumerate(row): @@ -255,14 +256,14 @@ class InGame(Screen): def refresh_right_pane_canvas(self) -> None: for player in self.players: - player.level_canvas.fill(black) - player.score_canvas.fill(black) + player.level_canvas.fill(Color.black.value) + player.score_canvas.fill(Color.black.value) if pygame.font: score_font = pygame.font.Font(None, 56) - player.score_canvas.blit(score_font.render(f"{player.score:08d}", True, white), (0, 0)) - player.level_canvas.blit(score_font.render(f"{player.level:08d}", True, white), (0, 0)) + player.score_canvas.blit(score_font.render(f"{player.score:08d}", True, Color.white.value), (0, 0)) + player.level_canvas.blit(score_font.render(f"{player.level:08d}", True, Color.white.value), (0, 0)) right_pane_canvas.blit(player.score_canvas, (2, 10)) right_pane_canvas.blit(player.level_canvas, (2, 70)) |