Пример #1
0
    void moveBlocks()
    {
        nbOfRowsViewd += 1;

        print("---------------------   " + nbOfRowsViewd + "   ---------------------");

        //Checks a row in advance. If there is a cube in that spot. If there is than we should start resolving the cubes combi
        if (10 - (nbOfRowsViewd + 1) >= 0)
        {
            //We resolve the cubes combinaisons.  Now the index only starts if it finds a cube in rowA
            //print (" <R>    We could try to resolve the issues in here   " + createField.theTileNames[ 0, 10 - (nbOfRowsViewd + 1)  ]  +  "      "  +  createField.theField[ 0, 10 - (nbOfRowsViewd + 1) ]  +  "    <R> ");
        }


        //We the function is done checking through all the rows. We reset this function and generate a new cube.
        if (nbOfRowsViewd >= 10)
        {
            //We reset the value
            changeRow = 10;

            //We reset the counter as well
            nbOfRowsViewd = 0;

            //We generate a new cube Set[Shape?]
            generateCube();

            //We generate the visuals
            generateCube theGenerateCube = GetComponent <generateCube>();
            theGenerateCube.generateField();


            //We resolve the cubes combinaisons.
            //print("<R>      We resolve the cube issue in here      <R>");

            //We start by calling the fct
            //Invoke("moveBlocks", 1);


//			print ("<$$$> We are done Looping" + nbOfRowsViewd);
        }



        //Step4

        //Get the number of rows
        int theNumRows = (createField.theField.Length / 10);

        for (int theRow = 0; theRow < theNumRows; theRow++)
        {
            //We check if we came to an end.
            //print( "<////>  " + theRow);

            //print( "<////>" + createField.theTileNames[ theRow, changeRow]);
            //We populate the rows
            for (int incre = 0; incre < 2; incre++)
            {
                //print("%  " +  createField.theTileNames[ theRow, 10 ] + "   " + createField.theField[ theRow, 10 ] );

                // 1. We check for the next position while within the table range.
                // 2. If we are still within the range, We check if the next position is free. If so we move, if not we leave it is.

                //print ("< WWW> " + (changeRow + nextBelow1) + "     Rown/7: "   + cubeTemplate.Length/7 );



                //We make sure we dont get out of the index, when we reduce 1 or when we add 1.
                if (changeRow - nextBelow1 <= 0 && changeRow + nextBelow1 <= 11 && nbOfRowsViewd >= 10)
                {
                    print("*****************************  LOOP DONE FOR THE WHOLE TABLE " + nbOfRowsViewd + " ***************************");
                }
                else
                {
//					print ("below below " +  createField.theTileNames[ theRow, changeRow - nextBelow1 - nextBelow1 ] + "  its value: " + createField.theField[ theRow, changeRow - nextBelow1 - nextBelow1 ] );
                    // If the  next case is not empty we can start Generating a new cube.

/*					if( createField.theField[ theRow, changeRow - nextBelow1 - nextBelow1 ] != 0){
 *
 *                                              //print ("//////////////  Its Empty //////////////" +  createField.theTileNames[ theRow, changeRow - nextBelow1 - nextBelow1 ]  + "     " +  createField.theField[ theRow, changeRow - nextBelow1 - nextBelow1 ] );
 *                                              //print ("GENERATE A NEW CUBE HERE.");
 *
 *
 *                                      }
 *
 */



                    //We check the current Item.

                    /*if(createField.theField[ theRow, changeRow ] != 0){
                     *
                     *      print ( "<D> is not empty " + createField.theTileNames[ theRow, changeRow ] + "   " + createField.theField[ theRow, changeRow ] );
                     *
                     * }*/

//					print("<! Next Below !> " +  createField.theTileNames[ theRow, changeRow - nextBelow1 ] + "   " + createField.theField[ theRow, changeRow - nextBelow1 ] );

                    //If the next position is empty we move below
                    if (createField.theField[theRow, changeRow - nextBelow1] == 0)
                    {
//						print ("< +++ > THe next1 is empty: " +  createField.theTileNames[ theRow, changeRow - nextBelow1 ] + "   " + createField.theField[ theRow, changeRow - nextBelow1 ]  );

                        //We need to check the cube that has been inputted and move it as a set.

                        // 0. We check if next pos is available  [if empty]. If not we stop √
                        // 1. we check the current row. If it is not empty than we move the content to the empty position √
                        // 2.Then check the row that follows, if it is empty we do nothing. If it contains something we move it the current row. √
                        // 3. Then We check for the row again. Does it contain anything? If so we move it one square. If not we do nothing. √



                        //Schema
                        // [ +N,     Center,     -N  ]


                        //The next takes the info of the current position
                        createField.theField[theRow, changeRow - nextBelow1] = createField.theField[theRow, changeRow];

                        //print ("<Out Index>"   +  (changeRow-1 + nextBelow1)  + "   changer: " + changeRow + "    nextBelow: " + nextBelow1);


//						print ("chngR, NxtBelow*2: " + (changeRow + (nextBelow1 + nextBelow1)) );
                        if (changeRow + (nextBelow1 + nextBelow1) < 12)
                        {
                            //We delete the previous position
//							print("< ( C ) > We are about to copy previous: " + createField.theTileNames[ theRow, changeRow + nextBelow1 ] + " ==> " + createField.theTileNames[ theRow, changeRow ]);
                            createField.theField[theRow, changeRow] = createField.theField[theRow, changeRow + nextBelow1];


                            //print ("We activate a trap card: " + createField.theTileNames[ theRow, changeRow + nextBelow1] + "    " + createField.theField[ theRow, changeRow + nextBelow1] );
                            if (createField.theField[theRow, changeRow] == 0)
                            {
                                createField.theField[theRow, changeRow] = createField.theField[theRow, changeRow + nextBelow1];
                            }



                            //We recover a position where a bloc is assigned.
                            if (createField.theField[theRow, changeRow] != 0)
                            {
                                //print("-----Current: " + "   "  + createField.theTileNames[ theRow, changeRow ] + "   " + createField.theField[ theRow, changeRow ] + " Row Lenght: " + cubeTemplate.Length/7);

                                createField.theField[theRow, changeRow + nextBelow1] = createField.theField[theRow, changeRow + (cubeTemplate.Length / 7) - 1];
                                createField.theField[theRow, changeRow + (cubeTemplate.Length / 7) - 1] = 0;

                                /*if( createField.theField[ theRow, changeRow - nextBelow1 - nextBelow1 ] != 0){
                                 *      print("<+++++++>     START LOOPING     <+++++++>" + createField.theTileNames[ theRow, changeRow - nextBelow1] +  "   "  + createField.theField[ theRow, changeRow - nextBelow1]);
                                 * }*/
                            }
                            //createField.theField[ theRow, changeRow ] = 0; //= createField.theField[ theRow, (changeRow + nextBelow1 )];



                            ////////////////////////////////////
                            //RESOLUTION IS CALLED HERE
                            //Here we check if we can move if not we call for the Resolution
                            //if(createField.theField[ theRow, changeRow - (nextBelow1 + nextBelow1)] != 0){
                            if (createField.theField[theRow, (changeRow - nextBelow1)] != 0)
                            {
                                //print ("Its not empty  " +  createField.theTileNames[ theRow, changeRow - (nextBelow1 + nextBelow1)] + "    " + createField.theField[ theRow, changeRow - (nextBelow1 + nextBelow1)] );
//								print ("Its not empty  " +  createField.theTileNames[ theRow, changeRow - (nextBelow1)] + "    " + createField.theField[ theRow, changeRow - (nextBelow1)] );
//								print ("< -M- > We call for the Resolution "  );
                                //We call the function and test it out.
                                GameObject.Find("gameManager").GetComponent <cubeResolution>().resolve();
                            }
                        }
                        else
                        {
                            //If it is empty we get here. We delete the previous position an put nothing
                            createField.theField[theRow, changeRow] = 0;
                        }



                        //We delete the previous position
                        //createField.theField[ theRow, changeRow ] = createField.theField[ theRow, changeRow + nextBelow1] ;

                        //We Refresh the visuals
                        connectToGameManager = GameObject.Find("gameManager");
                        connectToGameManager.GetComponent <generateCube>().deleteAllCubes();
                        connectToGameManager.GetComponent <generateCube>().generateField();
                    }
                }
            }    //End For
        }        //End For



        //print("***" + Random.Range(0,(createField.theField.Length-1)/10));

        //If there is some space to generate a new cube we keep on doing what we are supposed to.
        if (isThereSomeSpace == true)
        {
            //We change row while staying within the table's index.
            if (changeRow <= 0)
            {
                //We reset the value
                changeRow = 10;
            }
            else
            {
                changeRow -= 1;

                //It calls itself again
                Invoke("moveBlocks", 1);
            }
        }
    }
Пример #2
0
    /*==================*/
    /* ==== Cube Types ====*/

    // [0]	Empty
    // [1]	Heart
    // [2]	Star
    // [3]	Triangle
    // [4]	Square
    // [5]	Spade



    //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



    // Use this for initialization
    public void initMe()
    {
//		print("++++++++++  " +  changeRow  + "  ++++++++++");
        //0. We create a row and add the info in the array.
        //1. We loop through the cubes we want to add.	We check the content of each cell.
        //2. We copy all the info into the top row of the array
        //3. We generate the cube's visual      //3a. We delete all the cubes that were on the scene.
        //4. We start moving them until there is no space for them to move.  //4a. We look below and make sure we are not out of range. We check if the next row is empty. If so, we move the cubes a row below
        //5. We find the matches and delete any match of 3 or more.


        //Step 1

        //Get the number of rows. We check their content.

        /*int theNumRows = (createField.theField.Length/10);
         * for(int theRow = 0 ; theRow < theNumRows; theRow++){
         *
         *      //We populate the rows
         *      for(int incre = 0; incre < 1; incre++){
         *
         *              print("%  " +  createField.theTileNames[ theRow, 10 ] + "   " + createField.theField[ theRow, 10 ] );
         *
         *      }
         *
         * }	*/



        //Step 2


        for (int w = 0; w < cubeTemplate.Length / 7; w++)
        {
            //print ("<!> check Rows: " + cubeFormTest2[0 , w]);

            for (int u = 0; u < cubeTemplate.Length / (cubeTemplate.Length / 7); u++)
            {
                //print ("<!> check Rows: " + cubeTemplate[u , w]);
                //we copy the info and see what happens
                createField.theField[u, 10 - w] = cubeTemplate[u, w];
                //createField.theField[ u, 10 ] = cubeFormTest2[u , 0];
                //print ("###  " + createField.theField[ u, 10 ] + "    "  + createField.theTileNames[ u, 10 ] + "   // " + cubeFormTest[u , 0]);
            }
        }


        /*for(int u = 0; u <  cubeFormTest2.Length/2; u++ ){
         *
         *
         *      //we copy the info and see what happens
         *      createField.theField[ u, 10 ] = cubeFormTest2[u , 0];
         *      //print ("###  " + createField.theField[ u, 10 ] + "    "  + createField.theTileNames[ u, 10 ] + "   // " + cubeFormTest[u , 0]);
         *
         * }*/



        //Step 3

        //We generate the visual
        generateCube theGenerateCube = GetComponent <generateCube>();

        theGenerateCube.generateField();



        //We start by calling the fct
        Invoke("moveBlocks", 1);
    }