/// <summary> /// Change the 'color' of the grid according to the type of the first cell (bucket) /// </summary> /// <param name="x">Start cell X position</param> /// <param name="y">Start cell Y position</param> /// <param name="color">the 'color' to paint the cave with with</param> /// <returns>Returns the boundries cells</returns> private RoomsAndMazesCell[] PaintDungeon(int x, int y, RoomsAndMazesCellType color) { RoomsAndMazesCellType firstType = grid[x][y].type; List <RoomsAndMazesCell> cellsToPaint = new List <RoomsAndMazesCell>(); cellsToPaint.Add(grid[x][y]); List <RoomsAndMazesCell> boundries = new List <RoomsAndMazesCell>(); while (cellsToPaint.Count > 0) { RoomsAndMazesCell currentCell = cellsToPaint[0]; cellsToPaint.Remove(currentCell); if (currentCell.type == firstType) { currentCell.type = color; IterateThroughNeumannNeighbours(new CaveCellsIterator((int nX, int nY) => { if (grid[nX][nY].type == firstType) { cellsToPaint.Add(grid[nX][nY]); } else if (grid[nX][nY].type != color && !boundries.Contains(grid[nX][nY])) { boundries.Add(grid[nX][nY]); } }), currentCell.x, currentCell.y); } } return(boundries.ToArray()); }
public RoomsAndMazesCell(int x, int y) { this.x = x; this.y = y; this.type = RoomsAndMazesCellType.Null; }