public void Paint(BruschInfo bruschInfo) { int x = bruschInfo.xPos; int y = bruschInfo.yPos; bruschInfo.grid.Tiles[x, y].colorTile.Paint(bruschInfo.currentColor); }
//Uses breadth first search (BFS). public void Paint(BruschInfo bruschInfo) { //Setting up alot of values that will be needed. int x = bruschInfo.xPos; int y = bruschInfo.yPos; int height = bruschInfo.grid.Height; int width = bruschInfo.grid.Width; MyTile[,] tiles = bruschInfo.grid.Tiles; Color currentColor = tiles[x, y].colorTile.CurrentColor; Queue <ColorTile> openTiles = new Queue <ColorTile>(); //Hashset contains method is O(1) so it's great for storing the already visited tiles. HashSet <ColorTile> closedTiles = new HashSet <ColorTile>(); openTiles.Enqueue(tiles[x, y].colorTile); //BFS is used. First all nondiagonal neighbours are added to a temporary list. //then we check if the tile exists or if it has already been evaluated or if it has the same color as the original tile. //If it passes all the conditions its added to the open list. After that the currently evaluated node is added to the closedlist. //Lastly we paint all the nodes that is in the closedtiles set while (openTiles.Count > 0) { ColorTile currentTile = openTiles.Dequeue(); x = (int)currentTile.Tile.gridPos.x; y = (int)currentTile.Tile.gridPos.y; List <ColorTile> tempList = new List <ColorTile>(); tempList.Add(currentTile.North); tempList.Add(currentTile.East); tempList.Add(currentTile.South); tempList.Add(currentTile.West); foreach (ColorTile c in tempList) { if (c != null && !closedTiles.Contains(c) && !openTiles.Contains(c) && currentColor == c.CurrentColor) { openTiles.Enqueue(c); } } if (!closedTiles.Contains(currentTile)) { closedTiles.Add(currentTile); } } //Hashsets aren't as good for iteration though. foreach (ColorTile c in closedTiles) { c.Paint(bruschInfo.currentColor); } }
public void Paint(BruschInfo bruschInfo) { MyTile[,] tiles = bruschInfo.grid.Tiles; int x = bruschInfo.xPos; int y = bruschInfo.yPos; int height = bruschInfo.grid.Height; int width = bruschInfo.grid.Width; //How many tiles that will be filled depends on the bruschsize. //A bruschsize of 1 will fill all the neighbouring tiles of tile[x,y] //A bruschsize of 2 will fill all the neighbouring tiles //and all the tiles that are neighbours to the neighbouring tiles of tile[x,y] for (int i = -bruschSize; i <= bruschSize; i++) { for (int j = -bruschSize; j <= bruschSize; j++) { if (AllowedPos(x + i, y + j, height, width)) { tiles[x + i, y + j].colorTile.Paint(bruschInfo.currentColor); } } } }
//Creates a bruschinfo objext that stores all info needed to paint a tile. public void OnMousePress(ColorTile colorTile) { BruschInfo bruschInfo = new BruschInfo((int)colorTile.Tile.gridPos.x, (int)colorTile.Tile.gridPos.y, grid, CurrentColor); currentBrusch.Paint(bruschInfo); }