generowanie planszy

This commit is contained in:
Zuzanna Wójcik 2023-05-08 11:27:16 +02:00
parent deb2be3745
commit 310228fb0b
3 changed files with 71 additions and 24 deletions

View File

@ -1,5 +1,6 @@
import pygame import pygame
from plansza import x1, y1, x2, y2, x3, y3, x4, y4, a_pix, b_pix
import packageList import packageList
import regal import regal
import wozek import wozek
@ -18,25 +19,25 @@ pygame.display.set_icon(icon)
lista_paczek = packageList.zainicjuj_liste_paczek() lista_paczek = packageList.zainicjuj_liste_paczek()
def narysuj_regaly(): def narysuj_regaly():
regal.Regal(1, 1, 2, 2) regal.Regal(1, 1, x1, y1)
regal.Regal(2, 1, 2, 3) regal.Regal(2, 1, x1, y1+1)
regal.Regal(3, 1, 3, 2) regal.Regal(3, 1, x1+1, y1)
regal.Regal(4, 1, 3, 3) regal.Regal(4, 1, x1+1, y1+1)
regal.Regal(5, 1, 10, 2) regal.Regal(5, 1, x2, y2)
regal.Regal(6, 1, 10, 3) regal.Regal(6, 1, x2, y2+1)
regal.Regal(7, 1, 11, 2) regal.Regal(7, 1, x2+1, y2)
regal.Regal(8, 1, 11, 3) regal.Regal(8, 1, x2+1, y2+1)
regal.Regal(9, 1, 2, 8) regal.Regal(9, 1, x3, y3)
regal.Regal(10, 1, 2, 9) regal.Regal(10, 1, x3, y3+1)
regal.Regal(11, 1, 3, 8) regal.Regal(11, 1, x3+1, y3)
regal.Regal(12, 1, 3, 9) regal.Regal(12, 1, x3+1, y3+1)
regal.Regal(13, 1, 10, 8) regal.Regal(13, 1, x4, y4)
regal.Regal(14, 1, 10, 9) regal.Regal(14, 1, x4, y4+1)
regal.Regal(15, 1, 11, 8) regal.Regal(15, 1, x4+1, y4)
regal.Regal(16, 1, 11, 9) regal.Regal(16, 1, x4+1, y4+1)
def narysuj_siatke(): def narysuj_siatke():
@ -50,8 +51,7 @@ def narysuj_siatke():
def odswiez_ekran(wozek): def odswiez_ekran(wozek):
screen.fill((51, 51, 51)) # removes object trail screen.fill((51, 51, 51)) # removes object trail
#screen.blit(miejsce, (430, 400)) screen.blit(miejsce,(a_pix, b_pix))
screen.blit(miejsce,(420, 350))
narysuj_siatke() narysuj_siatke()
narysuj_paczki(wozek) narysuj_paczki(wozek)
narysuj_regaly() narysuj_regaly()
@ -78,4 +78,4 @@ def sprawdz_ktora_kolumna(y):
def narysuj_paczki(wozek): def narysuj_paczki(wozek):
if wozek.ln == 0: if wozek.ln == 0:
for paczka in lista_paczek.list: for paczka in lista_paczek.list:
paczka.narysuj(430, 400, screen) paczka.narysuj(a_pix, b_pix, screen)

View File

@ -1,4 +1,5 @@
from enum import Enum from enum import Enum
from plansza import x1,x2,x3,x4,y1,y2,y3,y4,a,b
from typing import Tuple, Dict from typing import Tuple, Dict
@ -18,8 +19,8 @@ class SearchGrid:
for i in range (0,14): for i in range (0,14):
for j in range(0,14): for j in range(0,14):
self.grid[(i, j)] = GridCellType.FREE self.grid[(i, j)] = GridCellType.FREE
for r, c in [(2,2), (2,3), (3,2), (3,3), (10,2), (10,3), (11,2), (11,3), for r, c in [(x1, y1), (x1, y1+1), (x1+1, y1), (x1+1, y1+1), (x2, y2), (x2+1, y2), (x2, y2+1), (x2+1, y2+1),
(2,8), (2,9), (3,8), (3,9), (10,8), (10,9), (11,8), (11,9),]: (x3, y3), (x3+1, y3), (x3, y3+1), (x3+1, y3+1), (x4, y4), (x4+1, y4), (x4, y4+1), (x4+1, y4+1),]:
self.grid[(r,c)] = GridCellType.RACK self.grid[(r,c)] = GridCellType.RACK
for m, n in [(6,5), (6,6), (7,5), (7,6)]: for m, n in [(a,b), (a+1,b), (a,b+1), (a+1,b+1)]:
self.grid[(m,n)] = GridCellType.PLACE self.grid[(m,n)] = GridCellType.PLACE

46
plansza.py Normal file
View File

@ -0,0 +1,46 @@
import random
def obliczPixeleNaPodstawieKratek(wymiar): #Przeliczanie współrzędnych podanych w kratkach na pixele
i = 1
pixele = 73
while (i < wymiar):
pixele = pixele + 70
i = i + 1
return pixele
EKRAN_SZEROKOSC = 980
EKRAN_WYSOKOSC = 980
blockSize = 70
x1, y1, x2, y2, x3, y3, x4, y4 = [None] * 8
while True:
#wspolrzedne regalow
x1 = random.randint(1, EKRAN_SZEROKOSC // blockSize - 2)
y1 = random.randint(1, EKRAN_SZEROKOSC // blockSize - 2)
x2 = random.randint(1, EKRAN_SZEROKOSC // blockSize - 2)
y2 = random.randint(1, EKRAN_SZEROKOSC // blockSize - 2)
x3 = random.randint(1, EKRAN_SZEROKOSC // blockSize - 2)
y3 = random.randint(1, EKRAN_SZEROKOSC // blockSize - 2)
x4 = random.randint(1, EKRAN_SZEROKOSC // blockSize - 2)
y4 = random.randint(1, EKRAN_SZEROKOSC // blockSize - 2)
#wspolrzedne miejsca paczek
a = random.randint(1, EKRAN_SZEROKOSC // blockSize - 2)
b = random.randint(1, EKRAN_SZEROKOSC // blockSize - 2)
coords = [(x1, y1), (x1+1, y1), (x1, y1+1), (x1+1, y1+1),
(x2, y2), (x2+1, y2), (x2, y2+1), (x2+1, y2+1),
(x3, y3), (x3+1, y3), (x3, y3+1), (x3+1, y3+1),
(x4, y4), (x4+1, y4), (x4, y4+1), (x4+1, y4+1),
(a, b), (a+1, b), (a, b+1), (a+1, b+1)]
#sprawdzenie czy jakies wspolrzedne sie pokrywaja
if len(coords) == len(set(coords)):
break
x1, x2, x3, x4, y1, y2, y3, y4, a, b = map(int, [x1, x2, x3, x4, y1, y2, y3, y4, a, b])
a_pix = obliczPixeleNaPodstawieKratek(a)
b_pix = obliczPixeleNaPodstawieKratek(b)