59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
#!/usr/bin/python3
|
|
import copy
|
|
|
|
import pygame
|
|
import random
|
|
|
|
from app.fields import *
|
|
from app.utils import get_class
|
|
|
|
|
|
class Board:
|
|
def __init__(self, fields=None):
|
|
if fields is None:
|
|
fields = []
|
|
self.__fields = fields
|
|
self.create_board()
|
|
self.fill()
|
|
self.generate_board()
|
|
# print(self.__fields)
|
|
|
|
def get_fields(self) -> list:
|
|
return self.__fields
|
|
|
|
def get_field(self, x: int, y: int) -> Field:
|
|
return self.__fields[x][y]
|
|
|
|
def create_board(self) -> None:
|
|
for i in range(HORIZONTAL_NUM_OF_FIELDS):
|
|
self.__fields.append([])
|
|
for j in range(VERTICAL_NUM_OF_FIELDS):
|
|
self.__fields[i].append(None)
|
|
|
|
def fill(self) -> None:
|
|
for i in range(len(self.__fields)):
|
|
for j in range(len(self.__fields[i])):
|
|
self.__fields[i][j] = random.choice(FIELD_TYPES).capitalize()
|
|
|
|
def generate_board(self) -> None:
|
|
for x in range(len(self.__fields)):
|
|
for y in range(len(self.__fields[x])):
|
|
field_type = self.__fields[x][y]
|
|
c = get_class("app.fields", field_type)
|
|
field = c()
|
|
self.__fields[x][y] = field
|
|
|
|
def draw(self, screen: pygame.Surface) -> None:
|
|
for x in range(len(self.__fields)):
|
|
for y in range(len(self.__fields[x])):
|
|
field = self.__fields[x][y]
|
|
pos_x = x * FIELD_SIZE
|
|
pos_y = y * FIELD_SIZE
|
|
field.draw_field(screen, pos_x, pos_y)
|
|
|
|
def print_board(self) -> None:
|
|
for i in range(HORIZONTAL_NUM_OF_FIELDS):
|
|
for j in range(VERTICAL_NUM_OF_FIELDS):
|
|
print(f"{j} - {type(self.__fields[i][j]).__name__}", end=" | ")
|
|
print()
|