示例#1
0
    private void MovePiece(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            Pieces c = PlayerPieces[x, y];

            if (c != null && c.isWhite != timer.GetComponent <Timer>().isWhiteTurn)
            {
                //Capture a piece

                //If it is Leader
                if (c.GetType() == typeof(Leader) && selectedPieces.GetType() == typeof(Leader))
                {
                    EndGame();
                    return;
                }

                if (selectedPieces.GetType() == typeof(Leader))
                {
                    if (c.GetType() == typeof(BasePiece))
                    {
                        LeaderKilledBase = true;
                    }
                    if (c.GetType() == typeof(SpecialPiece))
                    {
                        LeaderKilledSpecial = true;
                    }
                }
                if (selectedPieces.GetType() == typeof(Leader) && timer.GetComponent <Timer>().isWhiteTurn)
                {
                    if (c.GetType() == typeof(BasePiece))
                    {
                        LeaderKilledBaseWhite = true;
                        LeaderKilledBase      = false;
                    }
                    if (c.GetType() == typeof(SpecialPiece))
                    {
                        LeaderKilledSpecialWhite = true;
                        LeaderKilledSpecial      = false;
                    }
                }

                if (c.GetType() == typeof(Leader) && selectedPieces.GetType() != typeof(Leader) && c.isWhite == true)
                {
                    SpawnPieces(3, 2, 1);
                }
                else if (c.GetType() == typeof(Leader) && selectedPieces.GetType() != typeof(Leader) && c.isWhite != true)
                {
                    SpawnPieces(0, 3, 8);
                }
                Destroy(c.gameObject);
            }
            // Destroy(c.gameObject);

            PlayerPieces [selectedPieces.CurrentX, selectedPieces.CurrentY] = null;
            selectedPieces.transform.position = GetTileCenter(x, y);
            selectedPieces.SetPosition(x, y);
            PlayerPieces[x, y] = selectedPieces;
            //timer.GetComponent<Timer>().isWhiteTurn = !timer.GetComponent<Timer>().isWhiteTurn;
        }

        BoardHighlights.Instance.Hidehighlights();
        selectedPieces = null;
    }