2020-04-07 16:58:12 +02:00
|
|
|
import pygame, sys
|
|
|
|
from traktor import Traktor
|
2020-04-28 21:15:29 +02:00
|
|
|
import dijkstra as di
|
2020-04-07 16:58:12 +02:00
|
|
|
|
|
|
|
class Game(object):
|
2020-04-28 21:15:29 +02:00
|
|
|
|
2020-04-07 16:58:12 +02:00
|
|
|
def __init__(self):
|
2020-04-28 21:15:29 +02:00
|
|
|
|
|
|
|
#to da sie chyba zrobic lepiej
|
|
|
|
#lokalizacje odpowiednich punktow na planszy
|
|
|
|
lokalizacje = [[0,0],
|
|
|
|
[100, 0],
|
|
|
|
[200, 0],
|
|
|
|
[300, 0],
|
|
|
|
[400, 0],
|
|
|
|
[400, 100],
|
|
|
|
[300, 100],
|
|
|
|
[200, 100],
|
|
|
|
[100, 100],
|
|
|
|
[0, 100],
|
|
|
|
[0, 200],
|
|
|
|
[100, 200],
|
|
|
|
[200, 200],
|
|
|
|
[300, 200],
|
|
|
|
[400, 200],
|
|
|
|
[400, 300],
|
|
|
|
[300, 300],
|
|
|
|
[200, 300],
|
|
|
|
[100, 300],
|
|
|
|
[0, 300],
|
|
|
|
[0, 400],
|
|
|
|
[100, 400],
|
|
|
|
[200, 400],
|
|
|
|
[300, 400],
|
|
|
|
[400, 400]]
|
|
|
|
|
2020-04-07 16:58:12 +02:00
|
|
|
#inicjalizacja
|
|
|
|
pygame.init()
|
2020-04-28 21:15:29 +02:00
|
|
|
self.pole = pygame.display.set_mode((501,501))
|
|
|
|
|
2020-04-07 16:58:12 +02:00
|
|
|
self.player = Traktor(self)
|
|
|
|
|
2020-04-28 21:15:29 +02:00
|
|
|
sterowanie = int(input("Podaj czy chcesz sam sterowac traktorem - 1, czy chcesz podawac punkty - 0: "))
|
|
|
|
if sterowanie == 1:
|
|
|
|
sterowanie = True
|
|
|
|
else:
|
|
|
|
sterowanie = False
|
|
|
|
|
|
|
|
#iohiu;i;gou;ihpiu
|
2020-04-07 16:58:12 +02:00
|
|
|
while True:
|
|
|
|
#obsługa zdarzń
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
pygame.quit()
|
|
|
|
sys.exit(0)
|
2020-04-28 21:15:29 +02:00
|
|
|
#sterowanie traktorem
|
|
|
|
if sterowanie:
|
|
|
|
if event.type == pygame.KEYDOWN :
|
|
|
|
if event.key == pygame.K_UP:
|
|
|
|
self.player.y -= 100
|
|
|
|
if self.player.y < 0:
|
|
|
|
self.player.y = 0
|
|
|
|
if event.key == pygame.K_DOWN:
|
|
|
|
self.player.y += 100
|
|
|
|
if self.player.y > 400:
|
|
|
|
self.player.y = 400
|
|
|
|
if event.key == pygame.K_RIGHT:
|
|
|
|
self.player.x += 100
|
|
|
|
if self.player.x > 400:
|
|
|
|
self.player.x = 400
|
|
|
|
if event.key == pygame.K_LEFT:
|
|
|
|
self.player.x -= 100
|
|
|
|
if self.player.x < 0:
|
|
|
|
self.player.x = 0
|
|
|
|
else:
|
|
|
|
#po spacji wpisujemy punkty
|
|
|
|
if event.type == pygame.KEYDOWN :
|
|
|
|
if event.key == pygame.K_SPACE:
|
|
|
|
pt = 0
|
|
|
|
punkt1 = int(input("Podaj pierwszy punkt (liczba od 0 do 24): "))
|
|
|
|
punkt2 = int(input("Podaj drugi punkt (liczba od 0 do 24): "))
|
|
|
|
dist = di.dijkstra(self.player.punkt)
|
|
|
|
|
|
|
|
if dist[punkt1] < dist[punkt2]:
|
|
|
|
print("Wybralem pierwszy punkt")
|
|
|
|
pt = punkt1
|
|
|
|
else:
|
|
|
|
print("Wybralem drugi punkt")
|
|
|
|
pt = punkt2
|
|
|
|
|
|
|
|
self.player.x = lokalizacje[pt][0]
|
|
|
|
self.player.y = lokalizacje[pt][1]
|
|
|
|
self.player.punkt = pt
|
|
|
|
|
|
|
|
|
2020-04-07 16:58:12 +02:00
|
|
|
pygame.display.update()
|
|
|
|
|
|
|
|
#rysowanie
|
|
|
|
self.pole.fill((0,0,0))
|
2020-04-28 21:15:29 +02:00
|
|
|
self.krata()
|
2020-04-07 16:58:12 +02:00
|
|
|
self.rysowanie()
|
|
|
|
pygame.display.flip()
|
2020-04-28 21:15:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
def krata(self):
|
|
|
|
#wymiary
|
|
|
|
w= 500
|
|
|
|
rows = 5
|
|
|
|
sizeBtw = w // rows
|
2020-04-07 16:58:12 +02:00
|
|
|
|
2020-04-28 21:15:29 +02:00
|
|
|
x = 0
|
|
|
|
y = 0
|
|
|
|
for r in range(rows):
|
|
|
|
x = x + sizeBtw
|
|
|
|
y = y + sizeBtw
|
2020-04-07 16:58:12 +02:00
|
|
|
|
2020-04-28 21:15:29 +02:00
|
|
|
#rysownie karaty
|
|
|
|
pygame.draw.line(self.pole, (255,255,255), (x,0), (x,w))
|
|
|
|
pygame.draw.line(self.pole, (255,255,255), (0,y), (w,y))
|
|
|
|
|
2020-04-07 16:58:12 +02:00
|
|
|
|
|
|
|
def rysowanie(self):
|
2020-04-28 21:15:29 +02:00
|
|
|
#rysowanie agenta
|
2020-04-07 16:58:12 +02:00
|
|
|
self.player.rysowanie()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__=="__main__":
|
|
|
|
Game()
|