public static string RenderGrid(GridView gridView) { StringBuilder finalString = new StringBuilder(); finalString.Append(" "); for (int c = 0; c < gridView.Width; c++) { finalString.Append(((char) (c + 'A')).ToString()); } finalString.Append("\n"); for (int y = 0; y < gridView.Height; y++) { finalString.Append(y + 1); for (int x = 0; x < gridView.Width; x++) { finalString.Append(RenderCell(gridView, x, y)); } finalString.Append("\n"); } return finalString.ToString(); }
public static char RenderCell(GridView gridView, int x, int y) { CellView cell = gridView.GetCellView(x, y); switch (cell.Type) { case CellView.CellType.Bomb: return '@'; case CellView.CellType.Unexplored: return '#'; case CellView.CellType.Explored: return cell.NeighbourCount == 0 ? '-' : cell.NeighbourCount.ToString()[0]; default: throw new Exception("Unknown cell state in cell " + x + y); } }