36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
|
import pygame
|
||
|
import random
|
||
|
from field import Field
|
||
|
|
||
|
GRID_CELL_PADDING = 3
|
||
|
GRID_CELL_WIDTH = 42
|
||
|
GRID_CELL_HEIGHT = 42
|
||
|
ROWS = 20
|
||
|
COLUMNS = 20
|
||
|
|
||
|
|
||
|
class Grid:
|
||
|
def __init__(self, textures):
|
||
|
self.textures = textures
|
||
|
self.grid = []
|
||
|
for row in range(ROWS):
|
||
|
self.grid.append([])
|
||
|
for _ in range(COLUMNS):
|
||
|
texture_path, converted_texture = self.get_random_texture()
|
||
|
field = Field(texture_path, converted_texture)
|
||
|
self.grid[row].append(field)
|
||
|
|
||
|
def get_random_texture(self):
|
||
|
texture_index = random.randint(0, len(self.textures) - 1)
|
||
|
return self.textures[texture_index]
|
||
|
|
||
|
def draw(self, screen):
|
||
|
for row in range(ROWS):
|
||
|
for column in range(COLUMNS):
|
||
|
box_rect = [(GRID_CELL_PADDING + GRID_CELL_WIDTH) * column + GRID_CELL_PADDING,
|
||
|
(GRID_CELL_PADDING + GRID_CELL_HEIGHT) * row + GRID_CELL_PADDING,
|
||
|
GRID_CELL_WIDTH,
|
||
|
GRID_CELL_HEIGHT]
|
||
|
image = self.grid[row][column].converted_texture
|
||
|
screen.blit(pygame.transform.scale(image, (GRID_CELL_WIDTH, GRID_CELL_HEIGHT)), box_rect)
|