Example #1
0
	private ArrayList FindMatch (GameObject[,] cells)
	{
		ArrayList stack = new ArrayList ();
		for (var x = 0; x <= cells.GetUpperBound (0); x++) {
			for (var y = 0; y <= cells.GetUpperBound (1); y++) {
				var thiscell = cells [x, y];
				if (thiscell.name == "empty(Clone)")
					continue;
				int matchCount = 0;
				int y2 = cells.GetUpperBound (1);
				int y1;
				for (y1 = y + 1; y1 <= y2; y1++) {
					if (cells [x, y1].name == "empty(Clone)" ||
					    (thiscell.name != cells [x, y1].name))
						break;
					matchCount++;
				}
				if (matchCount >= 2) {
					y1 = Mathf.Min (cells.GetUpperBound (1), y1 - 1);
					for (var y3 = y; y3 <= y1; y3++) {
						if (!stack.Contains (cells [x, y3])) {
							stack.Add (cells [x, y3]);
						}
					}
				}
			}
		}

		for (var y = 0; y <= cells.GetUpperBound (1); y++) {
			for (var x = 0; x <= cells.GetUpperBound (0); x++) {
				var thiscell = cells [x, y];
				if (thiscell.name == "empty(Clone)")
					continue;


				int matchCount = 0;
				int x2 = cells.GetUpperBound (0);
				int x1;
				for (x1 = x + 1; x1 <= x2; x1++) {
					if (cells [x1, y].name == "empty(Clone)" ||
					    (thiscell.name != cells [x1, y].name))
						break;
					matchCount++;
				}
				if (matchCount >= 2) {
					x1 = Mathf.Min (cells.GetUpperBound (0), x1 - 1);
					for (var x3 = x; x3 <= x1; x3++) {
						if (!stack.Contains (cells [x3, y])) {
							stack.Add (cells [x3, y]);
						}
					}
				}
			}
		}
		return stack;
	}
    // Write a general move command that uses only the directions
    public void Move(GameObject[,] brickArray, MoveDirection moveDir)
    {
        // Settings to figure out which way it is going

        int brickArrayWidth = brickArray.GetUpperBound(0) + 1;
        int brickArrayHeight = brickArray.GetUpperBound(1) + 1;
        int newX;
        int newY;
        int xModifier = 0;
        int yModifier = 0;
        int startX = 0;
        int startY = 0;
        bool movingUpAndDown = false;

        newX = startX;
        newY = startY;

        if(moveDir == MoveDirection.Up)
        {
            // This should all be done by column

            newY = brickArrayHeight - 1;
            newX = 0;
            // Set up here which sides will be affected
            for(int x = 0; x < brickArrayWidth; x++)
            {
                for(int y = brickArrayHeight - 1; y >= 0; y--)
                {
                    if(brickArray[x,y] == null || brickArray[x, y] == gameModel.CurrentActiveBrick)
                    {

                    }
                    else if(brickArray[x,y] != null)
                    {
                        BrickComponent brickComponet = brickArray[x, y].GetComponent<BrickComponent>();
                        if(brickComponet.Side == Sides.Top || brickComponet.Side == Sides.Bottom)
                        {
                        }
                        else if(brickComponet.Side == Sides.Left || brickComponet.Side == Sides.Right)
                        {
                            gameModel.MoveBrick(brickArray[x,y], moveDir, false);
                        }

                        newY -= 1;
                    }
                }
                newY = brickArrayHeight - 1;
                newX += 1;
            }
        }
        else if(moveDir == MoveDirection.Down)
        {
            newY = 0;
            newX = 0;
            // Set up here which sides will be affected
            for(int x = 0; x < brickArrayWidth; x++)
            {
                for(int y = 0; y < brickArrayHeight; y++)
                {
                    if(brickArray[x,y] == null || brickArray[x, y] == gameModel.CurrentActiveBrick)
                    {

                    }
                    else if(brickArray[x,y] != null)
                    {
                        BrickComponent brickComponet = brickArray[x, y].GetComponent<BrickComponent>();
                        if(brickComponet.Side == Sides.Top || brickComponet.Side == Sides.Bottom)
                        {

                        }
                        else if(brickComponet.Side == Sides.Left || brickComponet.Side == Sides.Right)
                        {
                            gameModel.MoveBrick(brickArray[x,y], moveDir, false);
                        }

                        newY += 1;
                    }
                }
                newY = 0;
                newX += 1;
            }
        }
        else if(moveDir == MoveDirection.Left)
        {
            newX = 0;
            newY = brickArrayHeight - 1;
            // Set up here which sides will be affected
            for(int y = brickArrayHeight - 1; y >= 0; y--)
            {
                for(int x = 0; x < brickArrayWidth; x++)
                {
                    if(brickArray[x,y] == null || brickArray[x, y] == gameModel.CurrentActiveBrick)
                    {

                    }
                    else if(brickArray[x,y] != null)
                    {
                        BrickComponent brickComponet = brickArray[x, y].GetComponent<BrickComponent>();
                        if(brickComponet.Side == Sides.Left || brickComponet.Side == Sides.Right)
                        {

                        }
                        else if(brickComponet.Side == Sides.Top || brickComponet.Side == Sides.Bottom)
                        {
                            gameModel.MoveBrick(brickArray[x,y], moveDir, false);
                        }

                        newX += 1;
                    }
                }
                newX = 0;
                newY -= 1;
            }
        }
        else if(moveDir == MoveDirection.Right)
        {
            newX = brickArrayWidth - 1;
            newY = brickArrayHeight - 1;
            // Set up here which sides will be affected
            for(int y = brickArrayHeight - 1; y >= 0; y--)
            {
                for(int x = brickArrayWidth - 1; x >= 0; x--)
                {
                    if(brickArray[x,y] == null || brickArray[x, y] == gameModel.CurrentActiveBrick)
                    {

                    }
                    else if(brickArray[x,y] != null)
                    {
                        BrickComponent brickComponet = brickArray[x, y].GetComponent<BrickComponent>();
                        if(brickComponet.Side == Sides.Left || brickComponet.Side == Sides.Right)
                        {

                        }
                        else if(brickComponet.Side == Sides.Top || brickComponet.Side == Sides.Bottom)
                        {
                            gameModel.MoveBrick(brickArray[x,y], moveDir, false);

                        }

                        newX -= 1;
                    }
                }
                newX = brickArrayWidth - 1;
                newY -= 1;
            }
        }
        moveProcessor.UpdateBrickArray();
    }
    public void MoveUp(GameObject[,] brickArray)
    {
        // This takes the entire BrickArray and goes column by column moving every block that is in the side up to the top of its column.

        // First

        int brickArrayWidth = brickArray.GetUpperBound(0) + 1;
        int brickArrayHeight = brickArray.GetUpperBound(1) + 1;

        int newX = 0;
        int newY = brickArrayHeight - 1;

        for(int x = 0; x < brickArrayWidth; x++)
        {

            for(int y = brickArrayHeight - 1; y >= 0; y--)
            {
                if(brickArray[x,y] == null)
                {

                }
                // Need to add in a check to see which side the brick is on
                else if(brickArray[x,y] != null)
                {
                    Debug.Log(brickArray[x,y].ToString());
                    brickArray[x,y].GetComponent<BrickComponent>().Location = new Vector2((float)newX, (float)newY);
                    newY--;
                }

            }
            newY = brickArrayHeight - 1;
            newX++;
        }
        moveProcessor.UpdateBrickArray();
    }
    //This will generate out the field based off of the size, and add/remove any spots. if the spot has something and it is removed then that is removed with it.
    public void Update_Field_Size(int new_x, int new_y)
    {
        i_field_width = new_x;
        i_field_height = new_y;
        //This is the highest path spot that is placed on the new field, 0 means the path maker is not on the field at all and can ignore.
        int i_Highest_Path_Spot = 0;
        int[] i_All_Spots = new int[2000];
        GameObject Path_Maker_Temp = null;

        //we make a new field that will eventually replace the old field.
        GameObject[,] New_All_Field_Spots = new GameObject[i_field_width, i_field_height];

        //Debug.Log("Newx: " + i_field_width);
        //Debug.Log("Newy: " + i_field_height);

        //Debug.Log("Oldx: " + All_Field_Spots.GetUpperBound(0));
        //Debug.Log("Oldy: " + All_Field_Spots.GetUpperBound(1));

        //go through each of the field spots and give it the game object and then update it.
        for (int i = 0; i <= New_All_Field_Spots.GetUpperBound(0); i++)
        {
            for (int j = 0; j <= New_All_Field_Spots.GetUpperBound(1); j++)
            {
                //Create/initilze a spot for this spot.
                GameObject New_Game_Field_Spot = Instantiate(Empty_Field_Spot);
                New_Game_Field_Spot.transform.parent = The_Field_Test.transform;
                //now we add the spot to the spot on the all field spots.
                New_All_Field_Spots[i, j] = New_Game_Field_Spot;

                //now we tell that spot to move it's gameobject to the correct location on said grid.
                //we use 1.28 because the sprite is 256 pixles, but devided by half so 128. so 1.28 is how far apart they are.
                Vector2 New_Vect = new Vector2(i * 1.28f, j * -1.28f);
                New_Game_Field_Spot.transform.localPosition = New_Vect;

            }
        }

        //see if the x or y is lower to know if we need to check for path moves.
        if (New_All_Field_Spots.GetUpperBound(0) < All_Field_Spots.GetUpperBound(0) || New_All_Field_Spots.GetUpperBound(1) < All_Field_Spots.GetUpperBound(1))
        {
            //this will be what we will check through x/y wise.
            int Check_x = All_Field_Spots.GetUpperBound(0);
            int Check_y = All_Field_Spots.GetUpperBound(1);

            //we get the lower of the two values.
            if (New_All_Field_Spots.GetUpperBound(0) < All_Field_Spots.GetUpperBound(0))
            {
                Check_x = New_All_Field_Spots.GetUpperBound(0);
            }
            if (New_All_Field_Spots.GetUpperBound(1) < All_Field_Spots.GetUpperBound(1))
            {
                Check_y = New_All_Field_Spots.GetUpperBound(1);
            }



            //going to go through all the places with the check x/y and see if there is a path, then if so we will move the maker to the highest spot.
            //Then we need to make sure everything is moved and if it can't be moved it's removed.
            //Only the path maker and start will not be removed, they are at worse moved to the invintory.

            //get the path maker if it exsists
            for (int i = 0; i <= All_Field_Spots.GetUpperBound(0); i++)
            {
                for (int j = 0; j <= All_Field_Spots.GetUpperBound(1); j++)
                {
                    //go through each of the children for that spot and move them to the new spot.
                    for (int q = 0; q < All_Field_Spots[i, j].gameObject.transform.childCount; q++)
                    {
                        if (All_Field_Spots[i, j].gameObject.transform.GetChild(q).name == G_Tags.Name_Path_Maker)
                        {
                            //this is the path maker.
                            Path_Maker_Temp = (All_Field_Spots[i, j].gameObject.transform.GetChild(q).gameObject);
                        }
                        if (All_Field_Spots[i, j].gameObject.transform.GetChild(q).name == G_Tags.Name_Start_Point)
                        {
                            //make sure it's within the x/y.
                            if (i > Check_x || j > Check_y)
                            {
                                //it's outside the new field so we move it back to invintory.
                                Move_To_Invintory(All_Field_Spots[i, j].gameObject.transform.GetChild(q).gameObject);
                            }

                        }
                    }
                }
            }

                    //go through and move everything but path while counting how high path goes.
                    //go through each of the field spots and give it the game object and then update it.
                    for (int i = 0; i <= Check_x; i++)
            {
                for (int j = 0; j <= Check_y; j++)
                {
                    //Debug.Log("Running_Check");

                    //go through each of the children for that spot and move them to the new spot.
                    for (int q = 0; q < All_Field_Spots[i, j].gameObject.transform.childCount; q++)
                    {
                        //Debug.Log("Child_FOund");
                        //check if the object is part of the path. ONLY FOR PATH SEGEMENTS.
                        if (All_Field_Spots[i, j].gameObject.transform.GetChild(q).tag.Contains(G_Tags.Tag_Path_Placement))
                        {
                            //need to check the path number.
                            int i_Temp_Path_Number = int.Parse((All_Field_Spots[i, j].gameObject.transform.GetChild(q).name.Split('_')[1]));
                            //Debug.Log("Number_Path_Found = " + i_Temp_Path_Number);
                            //add it to all spots to find the highest path.
                            i_All_Spots[i_Highest_Path_Spot] = i_Temp_Path_Number;
                            //add temp path, this is just used for counting here, will reset after done.
                            i_Highest_Path_Spot++;

                        }


                        //we move it to the parent's location.
                        All_Field_Spots[i, j].gameObject.transform.GetChild(q).transform.position = New_All_Field_Spots[i, j].gameObject.transform.position;
                        //we set the new parent.
                        All_Field_Spots[i, j].gameObject.transform.GetChild(q).transform.parent = New_All_Field_Spots[i, j].gameObject.transform;

                        //now everything is over on the new all field.
                    }
                }
            }


            //check if there is a path maker.
            if (Path_Maker_Temp != null)
            {
                //reset the path number
                i_Highest_Path_Spot = 0;

                


                
                i_Highest_Path_Spot = 0;
                //need to find the highest path that does not break the chain.
                for (int i = 0; i < i_All_Spots.GetLength(0); i++)
                {
                    //check if the next link is found.
                    if (i_All_Spots[i] == i_Highest_Path_Spot + 1)
                    {
                        //increase the highest path spot by 1.
                        i_Highest_Path_Spot++;
                        //reset i back to 0 to keep checking. if it gets through then max has been found.
                        i = 0;
                    }
                }

                //we need to set the path number to the correct spot for adding/removing future paths!
                i_Path_Number = i_Highest_Path_Spot;

                //Debug.Log("Highest_Spot = " + i_Highest_Path_Spot);


                //now check if there is a highest path
                if (i_Highest_Path_Spot > 0)
                {

                    //now we need to remove all the numbers greater than the highest path and move the path maker to that spot.
                    for (int i = 0; i <= New_All_Field_Spots.GetUpperBound(0); i++)
                    {
                        for (int j = 0; j <= New_All_Field_Spots.GetUpperBound(1); j++)
                        {
                            //go through each of the children for that spot and move them to the new spot.
                            for (int q = 0; q < New_All_Field_Spots[i, j].gameObject.transform.childCount; q++)
                            {
                                //check if the object is part of the path. ONLY FOR PATH SEGEMENTS.
                                if (New_All_Field_Spots[i, j].gameObject.transform.GetChild(q).tag.Contains( G_Tags.Tag_Path_Placement))
                                {
                                    //need to check the path number.
                                    int i_Temp_Path_Number = int.Parse((New_All_Field_Spots[i, j].gameObject.transform.GetChild(q).name.Split('_')[1]));

                                    //now check if the spot is higher than the highest path.
                                    if (i_Temp_Path_Number > i_Highest_Path_Spot)
                                    {
                                        //we remove this spot since it was cut off.
                                        //we destory the gameobject.
                                        GameObject.Destroy(New_All_Field_Spots[i, j].gameObject.transform.GetChild(q).gameObject);
                                    }

                                    //check if it is the highest.
                                    if (i_Temp_Path_Number == i_Highest_Path_Spot)
                                    {
                                        //we need to move the path maker here and remove this path spot then update the path maker.

                                        //get the character.
                                        char char_Temp = New_All_Field_Spots[i, j].gameObject.transform.GetChild(q).name.Split('_')[0][0];
                                        Path_Maker_Temp.GetComponent<LE_Path_Creator>().Reset_Children(char_Temp);

                                        //remove old.
                                        GameObject.Destroy(New_All_Field_Spots[i, j].gameObject.transform.GetChild(q).gameObject);
                                        //now move the path maker there.
                                        Path_Maker_Temp.transform.position = New_All_Field_Spots[i, j].gameObject.transform.position;
                                        Path_Maker_Temp.transform.parent = New_All_Field_Spots[i, j].gameObject.transform;
                                        //will do the update for remove at the end.
                                    }
                                }
                            }
                        }
                    }
                }
                //we move the path maker back to the invintory.
                else
                {
                    Move_To_Invintory(Path_Maker_Temp);
                }

            }

        }
        //both values are larger or equal so we can just do a simple move without worry.
        else
        {
            //go through each of the field spots and give it the game object and then update it.
            for (int i = 0; i <= All_Field_Spots.GetUpperBound(0); i++)
            {
                for (int j = 0; j <= All_Field_Spots.GetUpperBound(1); j++)
                {
                    //go through each of the children for that spot and move them to the new spot.
                    for (int q = 0; q < All_Field_Spots[i, j].gameObject.transform.childCount; q++)
                    {
                        //we move it to the parent's location.
                        All_Field_Spots[i, j].gameObject.transform.GetChild(q).transform.position = New_All_Field_Spots[i, j].gameObject.transform.position;
                        //we set the new parent.
                        All_Field_Spots[i, j].gameObject.transform.GetChild(q).transform.parent = New_All_Field_Spots[i, j].gameObject.transform;
                    }
                }
            }
        }

        //now we go through all of the old spots and remove/delete them and then do the switch.
        //go through each of the field spots and give it the game object and then update it.
        for (int i = 0; i <= All_Field_Spots.GetUpperBound(0); i++)
        {
            for (int j = 0; j <= All_Field_Spots.GetUpperBound(1); j++)
            {
                //go through each of the children for that spot and move them to the new spot.
                for (int q = 0; q < All_Field_Spots[i, j].gameObject.transform.childCount; q++)
                {
                    //destory any children. might be decorations/left over path, ect, ect.
                    GameObject.Destroy(All_Field_Spots[i, j].gameObject.transform.GetChild(q).gameObject);
                }
                    //we destory the gameobject.
                    GameObject.Destroy(All_Field_Spots[i, j].gameObject);
            }
        }
        //now we do the switch.
        All_Field_Spots = New_All_Field_Spots;


    }
Example #5
0
	private void DoEmptyDown (ref GameObject[,] cells)
	{
		for (int x = 0; x <= cells.GetUpperBound (0); x++) {
			for (int y = 0; y <= cells.GetUpperBound (1); y++) {
			
				var thisCell = cells [x, y];
				if (thisCell.name == "empty(Clone)") {
					for (int y2 = y; y2 <= cells.GetUpperBound (1); y2++) {
						if (cells [x, y2].name != "empty(Clone)") {
							cells [x, y] = cells [x, y2];
							cells [x, y2] = thisCell;
							break;
						}
					}
				}
			}
		}

		for (int x = 0; x <= cells.GetUpperBound (0); x++) {
			for (int y = 0; y <= cells.GetUpperBound (1); y++) {
				if (cells [x, y].name == "empty(Clone)") { 
					Destroy (cells [x, y]);
					cells [x, y] = GameObject.Instantiate (_listOfShapes [Random.Range (0, _listOfShapes.Length)] 
						as GameObject, new Vector3 (x, y, 0), transform.rotation) as GameObject;
				}
			}
		}

		for (int x = 0; x <= cells.GetUpperBound (0); x++) {
			for (int y = 0; y <= cells.GetUpperBound (1); y++) {
				cells [x, y].transform.position = new Vector3 (x, y, 0);
			}
		}
	}