public CollapseInfo Collapse(IEnumerable <int> columns) { var collapseInfo = new CollapseInfo(); foreach (var column in columns) { for (int row = 0; row < GameController.SizeMatrix - 1; row++) { if (_dots[row, column] != null) { continue; } for (int row2 = row + 1; row2 < GameController.SizeMatrix; row2++) { if (_dots[row2, column] == null) { continue; } _dots[row, column] = _dots[row2, column]; _dots[row2, column] = null; _dots[row, column].GetComponent <Dot>().Row = row; _dots[row, column].GetComponent <Dot>().Column = column; collapseInfo.AddDot(_dots[row, column]); break; } } } return(collapseInfo); }
private CollapseInfo CreateNewDotForColumn(IEnumerable <int> columnsWithMissingCandies) { CollapseInfo dotCollapseInfo = new CollapseInfo(); foreach (int column in columnsWithMissingCandies) { var emptyItems = dots.GetEmptySlotsOnColumn(column); foreach (var item in emptyItems) { var dot = GetRandomDot(); GameObject dotGameObject = Instantiate(dot, SpawnPositions[column], Quaternion.identity); dotGameObject.transform.SetParent(gameObject.transform); dotGameObject.transform.localScale = new Vector3(1, 1, 1); dotGameObject.GetComponent <Dot>().Init(dot.GetComponent <Dot>().Type, item.Row, item.Column); dots.Add(item.Row, item.Column, dotGameObject); dotCollapseInfo.AddDot(dotGameObject); } } return(dotCollapseInfo); }