Exemplo n.º 1
0
    //Move the Chessman to selected position
    private void MoveChessman(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            Chessman c = chessmans[x, y];
            if (c != null && c.isWhite != isWhiteTurn)
            {
                //If King captured
                if (c.GetType() == typeof(King))
                {
                    //End the game
                    if (c.isWhite)
                    {
                        print("Black team win the game");
                    }
                    else
                    {
                        print("White team win the game");
                    }
                }
                //Capture a piece
                activeChessman.Remove(c.gameObject);
                Destroy(c.gameObject);
            }

            if (selectedChessman.GetType() == typeof(Pawn))
            {
                if (y == 7)
                {
                    activeChessman.Remove(selectedChessman.gameObject);
                    Destroy(selectedChessman.gameObject);
                    spawnChessman(1, x, y, Quaternion.Euler(0, 90f, 0));
                    selectedChessman = chessmans[x, y];
                }
                else if (y == 0)
                {
                    activeChessman.Remove(selectedChessman.gameObject);
                    Destroy(selectedChessman.gameObject);
                    spawnChessman(7, x, y, Quaternion.Euler(0, -90f, 0));
                    selectedChessman = chessmans[x, y];
                }
            }

            chessmans[selectedChessman.CurrentX, selectedChessman.CurrentY] = null;
            selectedChessman.transform.position = GetTileCenter(x, y);
            selectedChessman.SetPosisiton(x, y);
            chessmans[x, y] = selectedChessman;
            isWhiteTurn     = !isWhiteTurn;

            if (isWhiteTurn)
            {
                vCamWhite.gameObject.SetActive(true);
            }
            else
            {
                vCamWhite.gameObject.SetActive(false);
            }
        }
        BoardHighlight.Instance.HideHighlights();
        selectedChessman = null;
    }