Projekt_Sztuczna_Inteligencja/minefield.py

40 lines
1.3 KiB
Python

import pygame
import project_constants as consts
import tile as tl
import mine as mn
class Minefield:
def __init__(self, minefield_data=None):
# create matrix of a desired size, fill it with empty tile objects
self.matrix = [[tl.Tile((i, j)) for i in range(consts.V_GRID_VER_TILES)] for j in range(consts.V_GRID_HOR_TILES)]
# serialize JSON, create matrix
# iterate through matrix fields
for x in range(consts.V_GRID_HOR_TILES):
for y in range(consts.V_GRID_VER_TILES):
# if there should be a mine, create one
mine = mn.Mine((x, y), 'f')
# change tile properties
self.matrix[x][y].update_color("green")
self.matrix[x][y].mine = mine
def draw(self, window):
# iterate through tiles
for column in self.matrix:
for tile in column:
pixel_coords = (
consts.V_SCREEN_PADDING + consts.V_TILE_SIZE * tile.position[0], # x
consts.V_SCREEN_PADDING + consts.V_TILE_SIZE * tile.position[1] # y
)
window.blit(tile.asset, pixel_coords)
if tile.mine is not None:
window.blit(tile.mine.asset, pixel_coords)