2019SZI-Projekt/UI/window.py

62 lines
1.7 KiB
Python
Raw Normal View History

import pygame as pg
2019-04-25 20:56:02 +02:00
import numpy as np
2019-04-25 18:25:37 +02:00
import random
2019-04-08 01:15:47 +02:00
from UI.grid import Grid, Node
2019-04-27 18:23:33 +02:00
from UI.Apath import APath
2019-04-25 20:56:02 +02:00
2019-04-08 12:16:50 +02:00
class Window():
2019-04-08 01:15:47 +02:00
def __init__(self, grid: Grid):
2019-04-15 12:54:29 +02:00
pg.init() # pylint: disable=no-member
# setup window
pg.display.set_caption('Inteligentna śmieciarka')
self.grid = grid
# assign to variables for brevity
2019-04-08 01:15:47 +02:00
cols = self.grid.cols
rows = self.grid.rows
width = Node.r_width
height = Node.r_height
margin = Node.r_margin
screen_width = cols * (width + margin) + 2 * margin
screen_height = rows * (height + margin) + 2 * margin
self.screen = pg.display.set_mode([screen_width, screen_height])
self.end = False
self.clock = pg.time.Clock()
grid.change_field(0, 0, 1)
grid.change_field(19, 19, 2)
2019-04-25 18:25:37 +02:00
#random obsticle
2019-04-27 18:23:33 +02:00
for x in range(100):
2019-04-25 18:25:37 +02:00
grid.change_field(random.randint(1,18),random.randint(1,18),3)
2019-04-25 20:56:02 +02:00
#path
path = [(i, i) for i in range(1, 20, 1)]
self.grid.draw_map(self.screen)
2019-04-25 18:25:37 +02:00
2019-04-27 18:23:33 +02:00
#copy table
2019-04-25 20:56:02 +02:00
array = [[self.grid.table[col][row] for row in range(cols)] for col in range(rows)]
2019-04-27 18:04:06 +02:00
2019-04-25 20:56:02 +02:00
2019-04-27 18:04:06 +02:00
path = APath(array,(0,0),(19,19))
print(path,"\n\n")
2019-04-25 18:25:37 +02:00
2019-04-27 18:23:33 +02:00
for index, t in enumerate(path):
x,y =t
if index != 0:
self.grid.change_field(path[index-1][0],path[index-1][1],4)
self.grid.change_field(x, y, 1)
2019-04-27 18:23:33 +02:00
self.grid.draw_node(self.screen, path[index-1][0],path[index-1][1])
self.grid.draw_node(self.screen, x, y)
pg.time.delay(500)
2019-04-15 12:54:29 +02:00
pg.quit() # pylint: disable=no-member
2019-04-25 20:56:02 +02:00