public void MovePieceToCell(Cell to)
    {
        TargetCell = to;
        if (!TargetCell)
        {
            transform.position = CurrentCell.gameObject.transform.position;
            return;
        }

        SoundEvents.PlayMoveSound();

        //PieceManager.PieceMoveEvent(this, CurrentCell, TargetCell);
        //SendMoveMsg(this, CurrentCell, TargetCell);
        //SendMove(this, CurrentCell, TargetCell);

        //TargetCell.RemovePiece();

        CurrentCell.currentPiece = null;

        CurrentCell = TargetCell;
        CurrentCell.currentPiece = this;

        transform.position = CurrentCell.transform.position;
        TargetCell         = null;

        PieceManager.SwitchSides();
    }
Exemple #2
0
    private void ProceedMove(MoveContent lastMove, string message)
    {
        if (lastMove.TakenPiece.PieceType.ToString() != "None")
        {
            var takenSrcCell = Extensions.FromPosition(lastMove.TakenPiece.Position);
            var takenPiece   = board.AllCells[takenSrcCell.x, takenSrcCell.y].currentPiece;

            if (takenPiece != null)
            {
                message += Extensions.PieceToStr(takenPiece) + " взятие ";
                takenPiece.Kill();
            }
        }

        if (lastMove.MovingPiecePrimary.PieceType.ToString() != "None")
        {
            var primarySrcCell = Extensions.FromPosition(lastMove.MovingPiecePrimary.SrcPosition);
            var primaryDstCell = Extensions.FromPosition(lastMove.MovingPiecePrimary.DstPosition);

            var piecePrimary = board.AllCells[primarySrcCell.x, primarySrcCell.y].currentPiece;
            if (piecePrimary != null)
            {
                if (lastMove.PawnPromotedTo == ChessPieceType.Queen)
                {
                    message += " Pawn повышение Queen ";
                    PromotePiece(piecePrimary as Pawn, board.AllCells[primaryDstCell.x, primaryDstCell.y],
                                 piecePrimary.mainColor,
                                 piecePrimary.mainColor == Color.black ? Colors.BlackPieces : Colors.WhitePieces);
                }
                else
                {
                    piecePrimary.MovePieceToCell(board.AllCells[primaryDstCell.x, primaryDstCell.y]);
                    SoundEvents.PlayMoveSound();
                    message += Extensions.PieceToStr(piecePrimary);
                }
            }
            else
            {
                Debug.Log("Piece not found and not created!");
            }
        }

        if (lastMove.MovingPieceSecondary.PieceType.ToString() != "None")
        {
            var secondarySrcCell = Extensions.FromPosition(lastMove.MovingPieceSecondary.SrcPosition);
            var secondaryDstCell = Extensions.FromPosition(lastMove.MovingPieceSecondary.DstPosition);
            var pieceSecondary   = board.AllCells[secondarySrcCell.x, secondarySrcCell.y].currentPiece;

            if (pieceSecondary != null)
            {
                message += " рокировка ";
                pieceSecondary.Place(board.AllCells[secondaryDstCell.x, secondaryDstCell.y]);
                SoundEvents.PlayMoveSound();
                message += Extensions.PieceToStr(pieceSecondary);
            }
            else
            {
                var msg = "pieceSecondary not found!";

                msg += " Src X " + secondarySrcCell.x + " Y " + secondarySrcCell.y;
                msg += " Dst X " + secondaryDstCell.x + " Y " + secondaryDstCell.y;
                Debug.LogError(msg);
                //StaticEvents.LogMsgEvent(msg, LogType.Exception);
            }
        }

        if (lastMove.EnPassantOccured)
        {
            message += " взятие на проходе ";
        }

        message += "\n" + lastMove.ToString();
        StaticEvents.LogMsgEvent(message, LogType.Log);
        CheckMove(engine);
        SwitchSides();
    }