Exemplo n.º 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;
    }