/// <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); }
/// <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); }