In Visual Studio, C# console app,
Create a new helper function inside the Program class that willdisplay the contents of each that have been visited. You might wantto name the method PrintBoardDuringGame or something similar. Thiswill be similar to the PrintBoard function developed in Milestone1, but this time display either the number of live neighbors or anempty square if there are no live neighbors. If a cell has not beenvisited, print a question mark. See program.cs below to add toit.
Program.cs
using System;using System.Collections.Generic;using System.Text;
namespace Minesweeper_new{ class Program { //Here lies the error that was notallowing the program to lauch// public static void Main(String[]args) { Console.WriteLine("Pleasechoose the size of the board. The number provided is the height andwidth of the board, " + "forexample 20 would be a 10x10, 30 would be a 15x15 etc. Please useeven numbers."); Board newBoard = newBoard(int.Parse(Console.ReadLine())); Console.WriteLine("Choosethe difficulty, 1 - easy 2 - medium 3 - hard "); newBoard.SetupLiveNeighbors(int.Parse(Console.ReadLine())); newBoard.CalculateLiveNeighbors(); PrintBoard(newBoard.getGrid(), newBoard); }
//Method to print the board. public static void PrintBoard(Cell[,]grid, Board newBoard) { int counter = 0;
//Insert the firstpart of the top text format Console.Write("+ ");
//Display the top row,which is the numbers for the columns. for (int i = 0; i <newBoard.getSize(); i++) { if (i >=10) { Console.Write(i + "+ "); } else { Console.Write(i + " + "); }
}
//Insert the lineunder the very top row. Console.Write("\n+---+"); for (int k = 1; k <newBoard.getSize(); k++) { Console.Write("---+"); }
Console.WriteLine("");
for (int i = 0; i <grid.GetLength(0); i++) { //This partwill put the very far left line on each row. Console.Write("| ");
for (intj = 0; j < grid.GetLength(1); j++) { //Display the grid in a square format with the number oflive neighbors listed and a star for bombs. if (grid[i, j].getLive() == true) { Console.Write("* | "); } else { Console.Write(grid[i, j].getLiveNeighbors() +" | "); } counter++; //Keeps the display clean// if (counter == newBoard.getSize()) { //Create the right column of numbers Console.Write(i); Console.Write("\n+---+"); for (int k = 1; k < newBoard.getSize();k++) { Console.Write("---+"); } Console.Out.WriteLine(""); counter = 0; } } } } }}
In Visual Studio, C# console app, Create a new helper function inside the Program class that will display the contents o
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am