Ejemplo n.º 1
0
    /// <summary>
    /// Инициализация
    /// </summary>
    public void Initialize(PlayerColor playerColor)
    {
        ClearSpaceContainer();
        ClearPieceContainer();

        chessGame = new ChessGame(playerColor);
        foreach (var piece in chessGame.chessBoard.GetAllChessPieces())
        {
            Vector3 position = BoardCoordToTransformPosition(piece.Key);
            var     c        = UIBuilder.CreateChessPiece(PieceContainer, position, CurrentCellSize, piece.Key, piece.Value, OnChessPieceClickHandler);
            c.gameObject.AddClickEventTrigger(OnChessPieceClickHandler);
        }

        Highlight.SetSize(CurrentCellSize);
        Highlight.SetVisibility(false);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Обновить фигуры по их перемещению
    /// </summary>
    /// <param name="move">перемещение фигур</param>
    private void UpdateChessPieces(Stack <ChessMove> move)
    {
        if (move == null || move.Count == 0)
        {
            return;
        }

        ChessMove currentMove = move.Pop();

        if (currentMove == null)
        {
            return;
        }

        ChessPieceScript pieceScript = FindChessPiece(currentMove.MovingPiece);

        if (!pieceScript)
        {
            Vector3 position = BoardCoordToTransformPosition(currentMove.From);
            pieceScript = UIBuilder.CreateChessPiece(PieceContainer, position, CurrentCellSize, currentMove.From, currentMove.MovingPiece, OnChessPieceClickHandler);
            pieceScript.gameObject.AddClickEventTrigger(OnChessPieceClickHandler);
            Destroy(FindChessPiece(currentMove.From).gameObject);
        }

        ChessPieceScript defeatedScript = FindChessPiece(currentMove.DefeatedPiece);

        /// скрыть захваченную фигуру
        if (defeatedScript)
        {
            defeatedScript.SetVisibility(false);
        }

        /// переместить фигуру
        if (pieceScript.Coordiantes != currentMove.To)
        {
            pieceScript.SetCoordinates(currentMove.To);
            Vector3 from = pieceScript.transform.position;
            Vector3 to   = BoardCoordToTransformPosition(currentMove.To);
            StartCoroutine(ChessPieceMoveCoroutine(pieceScript, from, to, new UnityAction(() => { UpdateChessPieces(move); })));
        }
    }