Пример #1
0
    private AlteredCandyInfo CreateNewCandyInSpecificColumns(IEnumerable <int> columnsWithMissingCandy)
    {
        AlteredCandyInfo newCandyInfo = new AlteredCandyInfo();

        // find how many null values the column has
        foreach (int column in columnsWithMissingCandy)
        {
            var emptyItems = shapes.GetEmptyItemsOnColumn(column);
            int offset     = 0;
            foreach (var item in emptyItems)
            {
                var        go       = GetRandomCandy();
                GameObject newCandy = Instantiate(go,
                                                  spawnPositions[column] + new Vector2(0.0f, offset * CandySize.y),
                                                  Quaternion.identity,
                                                  shapesContainer) as GameObject;

                newCandy.GetComponent <Shape>().Assign(go.GetComponent <Shape>().Type, item.Row, item.Column);

                shapes[item.Row, item.Column] = newCandy;
                newCandyInfo.AddCandy(newCandy);

                offset++;
            }
        }

        return(newCandyInfo);
    }
Пример #2
0
    public AlteredCandyInfo Collapse(IEnumerable <int> columns)
    {
        AlteredCandyInfo collapseInfo = new AlteredCandyInfo();

        foreach (var column in columns)
        {
            for (int row = 0; row < GameVariables.Rows - 1; row++)
            {
                if (candies[row, column] == null)
                {
                    for (int row2 = row + 1; row2 < GameVariables.Rows; row2++)
                    {
                        if (candies[row2, column] != null)
                        {
                            candies [row, column]  = candies [row2, column];
                            candies [row2, column] = null;

                            if (row2 - row > collapseInfo.maxDistance)
                            {
                                collapseInfo.maxDistance = row2 - row;
                            }

                            candies [row, column].GetComponent <Candy> ().Row    = row;
                            candies [row, column].GetComponent <Candy> ().Column = column;

                            collapseInfo.AddCandy(candies[row, column]);
                            break;
                        }
                    }
                }
            }
        }
        return(collapseInfo);
    }
Пример #3
0
    /// <summary>
    /// Spawns new candy in columns that have missing ones
    /// </summary>
    /// <param name="columnsWithMissingCandy"></param>
    /// <returns>Info about new candies created</returns>
    private AlteredCandyInfo CreateNewCandyInSpecificColumns(IEnumerable <int> columnsWithMissingCandy)
    {
        AlteredCandyInfo newCandyInfo = new AlteredCandyInfo();

        //find how many null values the column has
        foreach (int column in columnsWithMissingCandy)
        {
            var emptyItems = shapes.GetEmptyItemsOnColumn(column);
            foreach (var item in emptyItems)
            {
                var        go       = GetRandomCandy();
                GameObject newCandy = Instantiate(go, SpawnPositions[column], Quaternion.identity)
                                      as GameObject;

                newCandy.GetComponent <Shape>().Assign(go.GetComponent <Shape>().Type, item.Row, item.Column);

                if (Constants.Rows - item.Row > newCandyInfo.MaxDistance)
                {
                    newCandyInfo.MaxDistance = Constants.Rows - item.Row;
                }

                shapes[item.Row, item.Column] = newCandy;
                newCandyInfo.AddCandy(newCandy);
            }
        }
        return(newCandyInfo);
    }
Пример #4
0
    /// <summary>
    /// Colapse or delete the specified column
    /// </summary>
    /// <param name="_columns"></param>
    /// <returns></returns>
    public AlteredCandyInfo Collapse(IEnumerable <int> _columns)
    {
        AlteredCandyInfo alteredCandy = new AlteredCandyInfo();

        foreach (int _col in _columns)
        {
            for (int _row = 0; _row < GameVariables.Rows - 1; _row++)
            {
                if (candies[_row, _col] == null)
                {
                    for (int _row2 = _row + 1; _row2 < GameVariables.Rows; _row2++)
                    {
                        if (candies[_row2, _col] != null)
                        {
                            candies[_row, _col]  = candies[_row2, _col];
                            candies[_row2, _col] = null;

                            if (_row2 - _row > alteredCandy.MaxDistance)
                            {
                                alteredCandy.MaxDistance = _row2 - _row;
                            }

                            candies[_row, _col].GetComponent <Candy>().row    = _row;
                            candies[_row, _col].GetComponent <Candy>().column = _col;

                            alteredCandy.AddNewCandies(candies[_row, _col]);
                            break;
                        }
                    }
                }
            }
        }

        return(alteredCandy);
    }
Пример #5
0
    private AlteredCandyInfo CreateNewCandyInSpecificColumns(IEnumerable <int> columnsWithMissingCandies)
    {
        AlteredCandyInfo newCandyInfo = new AlteredCandyInfo();

        foreach (int column in columnsWithMissingCandies)
        {
            var emptyItems = candies.GetEmptyItemsOnColumn(column);

            foreach (var item in emptyItems)
            {
                var go = GetRandomCandy();

                GameObject newCandy = Instantiate(go, SpawnPositions [column], Quaternion.identity) as GameObject;
                newCandy.GetComponent <Candy> ().Initialize(go.GetComponent <Candy> ().Type, item.Row, item.Column);

                if (GameVariables.Rows - item.Row > newCandyInfo.maxDistance)
                {
                    newCandyInfo.maxDistance = GameVariables.Rows - item.Row;
                }

                candies [item.Row, item.Column] = newCandy;
                newCandyInfo.AddCandy(newCandy);
            }
        }
        return(newCandyInfo);
    }
Пример #6
0
    /// <summary>
    /// Function resposible of creating new candies after the matches of the candies of same colour
    /// </summary>
    /// <param name="missingCandies"></param>
    /// <returns></returns>
    private AlteredCandyInfo CreateNewCandyinSpecificColumn(IEnumerable <int> missingCandies)
    {
        AlteredCandyInfo newCandyInfo = new AlteredCandyInfo();

        foreach (int col in missingCandies)
        {
            var candyInfos = candyArray.GetEmptyItemsOnColumn(col);

            foreach (var item in candyInfos)
            {
                GameObject tempGO = GetRandomCandy();
                if (tempGO != null)
                {
                    GameObject newCandy = Instantiate(tempGO, spawnPosition[col], Quaternion.identity);
                    newCandy.GetComponent <Candy>().Initialize(item.Row, item.Column, newCandy.GetComponent <Candy>().candyColour);

                    if (GameVariables.Rows - item.Row > newCandyInfo.MaxDistance)
                    {
                        newCandyInfo.MaxDistance = GameVariables.Rows - item.Row;
                    }

                    candyArray[item.Row, item.Column] = newCandy;
                    newCandyInfo.AddNewCandies(newCandy);
                }
            }
        }
        return(newCandyInfo);
    }
Пример #7
0
    /// <summary>
    /// Find all the candies that are collapsing downward
    /// </summary>
    /// <param name="columns"></param>
    /// <returns></returns>
    public AlteredCandyInfo Collapse(IEnumerable <int> columns)
    {
        AlteredCandyInfo collapseInfo = new AlteredCandyInfo();

        // loop through all columns
        foreach (var column in columns)
        {
            // Loop through each row
            for (int row = 0; row < GameVariables.Rows - 1; row++)
            {
                // Search for a destroyed candy location
                if (candies[row, column] == null)
                {
                    // Now navigate the column upward to find the first non-null candy
                    for (int row2 = row + 1; row2 < GameVariables.Rows; row2++)
                    {
                        // Did we find a non-null candy spot?
                        if (candies[row2, column] != null)
                        {
                            // We found a candy, so set the object at that destroyed position to the first non null object
                            candies[row, column] = candies[row2, column];

                            // nullify the found candy position
                            candies[row2, column] = null;

                            // Update the max distance between the destroyed bean and its first non-null bean above it
                            if (row2 - row > collapseInfo.maxDistance)
                            {
                                collapseInfo.maxDistance = row2 - row;
                            }

                            // Update the candy array positioning information
                            candies[row, column].GetComponent <Candy>().Row    = row;
                            candies[row, column].GetComponent <Candy>().Column = column;

                            // Add the candy to the collapsing info
                            collapseInfo.AddCandy(candies[row, column]);

                            // break loop
                            break;
                        }
                    }
                }
            }
        }

        return(collapseInfo);
    } // Collapse()
Пример #8
0
    /// <summary>
    /// Collapses the array on the specific columns, after checking for empty items on them
    /// </summary>
    /// <param name="columns"></param>
    /// <returns>Info about the GameObjects that were moved</returns>
    public AlteredCandyInfo Collapse(IEnumerable <int> columns)
    {
        AlteredCandyInfo collapseInfo = new AlteredCandyInfo();


        ///search in every column
        foreach (var column in columns)
        {
            //begin from bottom row
            for (int row = 0; row < Constants.Rows - 1; row++)
            {
                //if you find a null item
                if (shapes[row, column] == null)
                {
                    //start searching for the first non-null
                    for (int row2 = row + 1; row2 < Constants.Rows; row2++)
                    {
                        //if you find one, bring it down (i.e. replace it with the null you found)
                        if (shapes[row2, column] != null)
                        {
                            shapes[row, column]  = shapes[row2, column];
                            shapes[row2, column] = null;

                            //calculate the biggest distance
                            if (row2 - row > collapseInfo.MaxDistance)
                            {
                                collapseInfo.MaxDistance = row2 - row;
                            }

                            //assign new row and column (name does not change)
                            shapes[row, column].GetComponent <Shape>().Row    = row;
                            shapes[row, column].GetComponent <Shape>().Column = column;

                            collapseInfo.AddCandy(shapes[row, column]);
                            break;
                        }
                    }
                }
            }
        }

        return(collapseInfo);
    }
    /// <summary>
    /// Create new candies in empty spaces within each column
    /// </summary>
    /// <param name="columnsWithMissingCandies"></param>
    /// <returns></returns>
    private AlteredCandyInfo CreateNewCandyInSpecificColumns(IEnumerable <int> columnsWithMissingCandies)
    {
        AlteredCandyInfo newCandyInfo = new AlteredCandyInfo();

        // loop through each column to find the empty spaces
        foreach (int column in columnsWithMissingCandies)
        {
            var emptyItems = candies.GetEmptyItemsOnColumn(column);

            // for each missing item, generate a new candy
            foreach (var item in emptyItems)
            {
                // generate a new candy object
                var go = GetRandomCandy();

                // instantiate this candy
                GameObject newCandy = Instantiate(go, spawnPositions[column], Quaternion.identity) as GameObject;

                // initialize this candy and put it in its position
                newCandy.GetComponent <Candy>().Initialize(go.GetComponent <Candy>().Type, item.Row, item.Column);

                //
                if (GameVariables.Rows - item.Row > newCandyInfo.maxDistance)
                {
                    // Update the max distance
                    newCandyInfo.maxDistance = GameVariables.Rows - item.Row;
                }

                // add the new candy into the array
                candies[item.Row, item.Column] = newCandy;

                // add the candy to the new candy info
                newCandyInfo.AddCandy(newCandy);
            }
        }



        return(newCandyInfo);
    }
Пример #10
0
    public AlteredCandyInfo Collapse(IEnumerable <int> columns)
    {
        AlteredCandyInfo collapseInfo = new AlteredCandyInfo();

        // search in every column
        foreach (var column in columns)
        {
            // begin from bottom row
            for (int row = 0; row < Constants.Rows - 1; row++)
            {
                // null item found
                if (shapes[row, column] == null)
                {
                    // start searching for the first non-null item
                    for (int row2 = row + 1; row2 < Constants.Rows; row2++)
                    {
                        // let it fall down
                        if (shapes[row2, column] != null)
                        {
                            shapes[row, column]  = shapes[row2, column];
                            shapes[row2, column] = null;

                            // assign new row and column
                            shapes[row, column].GetComponent <Shape>().Row    = row;
                            shapes[row, column].GetComponent <Shape>().Column = column;

                            collapseInfo.AddCandy(shapes[row, column]);
                            break;
                        }
                    }
                }
            }
        }

        return(collapseInfo);
    }
Пример #11
0
    /// <summary>
    /// Spawns new candy in columns that have missing ones
    /// </summary>
    /// <param name="columnsWithMissingCandy"></param>
    /// <returns>Info about new candies created</returns>
    private AlteredCandyInfo CreateNewCandyInSpecificColumns(IEnumerable<int> columnsWithMissingCandy)
    {
        AlteredCandyInfo newCandyInfo = new AlteredCandyInfo();

        //find how many null values the column has
        foreach (int column in columnsWithMissingCandy)
        {
            var emptyItems = shapes.GetEmptyItemsOnColumn(column);
            foreach (var item in emptyItems)
            {
                var go = GetRandomCandy();
                GameObject newCandy = Instantiate(go, SpawnPositions[column], Quaternion.identity)
                    as GameObject;

                newCandy.GetComponent<Shape>().Assign(go.GetComponent<Shape>().Type, item.Row, item.Column);

                if (Constants.Rows - item.Row > newCandyInfo.MaxDistance)
                    newCandyInfo.MaxDistance = Constants.Rows - item.Row;

                shapes[item.Row, item.Column] = newCandy;
                newCandyInfo.AddCandy(newCandy);
            }
        }
        return newCandyInfo;
    }
Пример #12
0
    /// <summary>
    /// Collapses the array on the specific columns, after checking for empty items on them
    /// </summary>
    /// <param name="columns"></param>
    /// <returns>Info about the GameObjects that were moved</returns>
    public AlteredCandyInfo Collapse(IEnumerable<int> columns)
    {
        AlteredCandyInfo collapseInfo = new AlteredCandyInfo();


        ///search in every column
        foreach (var column in columns)
        {
            //begin from bottom row
            for (int row = 0; row < Constants.Rows - 1; row++)
            {
                //if you find a null item
                if (shapes[row, column] == null)
                {
                    //start searching for the first non-null
                    for (int row2 = row + 1; row2 < Constants.Rows; row2++)
                    {
                        //if you find one, bring it down (i.e. replace it with the null you found)
                        if (shapes[row2, column] != null)
                        {
                            shapes[row, column] = shapes[row2, column];
                            shapes[row2, column] = null;

                            //calculate the biggest distance
                            if (row2 - row > collapseInfo.MaxDistance) 
                                collapseInfo.MaxDistance = row2 - row;

                            //assign new row and column (name does not change)
                            shapes[row, column].GetComponent<Shape>().Row = row;
                            shapes[row, column].GetComponent<Shape>().Column = column;

                            collapseInfo.AddCandy(shapes[row, column]);
                            break;
                        }
                    }
                }
            }
        }

        return collapseInfo;
    }