2023-03-10 23:21:14 +01:00
|
|
|
import sys
|
2023-03-21 12:36:50 +01:00
|
|
|
import pygame
|
|
|
|
import regal
|
2023-03-26 18:13:07 +02:00
|
|
|
import paczka
|
2023-04-20 20:54:58 +02:00
|
|
|
from wozek import Wozek
|
2023-05-06 13:40:17 +02:00
|
|
|
import wyszukiwanie
|
|
|
|
import ekran
|
2023-03-10 23:21:14 +01:00
|
|
|
pygame.init()
|
2023-05-06 13:40:17 +02:00
|
|
|
# screen = pygame.display.set_mode((980, 980))
|
|
|
|
# miejsce = pygame.image.load('images/miejsce_paczek.png')
|
|
|
|
#
|
|
|
|
# pygame.display.set_caption("Inteligentny wozek")
|
|
|
|
# icon = pygame.image.load('images/icon.png')
|
|
|
|
# pygame.display.set_icon(icon)
|
2023-03-11 13:26:14 +01:00
|
|
|
|
2023-03-27 12:10:08 +02:00
|
|
|
|
|
|
|
def main():
|
2023-03-11 00:44:46 +01:00
|
|
|
wozek = Wozek()
|
|
|
|
while True:
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
sys.exit(0)
|
2023-03-26 21:21:52 +02:00
|
|
|
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
|
2023-03-11 00:44:46 +01:00
|
|
|
sys.exit(0)
|
2023-05-06 13:40:17 +02:00
|
|
|
if event.type == pygame.MOUSEBUTTONDOWN:
|
|
|
|
# lewy przycisk myszy
|
|
|
|
if event.button == 1:
|
|
|
|
x = pygame.mouse.get_pos()[0]
|
|
|
|
y = pygame.mouse.get_pos()[1]
|
|
|
|
wiersz = ekran.sprawdz_ktory_wiersz(x)
|
|
|
|
kolumna = ekran.sprawdz_ktora_kolumna(y)
|
|
|
|
docelowy_stan = wyszukiwanie.Stan(wiersz*70, kolumna*70, 0)
|
|
|
|
wezel = wyszukiwanie.wyszukiwanie_bfs(wozek.obecnyStan, docelowy_stan)
|
|
|
|
sciezka = wyszukiwanie.znajdz_sciezke(wezel)
|
|
|
|
wozek.przemiesc_wozek_po_sciezce(sciezka)
|
|
|
|
|
|
|
|
if event.type == pygame.KEYDOWN:
|
|
|
|
if event.key == pygame.K_DOWN:
|
|
|
|
wozek.y_change = 1
|
|
|
|
if event.key == pygame.K_UP:
|
|
|
|
wozek.y_change = -1
|
|
|
|
if event.key == pygame.K_RIGHT:
|
|
|
|
wozek.x_change = 1
|
|
|
|
if event.key == pygame.K_LEFT:
|
|
|
|
wozek.x_change = -1
|
|
|
|
|
|
|
|
if event.type == pygame.KEYUP:
|
|
|
|
if event.key == pygame.K_DOWN or event.key == pygame.K_UP:
|
|
|
|
wozek.y_change = 0
|
|
|
|
if event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT:
|
|
|
|
wozek.x_change = 0
|
|
|
|
|
|
|
|
wozek.obecnyStan.x += wozek.x_change
|
|
|
|
wozek.obecnyStan.y += wozek.y_change
|
|
|
|
|
|
|
|
if wozek.obecnyStan.x <= 0:
|
|
|
|
wozek.obecnyStan.x = 0
|
|
|
|
elif wozek.obecnyStan.x >= 916:
|
|
|
|
wozek.obecnyStan.x = 916
|
|
|
|
if wozek.obecnyStan.y <= 0:
|
|
|
|
wozek.obecnyStan.y = 0
|
|
|
|
elif wozek.obecnyStan.x >= 916:
|
|
|
|
wozek.obecnyStan.x = 916
|
|
|
|
|
|
|
|
ekran.odswiez_ekran(wozek)
|
2023-03-11 00:44:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|