I'm making a Minesweeper clone and I am currently writing the genMines
method. How would I generate the mines, so they are stored into memory, but not shown on the map? Would I need a separate variable for each new mine, or would I make a separate 2d array with the mines and nothing else?
My current code for the method is as follows:
public void genMines(){
int numMines = 0;
Random random = new Random();
while(numMines<7){
int row = random.nextInt(5);
int column = random.nextInt(5);
if(board[row][column] != '-'){ // no need to make a bomb on a bomb :P
board[row][column] = 'B';
}
}
}
For context, -
is the uncovered symbol in this clone, and B
would represent bomb once uncovered.