2020-04-26 13:32:20 +02:00
|
|
|
import astar
|
|
|
|
import shutil
|
|
|
|
import os
|
2020-03-29 16:12:46 +02:00
|
|
|
import pygame
|
2020-04-03 16:27:21 +02:00
|
|
|
import game
|
2020-04-03 16:20:20 +02:00
|
|
|
import random
|
2020-04-26 13:32:20 +02:00
|
|
|
<< << << < HEAD
|
|
|
|
== == == =
|
|
|
|
>>>>>> > 7cb3aa904cd3d316c84df69942bbfdf66561a2e9
|
2020-03-29 16:12:46 +02:00
|
|
|
|
2020-04-06 17:13:01 +02:00
|
|
|
# wysokosc i szerokosc kazdej kratki
|
2020-03-29 16:12:46 +02:00
|
|
|
WIDTH = 60
|
|
|
|
HEIGHT = 60
|
|
|
|
|
2020-04-06 17:13:01 +02:00
|
|
|
# margines pomiedzy kratkami
|
2020-03-29 16:12:46 +02:00
|
|
|
MARGIN = 5
|
|
|
|
|
2020-03-29 21:02:00 +02:00
|
|
|
# kolory
|
|
|
|
BLACK = (0, 0, 0)
|
|
|
|
WHITE = (255, 255, 255)
|
|
|
|
GREEN = (0, 255, 0)
|
|
|
|
RED = (255, 0, 0)
|
2020-04-17 15:16:00 +02:00
|
|
|
BLUE = (40, 50, 200)
|
2020-03-29 21:02:00 +02:00
|
|
|
GREY = (128, 128, 128)
|
2020-03-29 16:12:46 +02:00
|
|
|
|
2020-03-29 23:37:25 +02:00
|
|
|
|
2020-03-29 16:12:46 +02:00
|
|
|
class Smieciarka(pygame.sprite.Sprite):
|
|
|
|
def __init__(self, x, y):
|
|
|
|
self.x = x
|
|
|
|
self.y = y
|
2020-04-25 23:46:33 +02:00
|
|
|
self.pozycja = (self.x, self.y)
|
2020-03-29 23:37:25 +02:00
|
|
|
self.image = pygame.image.load('resources/plansza/smieciarka.png')
|
2020-04-17 13:56:29 +02:00
|
|
|
self.obraz = None
|
2020-04-17 14:02:53 +02:00
|
|
|
self.ruch = 1
|
2020-04-20 20:54:14 +02:00
|
|
|
self.plansza = None
|
|
|
|
self.obiekty = None
|
2020-03-29 16:12:46 +02:00
|
|
|
pygame.sprite.Sprite.__init__(self)
|
|
|
|
self.rect = pygame.Rect(self.x * WIDTH + MARGIN * self.x + MARGIN, self.y * HEIGHT + MARGIN * self.y, WIDTH,
|
|
|
|
HEIGHT)
|
|
|
|
|
2020-04-17 13:56:29 +02:00
|
|
|
def setObraz(self, obraz):
|
|
|
|
self.obraz = obraz
|
|
|
|
|
2020-04-03 16:20:20 +02:00
|
|
|
def rand_move(self):
|
2020-04-03 18:09:41 +02:00
|
|
|
rand_int = random.randint(0, 3)
|
|
|
|
if rand_int == 0:
|
2020-04-03 16:20:20 +02:00
|
|
|
self.w_lewo()
|
2020-04-03 18:09:41 +02:00
|
|
|
elif rand_int == 1:
|
2020-04-03 16:20:20 +02:00
|
|
|
self.w_prawo()
|
2020-04-03 18:09:41 +02:00
|
|
|
elif rand_int == 2:
|
2020-04-03 16:20:20 +02:00
|
|
|
self.w_gore()
|
2020-04-03 18:09:41 +02:00
|
|
|
elif rand_int == 3:
|
2020-04-03 16:20:20 +02:00
|
|
|
self.w_dol()
|
|
|
|
|
2020-04-25 23:46:33 +02:00
|
|
|
def astar_move(self, obiekty):
|
2020-04-26 13:32:20 +02:00
|
|
|
sciezka = astar.astar(obiekty, self.pozycja,
|
|
|
|
(random.randrange(15), random.randrange(15)))
|
2020-04-25 23:46:33 +02:00
|
|
|
print(sciezka)
|
|
|
|
for koord in sciezka:
|
|
|
|
if koord[0] == self.x - 1 and koord[1] == self.y:
|
|
|
|
self.w_lewo()
|
|
|
|
elif koord[0] == self.x + 1 and koord[1] == self.y:
|
|
|
|
self.w_prawo()
|
|
|
|
elif koord[0] == self.x and koord[1] + 1 == self.y:
|
|
|
|
self.w_gore()
|
|
|
|
elif koord[0] == self.x and koord[1] - 1 == self.y:
|
|
|
|
self.w_dol()
|
|
|
|
print("skonczylem")
|
|
|
|
|
2020-03-29 16:12:46 +02:00
|
|
|
def w_lewo(self):
|
2020-04-03 17:38:42 +02:00
|
|
|
if self.x > 0:
|
2020-04-25 15:42:45 +02:00
|
|
|
if self.ruch == 2:
|
|
|
|
self.image = pygame.image.load(
|
|
|
|
'resources/plansza/smieciarka.png')
|
|
|
|
self.ruch = 1
|
|
|
|
|
|
|
|
self.plansza[self.x - 1, self.y].setKolor(BLUE)
|
|
|
|
for i in range((WIDTH + MARGIN) // 5):
|
|
|
|
self.rect.x -= 5
|
|
|
|
self.obraz.blit(self.image, (self.rect.x, self.rect.y))
|
|
|
|
game.rysowaniePlanszy(self.obiekty)
|
|
|
|
self.x -= 1
|
2020-03-29 16:12:46 +02:00
|
|
|
|
|
|
|
def w_prawo(self):
|
2020-04-03 17:38:42 +02:00
|
|
|
if self.x < 14:
|
2020-04-25 15:42:45 +02:00
|
|
|
if self.ruch == 1:
|
|
|
|
self.image = pygame.transform.flip(self.image, True, False)
|
|
|
|
self.ruch = 2
|
|
|
|
|
|
|
|
self.plansza[self.x + 1, self.y].setKolor(BLUE)
|
|
|
|
for i in range((WIDTH + MARGIN) // 5):
|
|
|
|
self.rect.x += 5
|
|
|
|
self.obraz.blit(self.image, (self.rect.x, self.rect.y))
|
|
|
|
game.rysowaniePlanszy(self.obiekty)
|
|
|
|
self.x += 1
|
2020-03-29 16:12:46 +02:00
|
|
|
|
|
|
|
def w_gore(self):
|
2020-04-03 17:38:42 +02:00
|
|
|
if self.y > 0:
|
2020-04-25 15:42:45 +02:00
|
|
|
self.plansza[self.x, self.y - 1].setKolor(BLUE)
|
|
|
|
for i in range((WIDTH + MARGIN) // 5):
|
|
|
|
self.rect.y -= 5
|
|
|
|
self.obraz.blit(self.image, (self.rect.x, self.rect.y))
|
|
|
|
game.rysowaniePlanszy(self.obiekty)
|
|
|
|
self.y -= 1
|
2020-03-29 16:12:46 +02:00
|
|
|
|
|
|
|
def w_dol(self):
|
2020-04-03 17:38:42 +02:00
|
|
|
if self.y < 14:
|
2020-04-20 20:54:14 +02:00
|
|
|
if self.plansza[self.x, self.y + 1].jestPrzeszkoda is not True:
|
|
|
|
if self.plansza[self.x, self.y + 1].jestDomem is True:
|
2020-04-06 18:57:35 +02:00
|
|
|
if [self.x, self.y + 1] not in self.wspolrzedne_odwiedzonych_domow:
|
2020-04-26 13:32:20 +02:00
|
|
|
self.wspolrzedne_odwiedzonych_domow.append(
|
|
|
|
[self.x, self.y + 1])
|
2020-04-06 18:57:35 +02:00
|
|
|
self.zwiekszIloscOdwiedzonychDomow()
|
2020-04-17 13:56:29 +02:00
|
|
|
|
2020-04-20 20:54:14 +02:00
|
|
|
self.plansza[self.x, self.y + 1].setKolor(BLUE)
|
2020-04-17 15:05:28 +02:00
|
|
|
for i in range((WIDTH + MARGIN) // 5):
|
|
|
|
self.rect.y += 5
|
2020-04-17 13:56:29 +02:00
|
|
|
self.obraz.blit(self.image, (self.rect.x, self.rect.y))
|
2020-04-20 20:54:14 +02:00
|
|
|
game.rysowaniePlanszy(self.obiekty)
|
2020-04-03 17:38:42 +02:00
|
|
|
self.y += 1
|
2020-03-29 16:12:46 +02:00
|
|
|
|
2020-04-05 18:22:28 +02:00
|
|
|
def dodajPlastik(self, smiec):
|
|
|
|
self.plastik.append(smiec)
|
|
|
|
|
|
|
|
def dodajSzklo(self, smiec):
|
|
|
|
self.szklo.append(smiec)
|
|
|
|
|
|
|
|
def dodajPapier(self, smiec):
|
|
|
|
self.papier.append(smiec)
|
|
|
|
|
|
|
|
def dodajMetal(self, smiec):
|
|
|
|
self.metal.append(smiec)
|
|
|
|
|
2020-04-06 18:57:35 +02:00
|
|
|
def zwiekszIloscOdwiedzonychDomow(self):
|
|
|
|
self.odwiedzone_domy += 1
|
|
|
|
|
|
|
|
def getOdwiedzoneDomy(self):
|
|
|
|
return self.odwiedzone_domy
|
2020-04-25 15:42:45 +02:00
|
|
|
|
|
|
|
def setPlansza(self, plansza):
|
2020-04-20 20:54:14 +02:00
|
|
|
self.plansza = plansza
|
|
|
|
|
2020-04-25 15:42:45 +02:00
|
|
|
def setObiekty(self, obiekty):
|
2020-04-20 20:54:14 +02:00
|
|
|
self.obiekty = obiekty
|
|
|
|
|
2020-03-29 16:12:46 +02:00
|
|
|
|
|
|
|
class Kratka(pygame.sprite.Sprite):
|
2020-03-29 21:02:00 +02:00
|
|
|
def __init__(self, poz_x, poz_y):
|
2020-03-29 16:12:46 +02:00
|
|
|
self.pozX = poz_x
|
|
|
|
self.pozY = poz_y
|
2020-04-26 13:32:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
<< << << < HEAD
|
|
|
|
== == == =
|
2020-04-25 22:30:39 +02:00
|
|
|
self.pozycja = (self.pozX, self.pozY)
|
|
|
|
self.rodzic = None
|
2020-04-03 17:39:57 +02:00
|
|
|
self.jestDomem = False
|
2020-03-29 21:02:00 +02:00
|
|
|
self.jestKontenerem = False
|
|
|
|
self.jestWysypiskiem = False
|
2020-04-03 16:27:21 +02:00
|
|
|
self.jestPrzeszkoda = False
|
2020-04-26 13:32:20 +02:00
|
|
|
>>>>>> > 7cb3aa904cd3d316c84df69942bbfdf66561a2e9
|
2020-03-29 21:02:00 +02:00
|
|
|
self.kolor = GREY
|
2020-04-06 01:36:54 +02:00
|
|
|
self.obiekt = None
|
2020-04-25 22:30:39 +02:00
|
|
|
self.g = 0 # Distance to start node
|
|
|
|
self.h = 0 # Distance to goal node
|
|
|
|
self.f = 0 # Total cost
|
2020-03-29 16:12:46 +02:00
|
|
|
pygame.sprite.Sprite.__init__(self)
|
2020-03-29 17:27:02 +02:00
|
|
|
self.image = pygame.image.__class__
|
2020-03-29 21:02:00 +02:00
|
|
|
self.rect = pygame.Rect(self.pozX * WIDTH + MARGIN * self.pozX + MARGIN,
|
|
|
|
self.pozY * HEIGHT + MARGIN * self.pozY + MARGIN,
|
2020-03-29 16:12:46 +02:00
|
|
|
WIDTH, HEIGHT)
|
|
|
|
|
2020-04-25 22:30:39 +02:00
|
|
|
# Sort nodes
|
|
|
|
def __lt__(self, other):
|
|
|
|
return self.f < other.f
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return ('{0}'.format(self.pozycja))
|
|
|
|
|
|
|
|
# Compare nodes
|
|
|
|
def __eq__(self, other):
|
|
|
|
return True if self.pozycja == other.pozycja else False
|
|
|
|
|
2020-03-29 16:12:46 +02:00
|
|
|
def setImage(self, image):
|
|
|
|
self.image = image
|
2020-03-29 19:59:24 +02:00
|
|
|
|
2020-04-25 22:30:39 +02:00
|
|
|
def setRodzic(self, rodzic):
|
|
|
|
self.rodzic = rodzic
|
|
|
|
|
2020-04-06 18:16:38 +02:00
|
|
|
def setObiekt(self, obiekt):
|
2020-04-06 01:36:54 +02:00
|
|
|
self.obiekt = obiekt
|
|
|
|
|
2020-03-29 23:37:25 +02:00
|
|
|
def setKolor(self, kolor):
|
|
|
|
self.kolor = kolor
|