Exemplo n.º 1
0
 def is_element_at(self, point: Union[Point, Tuple[int]],
                   element_object: Union[Element, str]) -> bool:
     point = prepare_point(point)
     element_object
     if point.is_out_of_board(self._size):
         return False
     return element_object == self.get_element_at(point)
Exemplo n.º 2
0
 def get_shift_by_point(self, point: Union[Point, Tuple[int]]) -> int:
     point = prepare_point(point)
     return point.get_y() * self._size + point.get_x()
Exemplo n.º 3
0
 def get_element_at(self, point: Union[Point, Tuple[int]]) -> Element:
     """ Return an Element object at coordinates x,y."""
     point = prepare_point(point)
     return Element(self._layer[self._xy2strpos(point.get_x(),
                                                point.get_y())])
    def get_all_coords_after_rotation(self,
                                      anchor: Union[Point, Tuple[int]],
                                      rotation: int = 0) -> List[Point]:
        # anchor - левый нижний угол фигуры, аналогично приходящей с сервера в 'currentFigurePoint' координате
        # эксперементальный метод
        # возвращает все координаты фигуры - rotation: 0
        # возвращает координаты фигуры после вращения (rotation = 1, rotation = 2, и т.д)
        # чтобы понять лучше как работает данный метод посмотри тесты - CodeBattlePython/tests/test_client_methods.py
        anchor = prepare_point(anchor)
        shift_top_after_rotation = get_shift_after_rotation(
            "shift_top", rotation)
        shift_right_after_rotation = get_shift_after_rotation(
            "shift_right", rotation)
        shift_bottom_after_rotation = get_shift_after_rotation(
            "shift_bottom", rotation)
        shift_left_after_rotation = get_shift_after_rotation(
            "shift_left", rotation)

        elems_shift = {
            "BLUE": [
                getattr(anchor, shift_top_after_rotation)(1),
                anchor,
                getattr(anchor, shift_bottom_after_rotation)(1),
                getattr(anchor, shift_bottom_after_rotation)(2),
            ],
            "CYAN": [
                getattr(anchor, shift_top_after_rotation)(1),
                anchor,
                getattr(anchor, shift_bottom_after_rotation)(1),
                getattr(
                    getattr(anchor, shift_bottom_after_rotation)(1),
                    shift_left_after_rotation,
                )(1),
            ],
            "ORANGE": [
                getattr(anchor, shift_top_after_rotation)(1),
                anchor,
                getattr(anchor, shift_bottom_after_rotation)(1),
                getattr(
                    getattr(anchor, shift_bottom_after_rotation)(1),
                    shift_right_after_rotation,
                )(1),
            ],
            "YELLOW": [
                anchor,
                getattr(anchor, shift_right_after_rotation)(1),
                getattr(anchor, shift_bottom_after_rotation)(1),
                getattr(
                    getattr(anchor, shift_bottom_after_rotation)(1),
                    shift_right_after_rotation,
                )(1),
            ],
            "GREEN": [
                getattr(anchor, shift_left_after_rotation)(1),
                anchor,
                getattr(anchor, shift_top_after_rotation)(1),
                getattr(
                    getattr(anchor, shift_top_after_rotation)(1),
                    shift_right_after_rotation,
                )(1),
            ],
            "PURPLE": [
                getattr(anchor, shift_left_after_rotation)(1),
                anchor,
                getattr(anchor, shift_right_after_rotation)(1),
                getattr(anchor, shift_top_after_rotation)(1),
            ],
            "RED": [
                getattr(
                    getattr(anchor, shift_top_after_rotation)(1),
                    shift_left_after_rotation,
                )(1),
                getattr(anchor, shift_top_after_rotation)(1),
                anchor,
                getattr(anchor, shift_right_after_rotation)(1),
            ],
        }

        return elems_shift[self._name]