2022-03-27 16:43:15 +02:00
|
|
|
from Code.Communication.Direction import Direction
|
|
|
|
from Code.Config import GeneralConfig, SquareConfig
|
2022-03-20 09:47:49 +01:00
|
|
|
from Code.UI import Square
|
2022-04-02 13:04:51 +02:00
|
|
|
from Code.UI.Shape import Shape
|
|
|
|
from Code.UI.Shapes import Shapes
|
2022-03-20 09:47:49 +01:00
|
|
|
from Code.UI.Square import Square
|
|
|
|
|
|
|
|
|
|
|
|
class Field:
|
2022-03-27 16:43:15 +02:00
|
|
|
def __init__(self):
|
2022-03-27 18:11:51 +02:00
|
|
|
self.width = GeneralConfig.fields_amount_x + 2
|
|
|
|
self.height = GeneralConfig.fields_amount_y + 2
|
2022-03-27 16:43:15 +02:00
|
|
|
self.field_shift = -10
|
|
|
|
self.squares = self._creat_squares()
|
2022-04-02 13:04:51 +02:00
|
|
|
self.shapes = {Shape.VERTICAL_GLIDER: Shapes().creat_vertical_glieder}
|
|
|
|
|
|
|
|
def create_shape(self, shape: Shape, start_square_pos):
|
|
|
|
self.squares = self.shapes[shape](start_square_pos, self.squares)
|
2022-03-27 16:43:15 +02:00
|
|
|
|
|
|
|
def _creat_squares(self):
|
|
|
|
squares = [
|
|
|
|
[Square(x_pos=j * SquareConfig.width + self.field_shift, y_pos=i * SquareConfig.height + self.field_shift)
|
|
|
|
for i in range(self.height)] for
|
|
|
|
j in range(self.width)]
|
|
|
|
|
|
|
|
return squares
|
|
|
|
|
|
|
|
def update_squares(self, squares):
|
|
|
|
self.squares = squares
|
|
|
|
|
|
|
|
def draw_squares(self, window):
|
|
|
|
for x in self.squares:
|
|
|
|
for y in x:
|
|
|
|
y.draw(window)
|
|
|
|
|
2022-04-02 13:04:51 +02:00
|
|
|
def get_edges(self) -> dict:
|
|
|
|
return {Direction.LEFT: self.get_left_edge(), Direction.RIGHT: self.get_right_edge(),
|
2022-03-27 16:43:15 +02:00
|
|
|
Direction.TOP: self.get_top(), Direction.BOTTOM: self.get_bottom_edge()}
|
2022-04-02 13:04:51 +02:00
|
|
|
|
|
|
|
def get_edge(self, edg_pos: Direction) -> list:
|
|
|
|
return self.get_edges()[edg_pos]
|
2022-03-27 16:43:15 +02:00
|
|
|
|
|
|
|
def get_top(self):
|
|
|
|
top_squares = []
|
|
|
|
for y in self.squares:
|
|
|
|
top_squares.append(y[1].active)
|
|
|
|
|
|
|
|
return top_squares
|
|
|
|
|
|
|
|
def get_bottom_edge(self):
|
|
|
|
right_squares = []
|
|
|
|
for y in self.squares:
|
|
|
|
right_squares.append(y[len(y) - 2].active)
|
|
|
|
return right_squares
|
|
|
|
|
|
|
|
def get_left_edge(self):
|
|
|
|
left_squares = []
|
|
|
|
for x in self.squares[1]:
|
|
|
|
left_squares.append(x.active)
|
|
|
|
return left_squares
|
|
|
|
|
|
|
|
def get_right_edge(self):
|
|
|
|
right_squares = []
|
|
|
|
|
|
|
|
for x in self.squares[len(self.squares[0]) - 2]:
|
|
|
|
right_squares.append(x.active)
|
|
|
|
|
|
|
|
return right_squares
|
|
|
|
|
|
|
|
def fill_ghost_edge(self, value: list):
|
|
|
|
|
|
|
|
edge_fn = {Direction.LEFT: self.fill_left_ghost_edge, Direction.RIGHT: self.fill_right_ghost_edge,
|
2022-03-27 18:11:51 +02:00
|
|
|
Direction.TOP: self.fill_top_ghost_edge, Direction.BOTTOM: self.fill_bottom_ghost_edge}
|
2022-03-27 16:43:15 +02:00
|
|
|
|
|
|
|
edge_fn(value)
|
|
|
|
|
|
|
|
def fill_right_ghost_edge(self, value: list):
|
2022-03-27 18:11:51 +02:00
|
|
|
# if len(value)== self.square.
|
2022-03-27 16:43:15 +02:00
|
|
|
for i in range(len(value)):
|
|
|
|
self.squares[len(self.squares[0]) - 1][i].active = value[i]
|
|
|
|
|
|
|
|
def fill_left_ghost_edge(self, value: list):
|
|
|
|
for i in range(len(value)):
|
|
|
|
self.squares[0][i].active = value[i]
|
|
|
|
|
2022-03-27 18:11:51 +02:00
|
|
|
def fill_top_ghost_edge(self, value):
|
2022-03-27 16:43:15 +02:00
|
|
|
pass
|
|
|
|
|
2022-03-27 18:11:51 +02:00
|
|
|
def fill_bottom_ghost_edge(self, value):
|
2022-03-27 16:43:15 +02:00
|
|
|
pass
|