adding ekran module
This commit is contained in:
parent
8dae8a4b20
commit
832094398c
63
ekran.py
Normal file
63
ekran.py
Normal file
@ -0,0 +1,63 @@
|
||||
import pygame
|
||||
import regal
|
||||
import wozek
|
||||
|
||||
EKRAN_SZEROKOSC = 980
|
||||
EKRAN_WYSOKOSC = 980
|
||||
screen = pygame.display.set_mode((EKRAN_SZEROKOSC, EKRAN_WYSOKOSC))
|
||||
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)
|
||||
|
||||
|
||||
def narysuj_regaly():
|
||||
regal.Regal(1, 1, 2, 2)
|
||||
regal.Regal(2, 1, 2, 3)
|
||||
regal.Regal(3, 1, 3, 2)
|
||||
regal.Regal(4, 1, 3, 3)
|
||||
|
||||
regal.Regal(5, 1, 10, 2)
|
||||
regal.Regal(6, 1, 10, 3)
|
||||
regal.Regal(7, 1, 11, 2)
|
||||
regal.Regal(8, 1, 11, 3)
|
||||
|
||||
regal.Regal(9, 1, 2, 8)
|
||||
regal.Regal(10, 1, 2, 9)
|
||||
regal.Regal(11, 1, 3, 8)
|
||||
regal.Regal(12, 1, 3, 9)
|
||||
|
||||
regal.Regal(13, 1, 10, 8)
|
||||
regal.Regal(14, 1, 10, 9)
|
||||
regal.Regal(15, 1, 11, 8)
|
||||
regal.Regal(16, 1, 11, 9)
|
||||
|
||||
def drawGrid():
|
||||
blockSize = 70 #Set the size of the grid block
|
||||
WHITE = (200, 200, 200)
|
||||
for x in range(0, EKRAN_SZEROKOSC, blockSize):
|
||||
for y in range(0, EKRAN_WYSOKOSC, blockSize):
|
||||
rect = pygame.Rect(x, y, blockSize, blockSize)
|
||||
pygame.draw.rect(screen, WHITE, rect, 1)
|
||||
def odswiez_ekran(wozek):
|
||||
screen.fill((51, 51, 51)) # removes object trail
|
||||
screen.blit(miejsce, (430, 400))
|
||||
drawGrid()
|
||||
narysuj_regaly()
|
||||
wozek.draw()
|
||||
# pygame.draw.rect(screen, (255,0,0),(70,70,10,10))
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
def sprawdz_ktory_wiersz(x):
|
||||
nr_wiersza = 0
|
||||
for i in range(70, EKRAN_WYSOKOSC + 70, 70):
|
||||
if x < i:
|
||||
return nr_wiersza
|
||||
nr_wiersza = nr_wiersza + 1
|
||||
def sprawdz_ktora_kolumna(y):
|
||||
nr_kolumny = 0
|
||||
for i in range(70, EKRAN_SZEROKOSC + 70, 70):
|
||||
if y < i:
|
||||
return nr_kolumny
|
||||
nr_kolumny = nr_kolumny + 1
|
134
main.py
134
main.py
@ -3,16 +3,15 @@ import pygame
|
||||
import regal
|
||||
import paczka
|
||||
from wozek import Wozek
|
||||
from wyszukiwanie import wyszukiwanie_bfs, Stan, SearchSpace
|
||||
|
||||
|
||||
import wyszukiwanie
|
||||
import ekran
|
||||
pygame.init()
|
||||
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)
|
||||
# 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)
|
||||
|
||||
|
||||
def main():
|
||||
@ -23,65 +22,86 @@ def main():
|
||||
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)
|
||||
# print(f'{docelowy_stan.x} + {docelowy_stan.y}')
|
||||
# wyszukiwanie.wyszukiwanie_bfs(wozek.obecnyStan, docelowy_stan)
|
||||
# wezel = wyszukiwanie.wyszukiwanie_bfs(wozek.obecnyStan, wyszukiwanie.Stan(905, 527))
|
||||
wezel = wyszukiwanie.wyszukiwanie_bfs(wozek.obecnyStan, docelowy_stan)
|
||||
sciezka = wyszukiwanie.znajdz_sciezke(wezel)
|
||||
# print(sciezka)
|
||||
wozek.przemiesc_wozek_po_sciezce(sciezka)
|
||||
|
||||
grid = SearchSpace()
|
||||
# create start and goal states
|
||||
start_state = Stan(x=1, y=0, kierunek=0) # for example
|
||||
goal_state = Stan(x=12, y=0, kierunek=0) # for example
|
||||
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
|
||||
|
||||
# perform BFS search
|
||||
path = wyszukiwanie_bfs(start_state, goal_state, grid)
|
||||
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
|
||||
|
||||
# print the path, if found
|
||||
if path:
|
||||
for p in path:
|
||||
print(p.x, p.y)
|
||||
print("Path found:", path)
|
||||
else:
|
||||
print("No path found.")
|
||||
wozek.obecnyStan.x += wozek.x_change
|
||||
wozek.obecnyStan.y += wozek.y_change
|
||||
|
||||
for state in path:
|
||||
pygame.time.delay(200)
|
||||
wozek.x = state.x
|
||||
wozek.y = state.y
|
||||
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 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
|
||||
|
||||
# grid = SearchSpace()
|
||||
# # create start and goal states
|
||||
# start_state = Stan(x=1, y=0, kierunek=0) # for example
|
||||
# goal_state = Stan(x=12, y=0, kierunek=0) # for example
|
||||
|
||||
# Drawing
|
||||
screen.fill((51,51,51)) # removes object trail
|
||||
screen.blit(miejsce, (430, 400))
|
||||
# # Drawing
|
||||
# screen.fill((51, 51, 51)) # removes object trail
|
||||
# screen.blit(miejsce, (430, 400))
|
||||
|
||||
# idRegału, Długość regału podana w kratkach, Współrzędne od których ma być tworzony regał (wiersz,kolumna) - poziomo
|
||||
# Współrzędne od (1,1) do (10,10)
|
||||
regal.Regal(1, 1, 2, 2)
|
||||
regal.Regal(2, 1, 2, 3)
|
||||
regal.Regal(3, 1, 3, 2)
|
||||
regal.Regal(4, 1, 3, 3)
|
||||
# regal.Regal(1, 1, 2, 2)
|
||||
# regal.Regal(2, 1, 2, 3)
|
||||
# regal.Regal(3, 1, 3, 2)
|
||||
# regal.Regal(4, 1, 3, 3)
|
||||
#
|
||||
# regal.Regal(5, 1, 8, 2)
|
||||
# regal.Regal(6, 1, 8, 3)
|
||||
# regal.Regal(7, 1, 9, 2)
|
||||
# regal.Regal(8, 1, 9, 3)
|
||||
#
|
||||
# regal.Regal(9, 1, 2, 8)
|
||||
# regal.Regal(10, 1, 2, 9)
|
||||
# regal.Regal(11, 1, 3, 8)
|
||||
# regal.Regal(12, 1, 3, 9)
|
||||
#
|
||||
# regal.Regal(13, 1, 8, 8)
|
||||
# regal.Regal(14, 1, 8, 9)
|
||||
# regal.Regal(15, 1, 9, 8)
|
||||
# regal.Regal(16, 1, 9, 9)
|
||||
|
||||
regal.Regal(5, 1, 8, 2)
|
||||
regal.Regal(6, 1, 8, 3)
|
||||
regal.Regal(7, 1, 9, 2)
|
||||
regal.Regal(8, 1, 9, 3)
|
||||
|
||||
regal.Regal(9, 1, 2, 8)
|
||||
regal.Regal(10, 1, 2, 9)
|
||||
regal.Regal(11, 1, 3, 8)
|
||||
regal.Regal(12, 1, 3, 9)
|
||||
|
||||
regal.Regal(13, 1, 8, 8)
|
||||
regal.Regal(14, 1, 8, 9)
|
||||
regal.Regal(15, 1, 9, 8)
|
||||
regal.Regal(16, 1, 9, 9)
|
||||
|
||||
wozek.draw()
|
||||
|
||||
pygame.display.flip() # updating frames
|
||||
# wozek.draw()
|
||||
#
|
||||
# pygame.display.flip() # updating frames
|
||||
ekran.odswiez_ekran(wozek)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user