Example #1
0
    private void MoveChessman(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            Chessman c = Chessmans[x, y];
            if (c != null && c.isWhite != isWhiteTurn)
            {
                //capture the piece

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

                activeChessman.Remove(c.gameObject);
                Destroy(c.gameObject);
                audioSource.clip = killSound;
                audioSource.Play();
            }
            else
            {
                audioSource.clip = moveSound;
                audioSource.Play();
            }
            Chessmans[selectedChessman.currentX, selectedChessman.currentY] = null;
            selectedChessman.transform.position = GetTileCenter(x, y);
            Chessmans[x, y] = selectedChessman;
            selectedChessman.setPostion(x, y);
            isWhiteTurn = !isWhiteTurn;
        }
        BoardHighlights.Instance.HideHighlights();
        selectedChessman = null;
        // PrintChessmans();
    }