static void Main(string[] args) { do { //get user input for minefield size and # of bombs(pass to Minefield constructor) //sets board size and bombs based on input ChooseBoard(); //Sets max flags and initializes minefields maxFlags = bombs; bool loseGame = false; HiddenMinefield gameMinefield = new HiddenMinefield(rows, columns, bombs); VisibleMinefield userMinefield = new VisibleMinefield(rows, columns); // Game loop do { VisibleMinefield.PrintVisibleArray(userMinefield.VisMinefield); //minefield display //Getting user input for box selection Console.WriteLine("Do you wish to flag a cell, check a cell, or double click a cell? Enter F or C or D: "); string choice = Validation.GetValidLetter(); if (choice.ToLower() == "f") //if user chooses to place a flag on a spot, spot will be marked "F" { FlagCell(userMinefield.VisMinefield); } else if (choice.ToLower() == "c") //user choosing to reveal a cell { loseGame = RevealCell(userMinefield.VisMinefield, gameMinefield.Minefield); } else if (choice.ToLower() == "d") //user choosing to reveal a cell { DoubleClickCell(userMinefield.VisMinefield, gameMinefield.Minefield); } winMethod(userMinefield.VisMinefield, bombs); //end loop } while (!loseGame); } while (Validation.Continue()); }
public static bool RevealCell(int[,] visArray, int[,] hiddenArray) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Please enter the x coordinate to reveal: "); int xGuess = Validation.GetNumberInRange(0, rows - 1); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("Please enter the y coordinate to reveal: "); int yGuess = Validation.GetNumberInRange(0, columns - 1); Console.ResetColor(); if (hiddenArray[xGuess, yGuess] == -1) //if the x,y coordinates chosen by user are a hidden bomb in the hiddenarray, game over { Console.Clear(); VisibleMinefield.PrintFullArray(hiddenArray, visArray); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("BOOM!\nYOU\nBLEW\nUP\nEARTH!\n"); Console.ResetColor(); return(true); } else if (hiddenArray[xGuess, yGuess] != -1) //if x,y coordinates are not a bomb, board will display empty spots and numbered spots { if (hiddenArray[xGuess, yGuess] != 0) { visArray[xGuess, yGuess] = hiddenArray[xGuess, yGuess]; } else { visArray[xGuess, yGuess] = hiddenArray[xGuess, yGuess]; VisibleMinefield.RevealZeroes(visArray, hiddenArray, xGuess, yGuess); } } return(false); }