Modyfikacja paczek, otrzymują również status, mogący być LOOSE - paczka leży na podłodze, STORED - paczka jest przechowywana na regale, STORED_BAD_LOCATION - paczka jest na regale, ale w złym miejscu magazynu, lub na regale, na którym "gabarytowo" nie powinna się znaleźć

This commit is contained in:
andrzej 2020-04-05 15:26:28 +02:00
parent c33043986c
commit 6393837799
3 changed files with 31 additions and 9 deletions

View File

@ -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',

22
main.py
View File

@ -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

View File

@ -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