public static Point ToPoint(CellGrid grid, ICell cell) { Debug.Assert(grid != null, "Cannot convert to a point when the CellGrid is null."); Debug.Assert(cell != null, "Cannot convert a null Cell into a point."); foreach (var column in grid.Columns) { if (column.Contains(cell)) { Point point; point.x = grid.Columns.IndexOf(column); point.y = column.IndexOf(cell); return(point); } } throw new InvalidOperationException("The CellGrid does not contain the given cell."); }
private void OnDrawGizmos() { var cellGrid = new CellGrid(gridWidth, gridHeight); CellGridOperation.Fill(cellGrid); foreach (var column in cellGrid.Columns) { foreach (var cell in column) { var point = GridQuery.ToPoint(cellGrid, cell); var center = new Vector3(point.x, point.y); var size = new Vector3(1, 1, 1); Gizmos.color = Color.yellow; Gizmos.DrawWireCube(center, size); } } }
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); }
public static void Fill(CellGrid grid) { Debug.Assert(grid != null, "Cannot fill a null CellGrid."); Debug.Assert(grid.Events.Count == 0, "CellGrid Events queue needs to be cleared before filling it."); foreach (var column in grid.Columns) { while (column.Count < grid.Height) { var cell = RandomizeCell(); column.Add(cell); var point = new Point(); point.x = grid.Columns.IndexOf(column); point.y = column.IndexOf(cell); var gridEvent = new AddEvent(point); grid.Events.Enqueue(gridEvent); } } }
public void Process(CellGrid cellGrid, VisualGrid visualGrid) { Debug.Assert(cellGrid != null && visualGrid != null, "Cannot process an AddEvent with a null argument(s)."); this.blockType = cellGrid.Columns[this.position.x][this.position.y].Type; visualGrid.InstantiateCellAt(cellGrid, this.blockType, this.position.x); }