Example #1
0
    private void SelectChessman(int x, int y)
    {
        if (Chessmoves[x, y] == null)
        {
            return;
        }
        if (Chessmoves[x, y].isWhite != isWhiteTurn)
        {
            return;
        }

        bool hasAtleastOneMove = false;

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

        allowedMoves            = Chessmoves[x, y].PossibleMove();
        selectedChessman        = Chessmoves[x, y];
        previousMat             = selectedChessman.GetComponent <MeshRenderer>().material;
        selectedMat.mainTexture = previousMat.mainTexture;
        selectedChessman.GetComponent <MeshRenderer>().material = selectedMat;
        BoardHighlights.Instance.HighlightAllowedMoves(allowedMoves);
    }
Example #2
0
    private void SpawnAllChess()
    {
        activeChessman = new List <GameObject>();
        Chessmoves     = new Chessmove[8, 8];
        EnPassantMove  = new int[2] {
            -1, -1
        };

        //BlackTeam
        //Rooks
        SpawnChess(6, 0, 0);
        SpawnChess(6, 7, 0);
        //Knight
        SpawnChess(7, 1, 0);
        SpawnChess(7, 6, 0);
        //Bishop
        SpawnChess(8, 2, 0);
        SpawnChess(8, 5, 0);
        //Queen
        SpawnChess(9, 3, 0);
        //King
        SpawnChess(10, 4, 0);
        //Pawn
        for (int i = 0; i < 8; i++)
        {
            SpawnChess(11, i, 1);
        }

        //WhiteTeam
        //Rooks
        SpawnChess(0, 0, 7);
        SpawnChess(0, 7, 7);
        //Knight
        SpawnChess2(1, 1, 7);
        SpawnChess2(1, 6, 7);
        //Bishop
        SpawnChess2(2, 2, 7);
        SpawnChess2(2, 5, 7);
        //Queen
        SpawnChess(3, 3, 7);
        //King
        SpawnChess(4, 4, 7);
        //Pawn
        for (int i = 0; i < 8; i++)
        {
            SpawnChess(5, i, 6);
        }
    }
Example #3
0
    private void MoveChessman(int x, int y)
    {
        if (allowedMoves[x, y])
        {
            Chessmove c = Chessmoves[x, y];
            if (c != null && c.isWhite != isWhiteTurn)
            {
                //if its the king
                if (c.GetType() == typeof(King))
                {
                    EndGame();
                    return;
                }
                //Destroyed A peice
                activeChessman.Remove(c.gameObject);
                Destroy(c.gameObject);
            }
            if (x == EnPassantMove[0] && y == EnPassantMove[1])
            {
                if (isWhiteTurn)
                {
                    c = Chessmoves[x, y - 1];
                    activeChessman.Remove(c.gameObject);
                    Destroy(c.gameObject);
                }
                else
                {
                    c = Chessmoves[x, y + 1];
                    activeChessman.Remove(c.gameObject);
                    Destroy(c.gameObject);
                }
            }
            EnPassantMove[0] = -1;
            EnPassantMove[1] = -1;
            if (selectedChessman.GetType() == typeof(Pawn))
            {
                if (y == 7)
                {
                    activeChessman.Remove(selectedChessman.gameObject);
                    Destroy(selectedChessman.gameObject);
                    SpawnChess(9, x, y);
                    selectedChessman = Chessmoves[x, y];
                }
                else if (y == 0)
                {
                    activeChessman.Remove(selectedChessman.gameObject);
                    Destroy(selectedChessman.gameObject);
                    SpawnChess(3, x, y);
                    selectedChessman = Chessmoves[x, y];
                }
                if (selectedChessman.CurrentY == 1 && y == 3)
                {
                    EnPassantMove[0] = x;
                    EnPassantMove[1] = y - 1;
                }
                else if (selectedChessman.CurrentY == 6 && y == 4)
                {
                    EnPassantMove[0] = x;
                    EnPassantMove[1] = y + 1;
                }
            }

            Chessmoves[selectedChessman.CurrentX, selectedChessman.CurrentY] = null;
            selectedChessman.transform.position = GetTileCenter(x, y);
            selectedChessman.SetPosition(x, y);
            Chessmoves[x, y] = selectedChessman;
            isWhiteTurn      = !isWhiteTurn;
        }

        selectedChessman.GetComponent <MeshRenderer>().material = previousMat;
        BoardHighlights.Instance.Hidehighlights();
        selectedChessman = null;
    }