//Check if the number of selected corns are equal to the
    //showing maya number
    private int checkCorrectCorns()
    {
        //Get the rows and columns in the grid of corns
        int rows = mgc.cornRows, cols = mgc.cornCols;
        //Count of selected corns
        int count = 0;

        //Corn grid
        GameObject [,] corns = mgc.cornObjects;
        //Iterate in the corn grid
        for (int i = 0; i < rows; i++)
        {
            for (int j = 0; j < cols; j++)
            {
                //Get the controller for the [i,j] corn
                CornController cornCont = corns[i, j].GetComponent <CornController>();
                //If the corn is selected and the corn state is healthy
                if (cornCont.selected == 1 && cornCont.state == 0)
                {
                    cornCont.setCornState(Random.Range(1, 5)); //change the corn state
                    count++;                                   //increment the count of selected corns
                }
                cornCont.selected = 0;                         //deselect the corn
                cornCont.changeSprite();                       //change the corn sprite
            }
        }
        return(count);
    }
Beispiel #2
0
    void initCornGrid2()
    {
        for (int i = 0; i < cornCols; i++)
        {
            cornObjects [0, i] = fila1 [i];
            cornObjects [1, i] = fila2 [i];
            cornObjects [2, i] = fila3 [i];
            cornObjects [3, i] = fila4 [i];
        }
        int N = cornRows * cornCols, st;

        for (int i = 0; i < cornRows; i++)
        {
            for (int j = 0; j < cornCols; j++)
            {
                int value = Random.Range(0, N);
                if (value < N / 2)
                {
                    st = 0;
                }
                else if (value < 5 * N / 8)
                {
                    st = 1;
                }
                else if (value < 6 * N / 8)
                {
                    st = 2;
                }
                else if (value < 7 * N / 8)
                {
                    st = 3;
                }
                else
                {
                    st = 4;
                }
                CornController cornScript = cornObjects [i, j].GetComponent <CornController> ();
                cornScript.setCornState(st);
            }
        }
    }