forked from s474139/Inteligentny_Wozek
merged bfs with picking up packages
This commit is contained in:
parent
e236cfe6f9
commit
642132e0f4
12
ekran.py
12
ekran.py
@ -1,6 +1,10 @@
|
|||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
|
import packageList
|
||||||
import regal
|
import regal
|
||||||
import wozek
|
import wozek
|
||||||
|
from packageList import *
|
||||||
|
from paczka import Paczka
|
||||||
|
|
||||||
EKRAN_SZEROKOSC = 980
|
EKRAN_SZEROKOSC = 980
|
||||||
EKRAN_WYSOKOSC = 980
|
EKRAN_WYSOKOSC = 980
|
||||||
@ -10,6 +14,7 @@ pygame.display.set_caption("Inteligentny wozek")
|
|||||||
icon = pygame.image.load('images/icon.png')
|
icon = pygame.image.load('images/icon.png')
|
||||||
pygame.display.set_icon(icon)
|
pygame.display.set_icon(icon)
|
||||||
|
|
||||||
|
lista_paczek = packageList.zainicjuj_liste_paczek()
|
||||||
|
|
||||||
def narysuj_regaly():
|
def narysuj_regaly():
|
||||||
regal.Regal(1, 1, 2, 2)
|
regal.Regal(1, 1, 2, 2)
|
||||||
@ -46,6 +51,7 @@ 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, (430, 400))
|
||||||
narysuj_siatke()
|
narysuj_siatke()
|
||||||
|
narysuj_paczki(wozek)
|
||||||
narysuj_regaly()
|
narysuj_regaly()
|
||||||
wozek.draw()
|
wozek.draw()
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
@ -65,3 +71,9 @@ def sprawdz_ktora_kolumna(y):
|
|||||||
if y < i:
|
if y < i:
|
||||||
return nr_kolumny
|
return nr_kolumny
|
||||||
nr_kolumny = nr_kolumny + 1
|
nr_kolumny = nr_kolumny + 1
|
||||||
|
|
||||||
|
|
||||||
|
def narysuj_paczki(wozek):
|
||||||
|
if wozek.ln == 0:
|
||||||
|
for paczka in lista_paczek.list:
|
||||||
|
paczka.narysuj(430, 400, screen)
|
||||||
|
@ -1,16 +1,10 @@
|
|||||||
#from main import pygame
|
|
||||||
import secrets, string
|
import secrets, string
|
||||||
|
|
||||||
class Etykieta:
|
class Etykieta:
|
||||||
def __init__(self, id, nadawca, adres, imie, nazwisko, telefon):
|
def __init__(self, nadawca, adres, imie, nazwisko, telefon):
|
||||||
self.nadawca = nadawca
|
self.nadawca = nadawca
|
||||||
self.adres = adres
|
self.adres = adres
|
||||||
self.imie = imie
|
self.imie = imie
|
||||||
self.nazwisko = nazwisko
|
self.nazwisko = nazwisko
|
||||||
self.telefon = telefon
|
self.telefon = telefon
|
||||||
self.id = ''.join(secrets.choice(string.ascii_uppercase + string.digits) for _ in range(9))
|
self.id = ''.join(secrets.choice(string.ascii_uppercase + string.digits) for _ in range(9))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
19
main.py
19
main.py
@ -1,21 +1,15 @@
|
|||||||
import sys
|
import sys
|
||||||
import pygame
|
import pygame
|
||||||
import regal
|
|
||||||
import paczka
|
|
||||||
from wozek import Wozek
|
from wozek import Wozek
|
||||||
import wyszukiwanie
|
import wyszukiwanie
|
||||||
import ekran
|
import ekran
|
||||||
|
|
||||||
pygame.init()
|
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)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
wozek = Wozek()
|
wozek = Wozek()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
@ -50,6 +44,15 @@ def main():
|
|||||||
if event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT:
|
if event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT:
|
||||||
wozek.x_change = 0
|
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.x += wozek.x_change
|
||||||
wozek.obecnyStan.y += wozek.y_change
|
wozek.obecnyStan.y += wozek.y_change
|
||||||
|
|
||||||
|
16
packageList.py
Normal file
16
packageList.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
class listOfPackages:
|
||||||
|
list = []
|
||||||
|
|
||||||
|
def add(self, item):
|
||||||
|
self.list.append(item)
|
||||||
|
|
||||||
|
def remove(self):
|
||||||
|
self.list.pop()
|
||||||
|
|
||||||
|
|
||||||
|
def zainicjuj_liste_paczek():
|
||||||
|
from paczka import Paczka
|
||||||
|
packageList = listOfPackages()
|
||||||
|
demo_paczka = Paczka('duzy', 10, any, False, any, any, any, any, any)
|
||||||
|
packageList.add(demo_paczka)
|
||||||
|
return packageList
|
25
paczka.py
25
paczka.py
@ -6,14 +6,29 @@ class Paczka:
|
|||||||
|
|
||||||
def __init__(self, rozmiar, waga, kategoria, czy_krucha, nadawca, adres, imie, nazwisko, telefon):
|
def __init__(self, rozmiar, waga, kategoria, czy_krucha, nadawca, adres, imie, nazwisko, telefon):
|
||||||
self.rozmiar = rozmiar
|
self.rozmiar = rozmiar
|
||||||
|
self.image = pygame.image.load("images/paczka.png")
|
||||||
|
if rozmiar == 'duzy':
|
||||||
|
self.image = pygame.transform.scale(self.image, (50, 50))
|
||||||
|
self.szerokosc = 50
|
||||||
|
self.wysokosc = 50
|
||||||
|
elif rozmiar == 'sredni':
|
||||||
|
self.image = pygame.transform.scale(self.image, (35, 35))
|
||||||
|
self.szerokosc = 35
|
||||||
|
self.wysokosc = 35
|
||||||
|
elif rozmiar == 'maly':
|
||||||
|
self.image = pygame.transform.scale(self.image, (20, 20))
|
||||||
|
self.szerokosc = 20
|
||||||
|
self.wysokosc = 20
|
||||||
|
else:
|
||||||
|
self.image = pygame.transform.scale(self.image, (20, 20))
|
||||||
|
self.szerokosc = 20
|
||||||
|
self.wysokosc = 20
|
||||||
|
self.rozmiar = 'undefined'
|
||||||
self.waga = waga
|
self.waga = waga
|
||||||
self.kategoria = kategoria
|
self.kategoria = kategoria
|
||||||
self.czy_krucha = czy_krucha
|
self.czy_krucha = czy_krucha
|
||||||
self.x = 0
|
self.x = 430
|
||||||
self.y = 0
|
self.y = 400
|
||||||
self.szerokosc = 0
|
|
||||||
self.wysokosc = 0
|
|
||||||
self.image = pygame.image.load("images/paczka.png")
|
|
||||||
self.label = Etykieta(nadawca, adres, imie, nazwisko, telefon)
|
self.label = Etykieta(nadawca, adres, imie, nazwisko, telefon)
|
||||||
|
|
||||||
# zmienia rozmiar obrazka w zaleznosci od rozmiaru
|
# zmienia rozmiar obrazka w zaleznosci od rozmiaru
|
||||||
|
57
wozek.py
57
wozek.py
@ -1,12 +1,13 @@
|
|||||||
import pygame
|
|
||||||
import ekran
|
import ekran
|
||||||
|
import pygame,math
|
||||||
|
from packageList import listOfPackages
|
||||||
|
|
||||||
|
|
||||||
class Wozek():
|
class Wozek():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.obecnyStan = None
|
self.obecnyStan = None
|
||||||
self.x = 55
|
# self.x = 55
|
||||||
self.y = 55
|
# self.y = 55
|
||||||
self.x_change = 0
|
self.x_change = 0
|
||||||
self.y_change = 0
|
self.y_change = 0
|
||||||
self.height = 64
|
self.height = 64
|
||||||
@ -22,29 +23,45 @@ class Wozek():
|
|||||||
#storage = ["none"] * 10
|
#storage = ["none"] * 10
|
||||||
storage = []
|
storage = []
|
||||||
max_size = 10
|
max_size = 10
|
||||||
|
ln = len(storage)
|
||||||
|
|
||||||
def add_element(element, storage, max_size):
|
def add_element(self, element):
|
||||||
if len(storage) < max_size:
|
if self.ln < self.max_size:
|
||||||
storage.append(element)
|
self.storage.append(element)
|
||||||
|
self.ln=self.ln+1
|
||||||
else:
|
else:
|
||||||
print("I'm full!")
|
print("I'm full!")
|
||||||
|
def remove_element(self):
|
||||||
def remove_element(storage):
|
if self.ln > 0:
|
||||||
if len(storage) > 0:
|
element = self.storage.pop()
|
||||||
place = storage.pop()
|
self.ln=self.ln-1
|
||||||
return place
|
return element
|
||||||
else:
|
else:
|
||||||
print("I'm empty!")
|
print("I'm empty!")
|
||||||
|
|
||||||
def dynamic_wozek_picture(wozek, storage):
|
def dynamic_wozek_picture(self):
|
||||||
if len(storage) == 0:
|
if self.ln == 0:
|
||||||
wozek.image = pygame.image.load("images/pusty_wozek.png")
|
self.image = pygame.image.load("images/pusty_wozek.png")
|
||||||
elif ((len(storage) > 0) and (len(storage) < 4)):
|
elif ((self.ln > 0) and (self.ln < 4)):
|
||||||
wozek.image = pygame.image.load("images/pelny_wozek_1_crate.png")
|
self.image = pygame.image.load("images/pelny_wozek_1_crate.png")
|
||||||
elif ((len(storage) > 3) and (len(storage) < 10)):
|
elif ((self.ln > 3) and (self.ln < 10)):
|
||||||
wozek.image = pygame.image.load("images/pelny_wozek_2_crates.png")
|
self.image = pygame.image.load("images/pelny_wozek_2_crates.png")
|
||||||
elif (len(storage) == 10):
|
elif (self.ln == 10):
|
||||||
wozek.image = pygame.image.load("images/pelny_wozek_full_3_crates.png")
|
self.image = pygame.image.load("images/pelny_wozek_full_3_crates.png")
|
||||||
|
|
||||||
|
|
||||||
|
def load_package(self):
|
||||||
|
for package in listOfPackages.list:
|
||||||
|
dist = math.sqrt((self.obecnyStan.x - package.x)**2 + (self.obecnyStan.y - package.y)**2)
|
||||||
|
if dist <= 50:
|
||||||
|
self.add_element(package)
|
||||||
|
listOfPackages.list.pop()
|
||||||
|
def drop_package(self):
|
||||||
|
package = self.remove_element()
|
||||||
|
if package is not None:
|
||||||
|
listOfPackages.list.append(package)
|
||||||
|
package.x = self.obecnyStan.x+50
|
||||||
|
package.y = self.obecnyStan.y
|
||||||
|
|
||||||
def __zainicjuj_stan_poczatkowy(self):
|
def __zainicjuj_stan_poczatkowy(self):
|
||||||
from wyszukiwanie import Stan
|
from wyszukiwanie import Stan
|
||||||
|
Loading…
Reference in New Issue
Block a user