protected void IterateThroughCave(CaveCellsIterator iterator) { for (int x = 0; x < caveWidth; x++) { for (int y = 0; y < caveHeight; y++) { iterator(x, y); } } }
/// <summary> /// Itarete through all (top, bottom, left and right) the neighbours of a cell giving its coords /// </summary> /// <param name="iterator">The function that will be called when the neightbour exist</param> /// <param name="notOnGridIterator">The function that will be called when the neightbour doesn't exists</param> /// <param name="centerX">X coordinates of the main cell</param> /// <param name="centerY">Y coordinates of the main cell</param> protected void IterateThroughNeumannNeighbours(CaveCellsIterator iterator, CaveCellsIterator notOnGridIterator, int centerX, int centerY) { // Top Neighbour if (IsOnGrid(centerX, centerY + 1)) { iterator(centerX, centerY + 1); } else { notOnGridIterator(centerX, centerY + 1); } // Right Neighbour if (IsOnGrid(centerX + 1, centerY)) { iterator(centerX + 1, centerY); } else { notOnGridIterator(centerX + 1, centerY); } // Bottom Neighbour if (IsOnGrid(centerX, centerY - 1)) { iterator(centerX, centerY - 1); } else { notOnGridIterator(centerX, centerY - 1); } // Left Neighbour if (IsOnGrid(centerX - 1, centerY)) { iterator(centerX - 1, centerY); } else { notOnGridIterator(centerX - 1, centerY); } }
protected void IterateThroughMooreNeighbours(CaveCellsIterator iterator, CaveCellsIterator notOnGridIterator, int centerX, int centerY) { for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { if (x != 0 || y != 0) { if (IsOnGrid(centerX + x, centerY + y)) { iterator(centerX + x, centerY + y); } else { notOnGridIterator(centerX + x, centerY + y); } } } } }
/// <summary> /// Itarete through all (top, bottom, left and right) the neighbours of a cell giving its coords /// </summary> /// <param name="iterator">The function that will be call when the neightbour exist</param> /// <param name="centerX">X coordinates of the main cell</param> /// <param name="centerY">Y coordinates of the main cell</param> protected void IterateThroughNeumannNeighbours(CaveCellsIterator iterator, int centerX, int centerY) { IterateThroughNeumannNeighbours(iterator, (int x, int y) => { }, centerX, centerY); }