public MobileActionInfo Collapse(IEnumerable<int> columns) { MobileActionInfo collapseInfo = new MobileActionInfo(); foreach (var column in columns) { for (int row = 0; row < Constants.Rows - 1; row++) { if (_actions[row, column] == null) { for (int row2 = row + 1; row2 < Constants.Rows; row2++) { if (_actions[row2, column] != null) { _actions[row, column] = _actions[row2, column]; _actions[row2, column] = null; if (row2 - row > collapseInfo.MaxDistance) { collapseInfo.MaxDistance = row2 - row; } _actions[row, column].GetComponent<Action>().Row = row; _actions[row, column].GetComponent<Action>().Column = column; collapseInfo.AddAction(_actions[row, column]); break; } } } } } return collapseInfo; }
private MobileActionInfo CreateNewActionInSpecificColumns(IEnumerable<int> columnsWithMissingActions) { MobileActionInfo newActionInfo = new MobileActionInfo(); foreach (var column in columnsWithMissingActions) { var emptyItems = Actions.GetEmptyItemsOnColumn(column); foreach (var item in emptyItems) { var randomAction = GetRandomAction(); GameObject newAction = Instantiate(randomAction, _spawnPositions[column], Quaternion.identity) as GameObject; newAction.GetComponent<Action>().Assign(randomAction.GetComponent<Action>().Type, item.Row, item.Column); if (Constants.Rows - item.Row > newActionInfo.MaxDistance) { newActionInfo.MaxDistance = Constants.Rows - item.Row; } Actions[item.Row, item.Column] = newAction; newActionInfo.AddAction(newAction); } } return newActionInfo; }