❔ Most of the code in class throws error when working before.

Hello, I'm making a simple minesweeper game in the console using OOP. I created a class for the grid to be able to manage the grid for the minesweeper. I was building the code without any issues before, i added a new method and then when I try to build it now the code doesn't seem to work at all and throws an error on almost every line of code.
using System;

namespace Minesweeper{
class Minesweeper{
static void Main(string[] args){
Grid grid = new Grid();
string __playerName = "Alex";
Player player = new Player() {playerName = __playerName };
grid.bombCreation("Hard");

grid.printSeenGrid();
}
}
class Grid{
bool[,] seenGrid = new bool[20,20]; //Contains grid of what squares can be seen
char[,] bombGrid = new char[20,20];//Contains grid where the bombs are
public void printBombGrid{
for(int row = 0; row <= bombGrid.GetLength(0)-1; row++){
for(int col = 0; col<=bombGrid.GetLength(1)-1; col++){
if (bombGrid[row, col] == 'B'){
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(" O");
}else{
Console.ForegroundColor = ConsoleColor.White;
Console.Write(" O");
}
Console.ForegroundColor = ConsoleColor.White;
}
Console.WriteLine();
}
}
public void setSeenGrid(bool set, int X, int Y){
seenGrid[X, Y] = set;
}

public void printSeenGrid(int[] playerSelection){
for(int row = 0; row<=seenGrid.GetLength(0)-1; row++){
for(int col = 0; col<=seenGrid.GetLength(1)-1; col++){
if(seenGrid[row, col] == true) {
Console.ForegroundColor = ConsoleColor.Green;
Console.Write(" O");
}
else if(seenGrid[row, col] == true && bombGrid[row, col] == 'B'){
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(" O");
}
else{
Console.ForegroundColor = ConsoleColor.White;
Console.Write(" O");
}
}
Console.WriteLine();
}
}

public void bombCreation(string difficulty){
if(difficulty=="Hard"){
for(int i = 100; i>=0; i--){
Random rnd = new Random();
int bombX = rnd.Next(0, bombGrid.GetLength(0));
int bombY = rnd.Next(0, bombGrid.GetLength(1));
bombGrid[bombX, bombY] = 'B';
}
}
}
}
class Player : Grid{
public string playerName { get; set;}
}
}
using System;

namespace Minesweeper{
class Minesweeper{
static void Main(string[] args){
Grid grid = new Grid();
string __playerName = "Alex";
Player player = new Player() {playerName = __playerName };
grid.bombCreation("Hard");

grid.printSeenGrid();
}
}
class Grid{
bool[,] seenGrid = new bool[20,20]; //Contains grid of what squares can be seen
char[,] bombGrid = new char[20,20];//Contains grid where the bombs are
public void printBombGrid{
for(int row = 0; row <= bombGrid.GetLength(0)-1; row++){
for(int col = 0; col<=bombGrid.GetLength(1)-1; col++){
if (bombGrid[row, col] == 'B'){
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(" O");
}else{
Console.ForegroundColor = ConsoleColor.White;
Console.Write(" O");
}
Console.ForegroundColor = ConsoleColor.White;
}
Console.WriteLine();
}
}
public void setSeenGrid(bool set, int X, int Y){
seenGrid[X, Y] = set;
}

public void printSeenGrid(int[] playerSelection){
for(int row = 0; row<=seenGrid.GetLength(0)-1; row++){
for(int col = 0; col<=seenGrid.GetLength(1)-1; col++){
if(seenGrid[row, col] == true) {
Console.ForegroundColor = ConsoleColor.Green;
Console.Write(" O");
}
else if(seenGrid[row, col] == true && bombGrid[row, col] == 'B'){
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(" O");
}
else{
Console.ForegroundColor = ConsoleColor.White;
Console.Write(" O");
}
}
Console.WriteLine();
}
}

public void bombCreation(string difficulty){
if(difficulty=="Hard"){
for(int i = 100; i>=0; i--){
Random rnd = new Random();
int bombX = rnd.Next(0, bombGrid.GetLength(0));
int bombY = rnd.Next(0, bombGrid.GetLength(1));
bombGrid[bombX, bombY] = 'B';
}
}
}
}
class Player : Grid{
public string playerName { get; set;}
}
}
7 Replies
Just Some Bread
Just Some BreadOP13mo ago
The errors that come up
phaseshift
phaseshift13mo ago
Methods need parens
Angius
Angius13mo ago
public void printBombGrid Should be public void printBombGrid()
phaseshift
phaseshift13mo ago
printBombGrid
Angius
Angius13mo ago
Or, to be precise, should be public void PrintBombGrid() if you were to stick to C# naming conventions The error would be easier to spot if you formatted your code properly, too
Jimmacle
Jimmacle13mo ago
generally when all your code starts showing compiler errors you made a syntax error near the top of where they start
Accord
Accord13mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server