Exemplo n.º 1
0
    public void RpcMoveChessman(int x0, int y0, int x, int y)
    {
        if (Chessmans[x0, y0].PossibleMove(x, y))
        {
            Chessman c = Chessmans[x, y];
            if (c != null && c.isWhite != isWhiteTurn)
            {
                activeChessman.Remove(c.gameObject);
                if (c.IsKing())
                {
                    ClearBoard();
                    SpawnAllChessmans();
                    isWhiteTurn = true;
                    BoardHighlightsOffline.Instace.HideHighlights();
                    return;
                }
                Destroy(c.gameObject);
                audioSource.PlayOneShot(captureSound, 1f);
            }
            else
            {
                audioSource.PlayOneShot(moveSound, .6f);
            }

            Chessmans[x0, y0].transform.position = GetTileCenter(x, y);
            Chessmans[x0, y0].SetPosition(x, y);
            Chessmans[x0, y0].nMoves += 1;
            Chessmans[x, y]           = Chessmans[x0, y0];
            Chessmans[x0, y0]         = null;
            isWhiteTurn = !isWhiteTurn;
        }
        selectedChessman.transform.localScale = new Vector3(.1f, .1f, .1f);
        selectedChessman.GetComponent <Renderer>().material.color = Color.white;
        oldSelectionX = -1;
        oldSelectionY = -1;
        Vector3    pos = selectedChessman.transform.position;
        Quaternion rot = selectedChessman.transform.rotation;

        pos.y = 0f;
        selectedChessman.transform.position = pos;
        selectedChessman.transform.rotation = Quaternion.Euler(0f, rot.eulerAngles.y, 0f);
        // selectedChessman.transform.position = GetTileCenter(selectedChessman.CurrentX, selectedChessman.CurrentY);
        BoardHighlightsOffline.Instace.HideHighlights();
        selectedChessman = null;
    }