.
This commit is contained in:
parent
d7edccf091
commit
7622e735a7
99
board
99
board
@ -1,14 +1,29 @@
|
||||
from asyncio.windows_events import NULL
|
||||
from lib2to3.pgen2.token import CIRCUMFLEX
|
||||
from queue import Queue
|
||||
import sys
|
||||
from unicodedata import name
|
||||
import pygame
|
||||
|
||||
screen = []
|
||||
objectArray = []
|
||||
|
||||
class Agent:
|
||||
class Object:
|
||||
def __init__(self, name, xPos, yPos):
|
||||
self.name = name
|
||||
self.xPos = xPos
|
||||
self.yPos = yPos
|
||||
|
||||
class Field:
|
||||
def __init__(self, xPos, yPos):
|
||||
self.xPos = xPos
|
||||
self.yPos = yPos
|
||||
self.visited = False
|
||||
self.parent = None
|
||||
|
||||
def printXandY(self):
|
||||
print("X: " + str(self.xPos) + ". Y: " + str(self.yPos))
|
||||
|
||||
|
||||
def draw(square_num, objectArr):
|
||||
#następne dwie linijki do odkomentowania, jak będzie wgrane zdjęcie do tła
|
||||
@ -43,32 +58,112 @@ def draw(square_num, objectArr):
|
||||
truck = pygame.image.load("car.png").convert_alpha() #tu ścieżka do zdjęcia w tle
|
||||
truck = pygame.transform.scale(truck, (square, square))
|
||||
screen.blit(truck, (circleX, circleY))
|
||||
|
||||
circleX = objectArray[1].xPos * square + square
|
||||
circleY = objectArr[1].yPos * square
|
||||
radius = 10
|
||||
grid_color = (255, 0, 0)
|
||||
pygame.draw.circle(screen, grid_color, (circleX, circleY), radius)
|
||||
|
||||
def kb_listen(objectArray, gridLength):
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_LEFT and objectArray[0].xPos > 0:
|
||||
objectArray[0].xPos = objectArray[0].xPos - 1
|
||||
print(objectArray[0].xPos)
|
||||
if event.key == pygame.K_RIGHT and objectArray[0].xPos < gridLength - 1:
|
||||
objectArray[0].xPos = objectArray[0].xPos + 1
|
||||
print(objectArray[0].xPos)
|
||||
if event.key == pygame.K_UP and objectArray[0].yPos > 1:
|
||||
objectArray[0].yPos = objectArray[0].yPos - 1
|
||||
print(objectArray[0].yPos)
|
||||
if event.key == pygame.K_DOWN and objectArray[0].yPos < gridLength:
|
||||
objectArray[0].yPos = objectArray[0].yPos + 1
|
||||
print(objectArray[0].yPos)
|
||||
if event.type == pygame.QUIT:
|
||||
sys.exit()
|
||||
|
||||
def validField():
|
||||
print("sda")
|
||||
|
||||
fieldQueue = []
|
||||
isGoalAchieved = False
|
||||
|
||||
def startQueue(agentX, agentY, fieldList, gridNum):
|
||||
currentX = agentX
|
||||
currentY = agentY
|
||||
currentIndex = currentY * gridNum + currentX
|
||||
|
||||
fieldQueue.append(fieldList[currentIndex])
|
||||
|
||||
while not checkGoal(currentIndex, fieldList, currentIndex):
|
||||
print("")
|
||||
|
||||
def checkGoal(index, fieldList, currentIndex):
|
||||
currentField = fieldQueue.pop(0)
|
||||
print("POPPED!!!")
|
||||
print(currentField.printXandY())
|
||||
##print(str(currentField.xPos) + " " + str(objectArray[1].xPos) + " " + str(currentField.yPos) + " " + str(objectArray[1].yPos))
|
||||
|
||||
## SPRAWDZAMY CZY DANE POLE JEST POLEM W KTORYM ZNAJDUJE SIE NASZ CEL
|
||||
if currentField.xPos == objectArray[1].xPos and currentField.yPos == objectArray[1].yPos:
|
||||
return True
|
||||
|
||||
## SPRAWDZAMY CZY DANE POLE ZOSTALO JUZ WCZESNIEJ ODWIEDZONE - JEZELI NIE TO USTAWIAMY STATUS
|
||||
if not currentField.visited:
|
||||
currentField.visited = True
|
||||
|
||||
## JEZELI DANE POLE NIE ZOSTALO ODWIEDZONE, TO DODAJEMY DO KOLEJKI WSZYSTKIE POLA OBOK I LECIMY DALEJ
|
||||
if currentIndex + 15 <= 224:
|
||||
fieldQueue.append(fieldList[currentIndex + 15])
|
||||
fieldList[currentIndex + 15].parent = fieldList[currentIndex]
|
||||
print("APPENDED!!!")
|
||||
print(fieldList[currentIndex + 15].printXandY())
|
||||
if currentIndex - 15 >= 0:
|
||||
fieldQueue.append(fieldList[currentIndex - 15])
|
||||
fieldList[currentIndex - 15].parent = fieldList[currentIndex]
|
||||
print("APPENDED!!!")
|
||||
print(fieldList[currentIndex + 15].printXandY())
|
||||
if (currentIndex + 1) % 15 != 0:
|
||||
fieldQueue.append(fieldList[currentIndex + 1])
|
||||
fieldList[currentIndex + 1].parent = fieldList[currentIndex]
|
||||
print("APPENDED!!!")
|
||||
print(fieldList[currentIndex + 15].printXandY())
|
||||
if (currentIndex - 1) % 15 != 14 or currentIndex - 1 >= 0:
|
||||
fieldQueue.append(fieldList[currentIndex - 1])
|
||||
fieldList[currentIndex - 1].parent = fieldList[currentIndex]
|
||||
print("APPENDED!!!")
|
||||
print(fieldList[currentIndex + 15].printXandY())
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
pygame.init() #inicjalizacja modułów, na razie niepotrzebna
|
||||
|
||||
#Tworzymy nowego playera, czy tam agenta
|
||||
agent = Agent("smieciarka", 5, 7)
|
||||
agent = Object("smieciarka", 1, 1)
|
||||
target = Object("cel", 10, 10)
|
||||
objectArray.append(agent)
|
||||
objectArray.append(target)
|
||||
|
||||
width = 600
|
||||
height = 530
|
||||
screen = pygame.display.set_mode((width, height)) #ustalanie rozmiarów okna
|
||||
|
||||
## OBLICZANIE SCIEZKI
|
||||
|
||||
## GENEROWANIE WSZYSTKICH POL - FIELDS
|
||||
fields = []
|
||||
for y in range(15):
|
||||
for x in range(15):
|
||||
newField = Field(x, y)
|
||||
newField.printXandY()
|
||||
fields.append(newField)
|
||||
|
||||
startQueue(objectArray[0].xPos, objectArray[0].yPos, fields, 15)
|
||||
|
||||
while 1:
|
||||
c = (255, 255, 255) #tymczasowy kolor tła - do usunięcia, jak już będzie zdjęcie
|
||||
|
Loading…
Reference in New Issue
Block a user