예제 #1
0
    private AlteredMarbleInfo CreateNewMarbleInSpecificColumns(IEnumerable <int> columnsWithMissingMarbles)
    {
        AlteredMarbleInfo newMarbleInfo = new AlteredMarbleInfo();

        foreach (int column in columnsWithMissingMarbles)
        {
            var emptyItems = marbles.GetEmptyItemsOnColumn(column);

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

                GameObject newMarble = Instantiate(go, SpawnPositions[column], Quaternion.identity) as GameObject;

                newMarble.GetComponent <Marble>().Initialize(go.GetComponent <Marble>().Type, item.Row, item.column);

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

                marbles[item.Row, item.column] = newMarble;

                newMarbleInfo.AddMarble(newMarble);
            }
        }

        return(newMarbleInfo);
    }
    public AlteredMarbleInfo Collapse(IEnumerable <int> columns)
    {
        AlteredMarbleInfo collapseInfo = new AlteredMarbleInfo();

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

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

                            marbles[row, column].GetComponent <Marble>().Row    = row;
                            marbles[row, column].GetComponent <Marble>().Column = column;

                            collapseInfo.AddMarble(marbles[row, column]);
                            break;
                        }
                    }
                }
            }
        }

        return(collapseInfo);
    }