Example #1
0
    // Collapses the remaining glyphs in the specified columns, after the matched glyphs removal
    public AlteredGlyphInfo Collapse(IEnumerable<int> columns)
    {
        AlteredGlyphInfo collapseInfo = new AlteredGlyphInfo();

        // 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 one is found, bring it down (replace it with the found null)
                        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.AddGlyph(shapes[row, column]);
                            break;
                        }
                    }
                }
            }
        }
        return collapseInfo;
    }
Example #2
0
    // Takes the columns that have been missing glyphs as a parameter
    private AlteredGlyphInfo CreateNewGlyphsInSpecificColumns(IEnumerable<int> columnsWithMissingGlyphs)
    {
        AlteredGlyphInfo newGlyphInfo = new AlteredGlyphInfo();

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

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

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

                shapes[item.Row, item.Column] = newGlyph;
                newGlyphInfo.AddGlyph(newGlyph);
            }
        }

        return newGlyphInfo;
    }