automatyczny_kelner/main.py
2023-03-31 00:48:17 +02:00

77 lines
1.9 KiB
Python

import pygame
import random
from models.Kitchen import Kitchen
from models.Table import Table
from models.Waiter import Waiter
pygame.init()
screen_size = (600, 600)
screen = pygame.display.set_mode(screen_size)
square_size = 50
num_squares = screen_size[0] // square_size
squares = []
for i in range(num_squares):
row = []
for j in range(num_squares):
square_rect = pygame.Rect(
j * square_size, i * square_size, square_size, square_size)
row.append(square_rect)
squares.append(row)
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:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
waiter.up()
elif event.key == pygame.K_DOWN:
waiter.down()
elif event.key == pygame.K_LEFT:
waiter.left()
elif event.key == pygame.K_RIGHT:
waiter.right()
elif event.key == pygame.K_ESCAPE:
for table in tables:
table.new_order()
screen.fill((255, 255, 255))
for row in squares:
for square_rect in row:
pygame.draw.rect(screen, (0, 0, 0), square_rect, 1)
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()