From aba828546977af983eae0d6410848bb161d75340 Mon Sep 17 00:00:00 2001 From: Pawel Felcyn Date: Sat, 22 Apr 2023 12:04:08 +0200 Subject: [PATCH] street grid cell type --- gameContext.py | 12 +++++++++++- gridCellType.py | 7 +++++++ street.py | 2 ++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 gridCellType.py diff --git a/gameContext.py b/gameContext.py index d749c04..37939b0 100644 --- a/gameContext.py +++ b/gameContext.py @@ -1,6 +1,7 @@ -from typing import Tuple, List +from typing import Tuple, List, Dict import pygame from PIL import Image +from gridCellType import GridCellType class GameContext: dust_car_speed = 20 @@ -11,6 +12,15 @@ class GameContext: canvas = None _cell_size: int = 30 city = None + grid: Dict[Tuple[int, int], GridCellType] = {} + + def __init__(self) -> None: + self._init_grid() + + def _init_grid(self) -> None: + for i in range(1, 28): + for j in range(1, 28): + self.grid[(i, j)] = GridCellType.NOTHING def render_in_cell(self, cell: Tuple[int, int], img_path: str): img = Image.open(img_path) diff --git a/gridCellType.py b/gridCellType.py new file mode 100644 index 0000000..d8e5e42 --- /dev/null +++ b/gridCellType.py @@ -0,0 +1,7 @@ +from enum import Enum + +class GridCellType(Enum): + NOTHING = 0 + STREET_VERTICAL = 1 + STREET_HORIZONTAL = 2 + GARBAGE_CAN = 3 \ No newline at end of file diff --git a/street.py b/street.py index 9287394..3ec4bd6 100644 --- a/street.py +++ b/street.py @@ -1,6 +1,7 @@ from enum import Enum from typing import Tuple from gameContext import GameContext +from gridCellType import GridCellType class StreetType (Enum): VERTICAL = 0 @@ -23,3 +24,4 @@ class Street: img_str: str = 'imgs/street_vertical.png' if self.street_type == StreetType.VERTICAL else 'imgs/street_horizontal.png' cell: Tuple[int, int] = (self.row_or_column, i) if self.street_type == StreetType.VERTICAL else (i, self.row_or_column) game_context.render_in_cell(cell, img_str) + game_context.grid[cell] = GridCellType.STREET_HORIZONTAL if self.street_type == StreetType.HORIZONTAL else GridCellType.STREET_VERTICAL