//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);
    }
Example #2
0
 private void deselectAllCorns()
 {
     for (int i = 0; i < cornRows; i++)
     {
         for (int j = 0; j < cornCols; j++)
         {
             CornController cc = cornObjects[i, j].GetComponent <CornController>();
             cc.selected = 0; cc.changeSprite();
         }
     }
 }
Example #3
0
 private void changeOneCornState(CornController cornContr)
 {
     if (cornContr.state == 0)        //State = "sano"
     {
         if (selectedPower == 0)      //Selected power => moon
         {
             cornContr.state = 3;     //new state = "gusanos"
         }
         else if (selectedPower == 1) //power => rain
         {
             cornContr.state = 4;     //new state = "ahogado"
         }
         else if (selectedPower == 3) //power => sun
         {
             cornContr.state = 2;     // new state = "quemado"
         }
     }
     else if (cornContr.state == 1)   //State = "brote"
     {
         if (selectedPower == 0)      //Selected power => moon
         {
             cornContr.state = 3;     //new state = "gusanos"
         }
         else if (selectedPower == 1) //power => rain
         {
             cornContr.state = 0;     //new state = "ahogado"
         }
         else if (selectedPower == 2) //power => mountain
         {
             cornContr.state = 0;     // new state = "quemado"
         }
         else if (selectedPower == 3) //power => sun
         {
             cornContr.state = 5;     // new state = "vacio"
         }
     }
     else if (cornContr.state == 2)   //State = "quemado"
     {
         if (selectedPower == 0)      //Selected power => moon
         {
             cornContr.state = 0;     //new state = "sano"
         }
         else if (selectedPower == 1) //power => rain
         {
             cornContr.state = 0;     //new state = "sano"
         }
         else if (selectedPower == 3) //power => sun
         {
             cornContr.state = 5;     // new state = "vacio"
         }
     }
     else if (cornContr.state == 3)   //State = "gusanos"
     {
         if (selectedPower == 0)      //Selected power => moon
         {
             cornContr.state = 5;     //new state = "vacio"
         }
         else if (selectedPower == 2) //power => mountain
         {
             cornContr.state = 0;     // new state = "sano"
         }
         else if (selectedPower == 3) //power => sun
         {
             cornContr.state = 0;     // new state = "sano"
         }
     }
     else if (cornContr.state == 4)   //State = "ahogado"
     {
         if (selectedPower == 0)      //Selected power => moon
         {
             cornContr.state = 0;     //new state = "sano"
         }
         else if (selectedPower == 1) //power => rain
         {
             cornContr.state = 5;     //new state = "vacio"
         }
         else if (selectedPower == 2) //power => mountain
         {
             cornContr.state = 5;     // new state = "vacio"
         }
         else if (selectedPower == 3) //power => sun
         {
             cornContr.state = 0;     // new state = "sano"
         }
     }
     else if (cornContr.state == 5) //State = "vacio"
     {
         if (selectedPower == 1)    //power => rain
         {
             cornContr.state = 1;   //new state = "brote"
         }
     }
     cornContr.changeSprite();
 }