private string PrintArea(IMineArea area) { if (area.ContainsMine) { return("*"); } else { return(area.AdjacentMines.ToString()); } }
public Minefield(int width, int height) { Width = width; Height = height; m_mineAreas = new IMineArea[width, height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { m_mineAreas[i, j] = new MineArea(j, i); } } }
/// <summary> /// Lists all of the areas that are adjacent to a mine area in a minefield. /// </summary> /// <param name="mineArea">Returns the neighbors of this area.</param> /// <param name="minefield">Uses this minefield to get references to neighboring areas.</param> /// <returns>An enumerable collection of IMineAreas that are adjacent to the specified area.</returns> public static IEnumerable <IMineArea> NeighboringAreas(this IMineArea mineArea, IMinefield minefield) { for (int row = mineArea.Row - 1; row <= mineArea.Row + 1; row++) { for (int col = mineArea.Col - 1; col <= mineArea.Col + 1; col++) { // Make sure indexes are in mine grid and area is not the current area if (row >= 0 && row < minefield.Height && col >= 0 && col < minefield.Width && (row != mineArea.Row || col != mineArea.Col)) { yield return(minefield.GetArea(row, col)); } } } }
private string PrintArea(IMineArea area) { if (area.ContainsMine) return "*"; else return area.AdjacentMines.ToString(); }