public List <Point> GetPositionsOrDefault(CellGrid grid) { Debug.Assert(grid != null, "Cannot activate BombBlock on a null CellGrid."); var activatedPoint = GridQuery.ToPoint(grid, this); var activationQueue = new Queue <Point>(); var choppingBlock = new List <Point>(); activationQueue.Enqueue(activatedPoint); while (activationQueue.Count > 0) { var processing = activationQueue.Dequeue(); if (!choppingBlock.Contains(processing)) { var surrounding = GridQuery.GetSurrounding(grid, processing, true); var surroundingBombs = from point in surrounding where grid.Columns[point.x][point.y].Type == BlockType.Bomb select point; var surroundingOthers = from point in surrounding where grid.Columns[point.x][point.y].Type != BlockType.Bomb select point; foreach (var point in surroundingBombs) { activationQueue.Enqueue(point); } foreach (var point in surroundingOthers) { if (!choppingBlock.Contains(point)) { choppingBlock.Add(point); } } choppingBlock.Add(processing); } } var soundManager = GameObject.FindGameObjectWithTag("GameManager").GetComponent <SoundManager>(); Debug.Assert(soundManager != null, "Could not locate SoundManager"); soundManager.PlaySound(this.Type); return(choppingBlock); }
public List <Point> GetPositionsOrDefault(CellGrid grid) { Debug.Assert(grid != null, "Cannot activate BasicBlock on a null CellGrid."); var cellPoint = GridQuery.ToPoint(grid, this); var cell = grid.Columns[cellPoint.x][cellPoint.y]; var queue = new Queue <Point>(); queue.Enqueue(cellPoint); var positions = new List <Point>(); while (queue.Count > 0) { var position = queue.Dequeue(); var currentCell = grid.Columns[position.x][position.y]; if (!positions.Contains(position) && currentCell.Type == cell.Type) { positions.Add(position); var surroundingPositions = GridQuery.GetSurrounding(grid, position, false); foreach (var point in surroundingPositions) { if (!queue.Contains(point)) { queue.Enqueue(point); } } } } if (positions.Count > 1) { var soundManager = GameObject.FindGameObjectWithTag("GameManager").GetComponent <SoundManager>(); Debug.Assert(soundManager != null, "Could not locate SoundManager"); soundManager.PlaySound(this.Type); return(positions); } return(null); }