2023-05-06 12:57:48 +02:00
|
|
|
import time
|
|
|
|
from typing import Tuple
|
2023-04-20 20:54:58 +02:00
|
|
|
import pygame
|
2023-03-27 12:10:08 +02:00
|
|
|
|
2023-05-06 12:57:48 +02:00
|
|
|
from wyszukiwanie import Stan, SearchSpace
|
|
|
|
|
|
|
|
# from main import screen, miejsce
|
|
|
|
|
2023-04-20 20:54:58 +02:00
|
|
|
# screen nie działa
|
2023-03-27 12:10:08 +02:00
|
|
|
|
|
|
|
class Wozek():
|
2023-05-06 12:57:48 +02:00
|
|
|
def __init__(self, y, x):
|
|
|
|
# self.x = 55
|
|
|
|
# self.y = 55
|
2023-05-06 14:59:23 +02:00
|
|
|
self.x_change = 0
|
|
|
|
self.y_change = 0
|
2023-03-27 12:10:08 +02:00
|
|
|
self.height = 64
|
|
|
|
self.width = 64
|
|
|
|
self.image = pygame.image.load("images/pusty_wozek.png")
|
2023-05-06 12:57:48 +02:00
|
|
|
# self.screen = pygame.display.set_mode((980, 980))
|
|
|
|
# self.miejsce = pygame.image.load('images/miejsce_paczek.png')
|
2023-03-27 12:10:08 +02:00
|
|
|
# Credit: Forklift icons created by Smashicons - Flaticon
|
|
|
|
# https://www.flaticon.com/free-icons/forklift
|
2023-05-06 12:57:48 +02:00
|
|
|
#self.__zainicjuj_stan_poczatkowy()
|
|
|
|
self.state = Stan(y, x, 0)
|
2023-03-27 12:10:08 +02:00
|
|
|
|
|
|
|
def draw(self):
|
2023-04-20 20:54:58 +02:00
|
|
|
from main import screen
|
2023-05-06 14:59:23 +02:00
|
|
|
# screen.blit(self.image, (self.x, self.y))
|
|
|
|
#screen.blit(self.image, (self.obecnyStan.x, self.obecnyStan.y))
|
|
|
|
screen.blit(self.image, (self.state.x, self.state.y))
|
|
|
|
def draw_bfs(self):
|
|
|
|
from main import screen
|
2023-04-20 20:54:58 +02:00
|
|
|
# screen.blit(self.image, (self.x, self.y))
|
2023-05-06 12:57:48 +02:00
|
|
|
#screen.blit(self.image, (self.obecnyStan.x, self.obecnyStan.y))
|
|
|
|
screen.blit(self.image, (self.state.x*98, self.state.y*98))
|
2023-03-27 12:10:08 +02:00
|
|
|
|
2023-04-20 20:54:58 +02:00
|
|
|
# storage = ["none"] * 10
|
2023-03-27 12:10:08 +02:00
|
|
|
storage = []
|
|
|
|
max_size = 10
|
|
|
|
|
|
|
|
def add_element(element, storage, max_size):
|
|
|
|
if len(storage) < max_size:
|
|
|
|
storage.append(element)
|
|
|
|
else:
|
|
|
|
print("I'm full!")
|
2023-04-20 20:54:58 +02:00
|
|
|
|
2023-03-27 12:10:08 +02:00
|
|
|
def remove_element(storage):
|
|
|
|
if len(storage) > 0:
|
|
|
|
place = storage.pop()
|
|
|
|
return place
|
|
|
|
else:
|
|
|
|
print("I'm empty!")
|
|
|
|
|
|
|
|
def dynamic_wozek_picture(wozek, storage):
|
|
|
|
if len(storage) == 0:
|
|
|
|
wozek.image = pygame.image.load("images/pusty_wozek.png")
|
|
|
|
elif ((len(storage) > 0) and (len(storage) < 4)):
|
|
|
|
wozek.image = pygame.image.load("images/pelny_wozek_1_crate.png")
|
|
|
|
elif ((len(storage) > 3) and (len(storage) < 10)):
|
|
|
|
wozek.image = pygame.image.load("images/pelny_wozek_2_crates.png")
|
|
|
|
elif (len(storage) == 10):
|
2023-04-20 20:54:58 +02:00
|
|
|
wozek.image = pygame.image.load("images/pelny_wozek_full_3_crates.png")
|
|
|
|
|
2023-05-06 12:57:48 +02:00
|
|
|
# def __zainicjuj_stan_poczatkowy(self):
|
|
|
|
# from wyszukiwanie import Stan
|
|
|
|
# # self.obecnyStan = Stan(55, 55, 3)
|
|
|
|
# self.obecnyStan = Stan(1, 1, 3)
|
|
|
|
|
2023-05-06 14:59:23 +02:00
|
|
|
# def _drive(self, actions):
|
2023-05-06 12:57:48 +02:00
|
|
|
# # for action in actions.reverse():
|
|
|
|
# for action in actions:
|
|
|
|
# self._move(action)
|
|
|
|
# pygame.event.pump()
|
|
|
|
# time.sleep(0.01)
|
|
|
|
# # self.screen.fill((51,51,51)) # removes object trail
|
|
|
|
# # self.screen.blit(self.miejsce, (430, 400))
|
|
|
|
# self.draw()
|
|
|
|
# pygame.display.flip()
|
|
|
|
|
|
|
|
def _move(self, action):
|
|
|
|
x = self.state.x
|
|
|
|
y = self.state.y
|
2023-05-06 14:59:23 +02:00
|
|
|
kierunek = self.state.kierunek
|
2023-05-06 12:57:48 +02:00
|
|
|
|
2023-05-06 14:59:23 +02:00
|
|
|
if action == "Lewo":
|
|
|
|
self.state.kierunek = 3 if kierunek == 0 else kierunek - 1
|
2023-05-06 12:57:48 +02:00
|
|
|
|
2023-05-06 14:59:23 +02:00
|
|
|
elif action == "Prawo":
|
|
|
|
self.state.kierunek = (kierunek + 1) % 4
|
2023-05-06 12:57:48 +02:00
|
|
|
|
2023-05-06 14:59:23 +02:00
|
|
|
elif action == "Do przodu":
|
|
|
|
new_x = x + 1 if kierunek == 1 else (x - 1 if kierunek == 3 else x)
|
|
|
|
new_y = y - 1 if kierunek == 0 else (y + 1 if kierunek == 2 else y)
|
2023-05-06 12:57:48 +02:00
|
|
|
|
2023-05-06 14:59:23 +02:00
|
|
|
self.state.x = new_x
|
|
|
|
self.state.y = new_y
|
2023-04-20 20:54:58 +02:00
|
|
|
|
|
|
|
# def ustaw_wozek_w_kierunku(self, kierunek):
|
|
|
|
# TODO
|
|
|
|
|