added basic agent logic
59
.gitignore
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
bin/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
.tox/
|
||||
.coverage
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
|
||||
# Mr Developer
|
||||
.mr.developer.cfg
|
||||
.project
|
||||
.pydevproject
|
||||
|
||||
# Rope
|
||||
.ropeproject
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
*.pot
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# vscode
|
||||
|
||||
.vscode
|
||||
|
||||
# Pipfiles
|
||||
|
||||
Pipfile
|
||||
Pipfile.lock
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 6.2 KiB |
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 43 KiB |
54
main.py
@ -1,6 +1,10 @@
|
||||
import pygame
|
||||
import random
|
||||
|
||||
from models.Kitchen import Kitchen
|
||||
from models.Table import Table
|
||||
from models.Waiter import Waiter
|
||||
|
||||
pygame.init()
|
||||
|
||||
|
||||
@ -22,17 +26,15 @@ for i in range(num_squares):
|
||||
squares.append(row)
|
||||
|
||||
|
||||
roles = ["kuchnia", "stół", "zamowienie", "czeka", "wykonane", "kelner"]
|
||||
images = {}
|
||||
roles_rect = {}
|
||||
|
||||
for role in roles:
|
||||
images[role] = pygame.transform.scale(pygame.image.load(
|
||||
'images/{0}.png'.format(role)), (square_size, square_size))
|
||||
left = random.randint(0, num_squares - 1) * square_size
|
||||
top = random.randint(0, num_squares - 1) * square_size
|
||||
roles_rect[role] = pygame.Rect(left, top, square_size, square_size)
|
||||
|
||||
tables = [
|
||||
Table(square_size, screen_size, 2, 4),
|
||||
Table(square_size, screen_size, 6, 5),
|
||||
Table(square_size, screen_size, 4, 2),
|
||||
Table(square_size, screen_size, 5, 6),
|
||||
Table(square_size, screen_size, 4, 4),
|
||||
]
|
||||
kitchen = Kitchen(square_size, screen_size, 0, 0)
|
||||
waiter = Waiter(square_size, screen_size, 0, 0)
|
||||
|
||||
running = True
|
||||
while running:
|
||||
@ -41,19 +43,17 @@ while running:
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
elif event.type == pygame.KEYDOWN:
|
||||
|
||||
if event.key == pygame.K_UP:
|
||||
if roles_rect["kelner"].top > 0:
|
||||
roles_rect["kelner"].top -= square_size
|
||||
waiter.up()
|
||||
elif event.key == pygame.K_DOWN:
|
||||
if roles_rect["kelner"].bottom < screen_size[1]:
|
||||
roles_rect["kelner"].top += square_size
|
||||
waiter.down()
|
||||
elif event.key == pygame.K_LEFT:
|
||||
if roles_rect["kelner"].left > 0:
|
||||
roles_rect["kelner"].left -= square_size
|
||||
waiter.left()
|
||||
elif event.key == pygame.K_RIGHT:
|
||||
if roles_rect["kelner"].right < screen_size[0]:
|
||||
roles_rect["kelner"].left += square_size
|
||||
waiter.right()
|
||||
elif event.key == pygame.K_ESCAPE:
|
||||
for table in tables:
|
||||
table.new_order()
|
||||
|
||||
screen.fill((255, 255, 255))
|
||||
|
||||
@ -61,8 +61,16 @@ while running:
|
||||
for square_rect in row:
|
||||
pygame.draw.rect(screen, (0, 0, 0), square_rect, 1)
|
||||
|
||||
for role in roles:
|
||||
pygame.draw.rect(screen, (0, 0, 0), roles_rect[role])
|
||||
screen.blit(images[role], roles_rect[role])
|
||||
for table in tables:
|
||||
table.blit(screen)
|
||||
kitchen.blit(screen)
|
||||
waiter.blit(screen)
|
||||
|
||||
for table in tables:
|
||||
if table.collision(waiter):
|
||||
waiter.do_smth(table)
|
||||
|
||||
if kitchen.collision(waiter):
|
||||
kitchen.take_orders(waiter)
|
||||
|
||||
pygame.display.flip()
|
||||
|
18
models/Kitchen.py
Normal file
@ -0,0 +1,18 @@
|
||||
import pygame
|
||||
from models.Object import Object
|
||||
from models.Waiter import Waiter
|
||||
|
||||
|
||||
class Kitchen(Object):
|
||||
def __init__(self, square_size, screen_size, left_square, top_square):
|
||||
super().__init__(
|
||||
'kitchen',
|
||||
square_size,
|
||||
screen_size,
|
||||
left_square,
|
||||
top_square
|
||||
)
|
||||
|
||||
def take_orders(self, waiter: Waiter):
|
||||
for table in waiter.get_order_list():
|
||||
table.done_order()
|
39
models/Object.py
Normal file
@ -0,0 +1,39 @@
|
||||
import pygame
|
||||
|
||||
|
||||
class Object:
|
||||
def __init__(self, role, square_size, screen_size, left_square, top_square):
|
||||
self.role = role
|
||||
self.image = pygame.transform.scale(pygame.image.load(
|
||||
'images/{0}.png'.format(role)), (square_size, square_size))
|
||||
|
||||
self.square_size = square_size
|
||||
self.screen_size = screen_size
|
||||
|
||||
left = left_square * square_size
|
||||
top = top_square * square_size
|
||||
self.rect = pygame.Rect(left, top, square_size, square_size)
|
||||
|
||||
def up(self):
|
||||
if self.rect.top > 0:
|
||||
self.rect.top -= self.square_size
|
||||
|
||||
def down(self):
|
||||
if self.rect.bottom < self.screen_size[1]:
|
||||
self.rect.top += self.square_size
|
||||
|
||||
def left(self):
|
||||
if self.rect.left > 0:
|
||||
self.rect.left -= self.square_size
|
||||
|
||||
def right(self):
|
||||
if self.rect.right < self.screen_size[0]:
|
||||
self.rect.left += self.square_size
|
||||
|
||||
def blit(self, screen):
|
||||
screen.blit(self.image, self.rect)
|
||||
|
||||
def collision(self, obj):
|
||||
x = self.rect.left == obj.rect.left
|
||||
y = self.rect.top == obj.rect.top
|
||||
return x and y
|
41
models/Table.py
Normal file
@ -0,0 +1,41 @@
|
||||
import pygame
|
||||
from models.Object import Object
|
||||
|
||||
|
||||
class Table(Object):
|
||||
def __init__(self, square_size, screen_size, left_square, top_square):
|
||||
super().__init__(
|
||||
'table',
|
||||
square_size,
|
||||
screen_size,
|
||||
left_square,
|
||||
top_square
|
||||
)
|
||||
|
||||
self.state = 'table'
|
||||
|
||||
def new_order(self):
|
||||
self.state = 'order'
|
||||
self.update_pic()
|
||||
|
||||
def wait_order(self):
|
||||
self.state = 'wait'
|
||||
self.update_pic()
|
||||
|
||||
def done_order(self):
|
||||
self.state = 'done'
|
||||
self.update_pic()
|
||||
|
||||
def reset_order(self):
|
||||
self.state = 'table'
|
||||
self.update_pic()
|
||||
|
||||
def is_order(self) -> bool:
|
||||
return self.state == 'order'
|
||||
|
||||
def is_done(self) -> bool:
|
||||
return self.state == 'done'
|
||||
|
||||
def update_pic(self):
|
||||
self.image = pygame.transform.scale(pygame.image.load(
|
||||
'images/{0}.png'.format(self.state)), (self.square_size, self.square_size))
|
44
models/Waiter.py
Normal file
@ -0,0 +1,44 @@
|
||||
import pygame
|
||||
from models.Object import Object
|
||||
from models.Table import Table
|
||||
|
||||
|
||||
class Waiter(Object):
|
||||
def __init__(self, square_size, screen_size, left_square, top_square):
|
||||
super().__init__(
|
||||
'waiter',
|
||||
square_size,
|
||||
screen_size,
|
||||
left_square,
|
||||
top_square
|
||||
)
|
||||
self.orders_limit = 3
|
||||
self.orders_list = []
|
||||
|
||||
def do_smth(self, table: Table):
|
||||
if table.is_order():
|
||||
self.take_order(table)
|
||||
elif table.is_done():
|
||||
self.deliver_order(table)
|
||||
|
||||
def take_order(self, table: Table):
|
||||
if self.orders_limit <= 0:
|
||||
return
|
||||
|
||||
if not table.is_order():
|
||||
return
|
||||
|
||||
self.orders_limit -= 1
|
||||
self.orders_list.append(table)
|
||||
|
||||
table.wait_order()
|
||||
|
||||
def deliver_order(self, table: Table):
|
||||
if table.is_done() and table in self.orders_list:
|
||||
self.orders_limit += 1
|
||||
self.orders_list.remove(table)
|
||||
|
||||
table.reset_order()
|
||||
|
||||
def get_order_list(self) -> list[Table]:
|
||||
return self.orders_list
|