forked from s474139/Inteligentny_Wozek
73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
import sys
|
|
import pygame
|
|
from wozek import Wozek
|
|
import wyszukiwanie
|
|
import ekran
|
|
|
|
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:
|
|
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
|
|
|
|
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()
|