From 639383779936b8f6a7d829f103096f8df14bb167 Mon Sep 17 00:00:00 2001 From: andrzej Date: Sun, 5 Apr 2020 15:26:28 +0200 Subject: [PATCH] =?UTF-8?q?Modyfikacja=20paczek,=20otrzymuj=C4=85=20r?= =?UTF-8?q?=C3=B3wnie=C5=BC=20status,=20mog=C4=85cy=20by=C4=87=20LOOSE=20-?= =?UTF-8?q?=20paczka=20le=C5=BCy=20na=20pod=C5=82odze,=20STORED=20-=20pacz?= =?UTF-8?q?ka=20jest=20przechowywana=20na=20regale,=20STORED=5FBAD=5FLOCAT?= =?UTF-8?q?ION=20-=20paczka=20jest=20na=20regale,=20ale=20w=20z=C5=82ym=20?= =?UTF-8?q?miejscu=20magazynu,=20lub=20na=20regale,=20na=20kt=C3=B3rym=20"?= =?UTF-8?q?gabarytowo"=20nie=20powinna=20si=C4=99=20znale=C5=BA=C4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- attributes.py | 4 ++++ main.py | 22 ++++++++++++++++------ warehouse.py | 14 +++++++++++--- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/attributes.py b/attributes.py index e425ded..da6ba83 100644 --- a/attributes.py +++ b/attributes.py @@ -7,6 +7,10 @@ class PackSize(Enum): LARGE = 3 HUGE = 4 +class PackStatus(Enum): + LOOSE = 0 + STORED = 1 + STORED_BAD_LOCATION = 2 PACK_CATEGORIES = { 'general', diff --git a/main.py b/main.py index 89a5861..6cbb1d2 100644 --- a/main.py +++ b/main.py @@ -2,15 +2,17 @@ import pygame import warehouse import agent import random -from attributes import PackSize +from attributes import PackSize, PackStatus WINDOW_SIZE = (600, 600) COLORS = { 'white': (255, 255, 255), 'black': (0, 0, 0), 'gray': (128, 128, 128), - 'darkgray': (60,60,60), - 'yellow': (225,225,0) + 'darkgray': (60, 60, 60), + 'yellow': (235, 235, 0), + 'lightgreen': (70, 238, 70), + 'red': (255, 0, 0) } COLOR_OF_FIELD = { 'Floor': 'gray', @@ -24,7 +26,7 @@ CIRCLE_CENTER_X, CIRCLE_CENTER_Y = int(TILE_WIDTH/2), int(TILE_HEIGHT/2) class MainGameFrame: def __init__(self): self.display = pygame.display.set_mode(WINDOW_SIZE) - self.warehouse_map = warehouse.Warehouse(20, 20, 100, 10) + self.warehouse_map = warehouse.Warehouse(20, 20, 100, 40) starting_x, starting_y = self.set_starting_agent_position() self.agent = agent.Agent(starting_x, starting_y, 20) @@ -52,9 +54,17 @@ class MainGameFrame: ((x * TILE_WIDTH) + 1, (y * TILE_HEIGHT) + 1, TILE_WIDTH - 1, TILE_HEIGHT - 1)) def draw_packages(self): + def get_package_color(pack): + colors = { + PackStatus.LOOSE: COLORS['yellow'], + PackStatus.STORED: COLORS['lightgreen'], + PackStatus.STORED_BAD_LOCATION: COLORS['red'] + } + return colors[pack.status] + for pack in self.warehouse_map.packages: pack_x, pack_y = pack.lays_on_field.x_position, pack.lays_on_field.y_position - package_color = COLORS['yellow'] + package_color = get_package_color(pack) pygame.draw.rect(self.display, package_color, ((pack_x * TILE_WIDTH) + 3, (pack_y * TILE_HEIGHT) + 3, TILE_WIDTH - 5, TILE_HEIGHT - 5)) @@ -65,7 +75,7 @@ class MainGameFrame: def set_starting_agent_position(self): starting_x, starting_y = random.randrange(self.warehouse_map.width), random.randrange(self.warehouse_map.height) - while self.warehouse_map.tiles[starting_x][starting_y].category.name != 'Floor': + while not isinstance(self.warehouse_map.tiles[starting_x][starting_y], warehouse.Tile) or self.warehouse_map.tiles[starting_x][starting_y].category.name != 'Floor': starting_x, starting_y = random.randrange(self.warehouse_map.width), random.randrange( self.warehouse_map.height) return starting_x, starting_y diff --git a/warehouse.py b/warehouse.py index ebd0e3f..37e6cbc 100644 --- a/warehouse.py +++ b/warehouse.py @@ -1,4 +1,4 @@ -from attributes import PackSize +from attributes import PackSize, PackStatus import random import queue import itertools @@ -18,9 +18,17 @@ class Pack: def __init__(self, size=PackSize.MEDIUM, categ='general', lays_on_field=None): self.size = size self.category = categ - assert isinstance(lays_on_field, Tile), AssertionError("Attribute lays_on_field must be a Tile object! You see, package cannot lay in void :)") + assert isinstance(lays_on_field, Tile), AssertionError("Attribute lays_on_field must be a Tile object! You know, package cannot lay in void :)") self.lays_on_field = lays_on_field + self.status = self.set_status() + def set_status(self): + status = PackStatus.LOOSE + if self.lays_on_field.category.name == 'Floor': + status = PackStatus.LOOSE + elif self.lays_on_field.category.name == 'Rack': + status = PackStatus.STORED + return status CATEGORY = { 'floor': CategoryData('Floor', True, False), #lava @@ -100,7 +108,7 @@ class Warehouse: return packages def _set_package_position(self): starting_x, starting_y = random.randrange(self.width), random.randrange(self.height) - while self.tiles[starting_x][starting_y].category.name != 'Floor': + while not isinstance(self.tiles[starting_x][starting_y], Tile): starting_x, starting_y = random.randrange(self.width), random.randrange( self.height) return starting_x, starting_y