Beispiel #1
0
    private void SelectChessmen(int x, int y)
    {
        if (Chessmens[x, y] == null)
        {
            return;
        }

        if (Chessmens[x, y].isWite != isWiteTurn)
        {
            return;
        }

        bool hasAtLeastOneMove = false;

        allowedMoves = Chessmens[x, y].PossibleMove();
        for (int i = 0; i < 8; i++)
        {
            for (int j = 0; j < 8; j++)
            {
                if (allowedMoves[i, j])
                {
                    hasAtLeastOneMove = true;
                }
            }
        }
        if (!hasAtLeastOneMove)
        {
            return;
        }


        allowedMoves            = Chessmens[x, y].PossibleMove();
        selectedChessmen        = Chessmens[x, y];
        previousMat             = selectedChessmen.GetComponent <MeshRenderer>().material;
        selectedMat.mainTexture = previousMat.mainTexture;
        selectedChessmen.GetComponent <MeshRenderer>().material = selectedMat;
        BoardHighlights.Instance.HighlightAllowedMoves(allowedMoves);
    }
Beispiel #2
0
    private void MoveChessmen(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            Chessmen c = Chessmens[x, y];

            if (c != null && c.isWite != isWiteTurn)
            {
                //Caprure a piece

                //If it is a king
                if (c.GetType() == typeof(Korol))
                {
                    EndGame();
                    return;
                }

                activeChessman.Remove(c.gameObject);
                Destroy(c.gameObject);
            }

            if (selectedChessmen.GetType() == typeof(Peshka))
            {
                if (y == 7)
                {
                    activeChessman.Remove(selectedChessmen.gameObject);
                    Destroy(selectedChessmen.gameObject);
                    SpawnChessman(1, x, y);
                    selectedChessmen = Chessmens[x, y];
                }
                else if (y == 0)
                {
                    activeChessman.Remove(selectedChessmen.gameObject);
                    Destroy(selectedChessmen.gameObject);
                    SpawnChessman(7, x, y);
                }
            }


            Chessmens[selectedChessmen.CurrentX, selectedChessmen.CurrentY] = null;
            selectedChessmen.transform.position = GetTileCenter(x, y);
            selectedChessmen.SetPosition(x, y);
            Chessmens[x, y] = selectedChessmen;
            isWiteTurn      = !isWiteTurn;
        }

        selectedChessmen.GetComponent <MeshRenderer>().material = previousMat;
        BoardHighlights.Instance.Hidenhighlights();
        selectedChessmen = null;
    }