2024-03-13 18:05:38 +01:00
|
|
|
import pygame
|
|
|
|
import random
|
|
|
|
import time
|
2024-04-04 03:01:13 +02:00
|
|
|
import numpy
|
2024-04-03 21:48:49 +02:00
|
|
|
import threading
|
2024-03-13 18:05:38 +01:00
|
|
|
|
2024-04-04 03:01:13 +02:00
|
|
|
kuchnia_xy = 40
|
|
|
|
pozycja_startowa = 5
|
|
|
|
|
|
|
|
#-----------------------------Inicjacja klas
|
|
|
|
class Kelner:
|
|
|
|
def __init__(self, x, y):
|
|
|
|
self.x = x
|
|
|
|
self.y = y
|
|
|
|
self.speed = 1 #---na razie nie zmieniać ;) działa dla 1 lub 5
|
|
|
|
self.stan = "stoi" # Stan kelnera: stoi, odbiera lub wraca
|
|
|
|
self.stolik_docelowy = None # Stolik, do którego idzie kelner
|
|
|
|
self.cel_x = x
|
|
|
|
self.cel_y = y
|
|
|
|
|
|
|
|
def wklej(self):
|
|
|
|
screen.blit(kelnerImg, (self.x, self.y))
|
|
|
|
|
|
|
|
def idz_do_stolika(self):
|
|
|
|
self.cel_x, self.cel_y = self.stolik_docelowy.x, self.stolik_docelowy.y
|
|
|
|
kelner.stan = "odbiera"
|
|
|
|
|
|
|
|
def idz_do_kuchni(self):
|
|
|
|
self.cel_x, self.cel_y = pozycja_startowa, pozycja_startowa
|
|
|
|
self.stolik_docelowy = None
|
|
|
|
kelner.stan = "wraca"
|
|
|
|
|
|
|
|
|
|
|
|
class Stolik:
|
|
|
|
def __init__(self, x, y):
|
|
|
|
self.x = x
|
|
|
|
self.y = y
|
|
|
|
self.zamowione = False
|
|
|
|
|
|
|
|
def wklej(self):
|
|
|
|
screen.blit(stolikImg, (self.x, self.y))
|
2024-03-13 18:05:38 +01:00
|
|
|
|
2024-04-04 03:01:13 +02:00
|
|
|
|
|
|
|
#--------------Inicjacja obiektów
|
|
|
|
kelner = Kelner(pozycja_startowa,pozycja_startowa)
|
|
|
|
|
|
|
|
#-----------wspolrzedne stolikow
|
|
|
|
coords = ["325 320", "325 640", "885 320", "885 640"]
|
|
|
|
|
|
|
|
#Tworzenie listy stolikow
|
|
|
|
stoliki = []
|
|
|
|
for coord in coords:
|
|
|
|
x, y = map(int, coord.split())
|
|
|
|
stoliki.append(Stolik(x, y))
|
|
|
|
|
|
|
|
pygame.init()
|
2024-03-13 18:05:38 +01:00
|
|
|
pygame.display.set_caption("Automatyczny kelner")
|
2024-04-04 03:01:13 +02:00
|
|
|
|
2024-03-13 18:05:38 +01:00
|
|
|
#----------------wymiary okna
|
2024-04-03 21:48:49 +02:00
|
|
|
width = 1200
|
2024-03-13 18:05:38 +01:00
|
|
|
height = 800
|
|
|
|
|
|
|
|
screen = pygame.display.set_mode((width, height))
|
|
|
|
|
|
|
|
kelnerImg = pygame.image.load("kelner.png")
|
2024-04-03 21:48:49 +02:00
|
|
|
kelnerImg = pygame.transform.scale(kelnerImg, (70, 70))
|
2024-03-13 18:05:38 +01:00
|
|
|
stolikImg = pygame.image.load("stolik.png")
|
2024-04-03 21:48:49 +02:00
|
|
|
stolikImg = pygame.transform.scale(stolikImg, (70, 70))
|
|
|
|
menuImg = pygame.image.load("menu.png")
|
|
|
|
menuImg = pygame.transform.scale(menuImg, (40, 40))
|
|
|
|
kitchenImg = pygame.image.load("kitchen.png")
|
|
|
|
kitchenImg = pygame.transform.scale(kitchenImg, (100, 100))
|
|
|
|
|
|
|
|
def kuchnia(x, y):
|
|
|
|
screen.blit(kitchenImg, (x, y))
|
2024-03-13 18:05:38 +01:00
|
|
|
|
2024-04-04 03:01:13 +02:00
|
|
|
def menu(x, y):
|
2024-04-03 21:48:49 +02:00
|
|
|
screen.blit(menuImg, (x, y))
|
|
|
|
|
|
|
|
#def randomoweZamowienia():
|
|
|
|
#threading.Timer(5.0).start()
|
|
|
|
#x = random.randrange(0, 4)
|
|
|
|
#if zamownienia[x] == 0:
|
|
|
|
#zamownienia[x] = 1
|
|
|
|
#stolikImg = pygame.image.load("menu.png") #----zmien
|
|
|
|
#stolikImg = pygame.transform.scale(stolikImg, (70, 70))
|
|
|
|
#screen.blit(stolikImg, (1, 1))
|
|
|
|
|
|
|
|
def wypiszOkno():
|
|
|
|
screen.fill((0, 0, 0))
|
|
|
|
blockSize = 80
|
|
|
|
for x in range(0, width, blockSize):
|
|
|
|
for y in range(0, height, blockSize):
|
|
|
|
rect = pygame.Rect(x, y, blockSize, blockSize)
|
|
|
|
pygame.draw.rect(screen, (200, 200, 200), rect, 1) #-------------Wypisz kratę -TA
|
|
|
|
|
2024-03-13 18:05:38 +01:00
|
|
|
run = True
|
|
|
|
|
2024-04-03 21:48:49 +02:00
|
|
|
#def randomTime():
|
|
|
|
# x = random.randrange(2, 20)
|
|
|
|
# threading.Timer(x, randomTime).start()
|
|
|
|
# y=random.randrange(0, 2)
|
|
|
|
# return y
|
|
|
|
|
|
|
|
#whichPic = randomTime()
|
|
|
|
|
2024-03-13 18:05:38 +01:00
|
|
|
while run:
|
2024-04-03 21:48:49 +02:00
|
|
|
wypiszOkno()
|
2024-04-04 03:01:13 +02:00
|
|
|
kuchnia(kuchnia_xy, kuchnia_xy)
|
|
|
|
|
|
|
|
for stolik in stoliki:
|
|
|
|
stolik.wklej()
|
|
|
|
|
|
|
|
kelner.wklej()
|
|
|
|
|
|
|
|
if kelner.stan == "wraca":
|
|
|
|
menu(kelner.x, kelner.y)
|
|
|
|
|
|
|
|
#------------weź zamowienie
|
|
|
|
for stolik in stoliki:
|
|
|
|
if stolik.zamowione == True:
|
|
|
|
menu(stolik.x, stolik.y)
|
|
|
|
if kelner.stan == "stoi":
|
|
|
|
kelner.stolik_docelowy = stolik
|
|
|
|
kelner.idz_do_stolika()
|
|
|
|
|
|
|
|
#----------Losuje stoliki, które dokonają zamówienia
|
|
|
|
if kelner.stan == "stoi":
|
|
|
|
for stolik in stoliki:
|
|
|
|
if stolik.zamowione == True:
|
|
|
|
break
|
|
|
|
for i in range(4):
|
|
|
|
if random.randrange(2) == 1:
|
|
|
|
stoliki[i].zamowione = True
|
|
|
|
|
|
|
|
#print("kelner.x: " + str(kelner.x) + " kelner.y: " + str(kelner.y))-------------Wypisuje wspolrzedne kelnera
|
|
|
|
|
|
|
|
#----------------Zmiana pozycji kelnera
|
|
|
|
if kelner.x != kelner.cel_x:
|
|
|
|
kelner.x += kelner.speed * numpy.sign(kelner.cel_x - kelner.x)
|
2024-03-13 18:05:38 +01:00
|
|
|
else:
|
2024-04-04 03:01:13 +02:00
|
|
|
kelner.y += kelner.speed * numpy.sign(kelner.cel_y - kelner.y) #zmieniamy pozycje Y dopiero, gdy pozycja X bedzie prawidlowa
|
|
|
|
|
|
|
|
print(kelner.stan)
|
|
|
|
|
|
|
|
#----------------Sprawdzenie, czy kelner jest u celu
|
|
|
|
if kelner.x == kelner.cel_x and kelner.y == kelner.cel_y:
|
|
|
|
if kelner.stan == "odbiera":
|
|
|
|
kelner.stolik_docelowy.zamowione = False
|
|
|
|
kelner.idz_do_kuchni()
|
|
|
|
|
|
|
|
elif kelner.stan == "wraca":
|
|
|
|
kelner.stan = "stoi"
|
|
|
|
|
2024-04-03 21:48:49 +02:00
|
|
|
|
2024-03-13 18:05:38 +01:00
|
|
|
time.sleep(0.001)
|
|
|
|
|
|
|
|
key = pygame.key.get_pressed()
|
|
|
|
pygame.display.update()
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
run = False
|
|
|
|
pygame.quit()
|