2022-03-21 22:12:01 +01:00
|
|
|
import pygame
|
|
|
|
|
2022-03-22 21:52:05 +01:00
|
|
|
from enumy_i_slowniki import *
|
2022-04-16 16:45:37 +02:00
|
|
|
from obserwacja import *
|
2022-03-21 22:12:01 +01:00
|
|
|
from stale import *
|
|
|
|
|
|
|
|
|
|
|
|
class PoleKraty:
|
2022-04-16 16:45:37 +02:00
|
|
|
gora: any
|
|
|
|
start: any
|
|
|
|
|
|
|
|
def __init__(self, krata, wiersz, kolumna):
|
|
|
|
self.krata = krata
|
2022-03-21 22:12:01 +01:00
|
|
|
self.bok = self.krata.bokPola
|
|
|
|
self._wiersz = wiersz
|
|
|
|
self._kolumna = kolumna
|
|
|
|
self.okreslGore()
|
|
|
|
self.okreslStart()
|
|
|
|
|
|
|
|
def okreslGore(self):
|
|
|
|
self.gora = (self.bok + self.krata.odstepMiedzyPolami) * self.wiersz + self.krata.odstepMiedzyPolami
|
|
|
|
|
|
|
|
def okreslStart(self):
|
|
|
|
self.start = (self.bok + self.krata.odstepMiedzyPolami) * self.kolumna + self.krata.odstepMiedzyPolami
|
|
|
|
|
|
|
|
def getWiersz(self):
|
|
|
|
return self._wiersz
|
|
|
|
|
|
|
|
def setWiersz(self, x):
|
|
|
|
self._wiersz = x
|
|
|
|
self.okreslGore()
|
|
|
|
|
|
|
|
def getKolumna(self):
|
|
|
|
return self._kolumna
|
|
|
|
|
|
|
|
def setKolumna(self, x):
|
|
|
|
self._kolumna = x
|
|
|
|
self.okreslStart()
|
|
|
|
|
|
|
|
wiersz = property(getWiersz, setWiersz)
|
|
|
|
kolumna = property(getKolumna, setKolumna)
|
|
|
|
|
2022-04-06 14:05:40 +02:00
|
|
|
def skopiuj(self):
|
|
|
|
return PoleKraty(self.krata, self.wiersz, self.kolumna)
|
|
|
|
|
2022-03-21 22:12:01 +01:00
|
|
|
|
2022-04-16 16:45:37 +02:00
|
|
|
class Krata(Obserwowany):
|
|
|
|
krata: []
|
|
|
|
|
2022-03-21 22:12:01 +01:00
|
|
|
def __init__(self, okno):
|
|
|
|
self.okno = okno
|
|
|
|
self.liczbaPolPoziomo = LICZBA_POL_W_POZIOMIE
|
|
|
|
self.liczbaPolPionowo = LICZBA_POL_W_PIONIE
|
|
|
|
self.bokPola = BOK_POLA
|
|
|
|
self.odstepMiedzyPolami = ODSTEP_MIEDZY_POLAMI
|
2022-03-22 21:52:05 +01:00
|
|
|
self.utworzPustaKrate()
|
2022-03-21 22:12:01 +01:00
|
|
|
self.agent = None
|
|
|
|
|
|
|
|
def utworzPustaKrate(self):
|
|
|
|
self.krata = []
|
2022-03-22 21:52:05 +01:00
|
|
|
for wiersz in range(self.liczbaPolPionowo):
|
2022-03-21 22:12:01 +01:00
|
|
|
self.krata.append([])
|
|
|
|
for kolumna in range(self.liczbaPolPoziomo):
|
2022-03-22 21:52:05 +01:00
|
|
|
zawartosc_pola = ZawartoscPola.PUSTE
|
|
|
|
self.krata[wiersz].append(zawartosc_pola)
|
2022-03-21 22:12:01 +01:00
|
|
|
|
2022-03-22 11:20:58 +01:00
|
|
|
def narysujKrate(self):
|
2022-03-21 22:12:01 +01:00
|
|
|
self.okno.fill(SZARY1)
|
2022-03-22 21:52:05 +01:00
|
|
|
for wiersz in range(self.liczbaPolPionowo):
|
2022-03-21 22:12:01 +01:00
|
|
|
for kolumna in range(self.liczbaPolPoziomo):
|
|
|
|
start = (self.odstepMiedzyPolami + self.bokPola) * kolumna + self.odstepMiedzyPolami
|
2022-03-22 21:52:05 +01:00
|
|
|
gora = (self.odstepMiedzyPolami + self.bokPola) * wiersz + self.odstepMiedzyPolami
|
|
|
|
kolor_pola = ZawartoscPolaNaKolorPola[self.krata[wiersz][kolumna]]
|
|
|
|
pygame.draw.rect(self.okno, kolor_pola, [start, gora, self.bokPola, self.bokPola])
|
2022-03-21 22:12:01 +01:00
|
|
|
|
2022-03-22 14:32:26 +01:00
|
|
|
def narysujKrateAlternatywnie(self):
|
|
|
|
self.okno.fill(SZARY1)
|
|
|
|
for i in range(LICZBA_POL_W_POZIOMIE + 1):
|
|
|
|
new_height = i * (BOK_POLA + ODSTEP_MIEDZY_POLAMI)
|
|
|
|
new_width = i * (BOK_POLA + ODSTEP_MIEDZY_POLAMI)
|
|
|
|
pygame.draw.line(self.okno, CZARNY, (0, new_height), (SZEROKOSC_OKNA, new_height), ODSTEP_MIEDZY_POLAMI)
|
|
|
|
pygame.draw.line(self.okno, CZARNY, (new_width, 0), (new_width, WYSOKOSC_OKNA), ODSTEP_MIEDZY_POLAMI)
|
|
|
|
|
2022-04-16 16:45:37 +02:00
|
|
|
def powiadomObserwatorow(self):
|
|
|
|
for obserwator in self.obserwatorzy:
|
|
|
|
obserwator.odbierzPowiadomienie(self)
|