Пример #1
0
    public void MoveChessman(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            if (chessMate != null)
            {
                BoardHighlights.Instance.HideCheckedHighlight();
                chessMate.HidePowerEffect();
                chessMate = null;
            }

            Chessman c      = Chessmans[x, y];
            float    delays = 0f;

            // Check EnPassantMove
            ProcessEnPassantMove(c, x, y, out delays);

            // Eat chessman
            bool isEatChess = false;
            if (c != null && c.isWhite != isWhiteTurn)
            {
                delays = DELAY_TIME;
                c.RotateEach(ROTATE_TIME);
                c.DestroyAfter(delays);

                BoardHighlights.Instance.ShowKillerHighlight(new Vector3(x + 0.5f, 0, y + 0.5f));
                BoardHighlights.Instance.HideKillerHighlightAfter(delays);
                isEatChess = true;

                if (c.GetType() == typeof(King))
                {
                    EndGame();
                    return;
                }
            }

            BoardHighlights.Instance.ShowHoverHighlight(new Vector3(x + 0.5f, 0, y + 0.5f));

            // check if pawn step on final line
            ProcessIfPawnStepOnFinalLine(x, y);

            // Move selected chessman to x, y position
            MoveSelectedChessmanTo(x, y, delays);

            // Checkmate
            if (!IsCheckmate(Chessmans[x, y].PossibleMove()) && isEatChess)
            {
                selectedChessman.PlayPowerEffectFor(DELAY_TIME);
            }
            ProcessCheckmate(x, y);

            // Change turn
            isWhiteTurn = !isWhiteTurn;
        }

        BoardHighlights.Instance.HideHighlights();
        selectedChessman = null;
    }
Пример #2
0
    private void ProcessEnPassantMove(Chessman c, int x, int y, out float delay)
    {
        delay = 0;
        if (x == EnPassantMove[0] && y == EnPassantMove[1])
        {
            if (isWhiteTurn)
            {
                c = Chessmans[x, y - 1];
            }
            else
            {
                c = Chessmans[x, y + 1];
            }

            c.RotateEach(ROTATE_TIME);
            c.DestroyAfter(DELAY_TIME);

            //selectedChessman.RotateEach(ROTATE_TIME);

            delay = DELAY_TIME;
        }

        EnPassantMove[0] = -1;
        EnPassantMove[1] = -1;
        // EnPassant
        if (selectedChessman.GetType() == typeof(Pawn))
        {
            if (selectedChessman.CurrentY == 1 && y == 3)
            {
                EnPassantMove[0] = x;
                EnPassantMove[1] = y - 1;
            }
            else if (selectedChessman.CurrentY == 6 && y == 4)
            {
                EnPassantMove[0] = x;
                EnPassantMove[1] = y + 1;
            }
        }
    }