AIprojekt-wozek/Environment.py

48 lines
1.3 KiB
Python
Raw Normal View History

2022-03-24 20:02:21 +01:00
import numpy as np
from Shelf import Shelf
2022-04-04 20:08:45 +02:00
import pygame
2022-03-24 20:02:21 +01:00
from Grid import Grid
WINDOW_X = 1400
WINDOW_Y = 750
RECT_SIZE = 50
2022-04-04 20:08:45 +02:00
RECT_COLOR = (70, 77, 87)
2022-03-24 20:02:21 +01:00
class Environment:
def __init__(self, window):
self.window = window
self.grid = Grid(self.window)
2022-04-04 20:08:45 +02:00
# draws grid&shelves
2022-03-24 20:02:21 +01:00
def draw_itself(self):
2022-04-04 20:08:45 +02:00
self.compute_coordinates_of_shelves()
2022-03-24 20:02:21 +01:00
self.grid.draw_grid()
# computes shelves coordinates according to window size, might change later
def compute_coordinates_of_shelves(self):
2022-04-04 20:08:45 +02:00
matrix = self.create_data_world()
for idx, value in np.ndenumerate(matrix):
x = RECT_SIZE*idx[1]
y = RECT_SIZE*idx[0]
if value == 0:
pygame.draw.rect(self.window, RECT_COLOR, (x, y, RECT_SIZE, RECT_SIZE))
for idx, value in np.ndenumerate(matrix):
x = RECT_SIZE*idx[1]
y = RECT_SIZE*idx[0]
if value == 1:
shelf = Shelf(self.window, x,y)
shelf.draw()
def create_data_world(self):
matrix = np.zeros((16, 28))
shelf_y = 0
shelf_y1 = 9
for x in range(2, 22, 3):
matrix[shelf_y][x] = 1
matrix[shelf_y1][x] = 1
print(matrix)
return matrix