2023-05-06 14:54:04 +02:00
|
|
|
import sys
|
|
|
|
import pygame
|
|
|
|
from wozek import Wozek
|
|
|
|
import wyszukiwanie
|
|
|
|
import ekran
|
2023-05-06 18:06:30 +02:00
|
|
|
from grid import SearchGrid
|
2023-05-06 14:54:04 +02:00
|
|
|
pygame.init()
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
wozek = Wozek()
|
|
|
|
|
|
|
|
while True:
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
sys.exit(0)
|
|
|
|
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
|
|
|
|
sys.exit(0)
|
|
|
|
if event.type == pygame.MOUSEBUTTONDOWN:
|
|
|
|
# lewy przycisk myszy
|
|
|
|
if event.button == 1:
|
2023-05-06 18:06:30 +02:00
|
|
|
grid_points = SearchGrid()
|
2023-05-06 14:54:04 +02:00
|
|
|
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)
|
2023-05-06 18:06:30 +02:00
|
|
|
wezel = wyszukiwanie.wyszukiwanie_bfs(wozek.obecnyStan, docelowy_stan, grid_points)
|
2023-05-06 14:54:04 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
if event.type == pygame.KEYDOWN:
|
|
|
|
if event.key == pygame.K_SPACE:
|
|
|
|
if wozek.ln == 0:
|
|
|
|
wozek.load_package()
|
|
|
|
wozek.dynamic_wozek_picture()
|
|
|
|
else:
|
|
|
|
wozek.drop_package()
|
|
|
|
wozek.dynamic_wozek_picture()
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|