Merge pull request 'states' (#18) from states into master

Reviewed-on: #18
This commit is contained in:
Paweł Felcyn 2023-04-22 12:12:32 +02:00
commit 7ef1ccb0a3
10 changed files with 30 additions and 3 deletions

6
agentActionType.py Normal file
View File

@ -0,0 +1,6 @@
from enum import Enum
class AgentActionType (Enum):
MOVE_FORWARD = 0
TURN_LEFT = 1
TURN_RIGHT = 2

View File

@ -1,6 +1,7 @@
from typing import Tuple, List from typing import Tuple, List, Dict
import pygame import pygame
from PIL import Image from PIL import Image
from gridCellType import GridCellType
class GameContext: class GameContext:
dust_car_speed = 20 dust_car_speed = 20
@ -11,6 +12,15 @@ class GameContext:
canvas = None canvas = None
_cell_size: int = 30 _cell_size: int = 30
city = None 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): def render_in_cell(self, cell: Tuple[int, int], img_path: str):
img = Image.open(img_path) img = Image.open(img_path)

View File

@ -1,6 +1,7 @@
from garbage import Garbage from garbage import Garbage
from typing import List, Tuple from typing import List, Tuple
from gameContext import GameContext from gameContext import GameContext
from gridCellType import GridCellType
class GarbageCan: class GarbageCan:
position: Tuple[int, int] position: Tuple[int, int]
@ -17,4 +18,5 @@ class GarbageCan:
self.garbage.remove(garbage) self.garbage.remove(garbage)
def render(self, game_context: GameContext) -> None: def render(self, game_context: GameContext) -> None:
game_context.render_in_cell(self.position, "imgs/container.png") game_context.render_in_cell(self.position, "imgs/container.png")
game_context.grid[self.position] = GridCellType.GARBAGE_CAN

7
gridCellType.py Normal file
View File

@ -0,0 +1,7 @@
from enum import Enum
class GridCellType(Enum):
NOTHING = 0
STREET_VERTICAL = 1
STREET_HORIZONTAL = 2
GARBAGE_CAN = 3

BIN
imgs/dust_car_down.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 751 B

After

Width:  |  Height:  |  Size: 751 B

BIN
imgs/dust_car_right.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 751 B

BIN
imgs/dust_car_up.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -9,7 +9,7 @@ pygame.init()
canvas = pygame.display.set_mode((800, 800)) canvas = pygame.display.set_mode((800, 800))
pygame.display.set_caption("Inteligentna śmieciarka") pygame.display.set_caption("Inteligentna śmieciarka")
dust_car_pil = Image.open('imgs/dust_car.png') dust_car_pil = Image.open('imgs/dust_car_right.png')
game_context = GameContext() game_context = GameContext()
game_context.dust_car_pil = dust_car_pil game_context.dust_car_pil = dust_car_pil

View File

@ -1,6 +1,7 @@
from enum import Enum from enum import Enum
from typing import Tuple from typing import Tuple
from gameContext import GameContext from gameContext import GameContext
from gridCellType import GridCellType
class StreetType (Enum): class StreetType (Enum):
VERTICAL = 0 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' 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) 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.render_in_cell(cell, img_str)
game_context.grid[cell] = GridCellType.STREET_HORIZONTAL if self.street_type == StreetType.HORIZONTAL else GridCellType.STREET_VERTICAL