Hey,
This is what I have to do, if anyone can help, much appreciated.
I have to complete the following method from the class MineSweeperLib:
public static boolean [][] generateMineField ( int length, int width, int numberMines)
This method generates a new mine field as a matrix of boolean values where a cell is set to "true" to indicate the presence of a mine. The length and the width of the field are provided, and also the desired number of mines (numberMines).
Hint: Use Math.random(), Math.floor(), and type cast to generate random positions for the mines.
I have already created How do I create a matrix of boolean values where cell is set to "true"?
public class MineSweeperLib
{
// 1st: TO COMPLETE
// METHOD generateMineField: generates a mine field in the forme of a
// matrix of boolean values where a cell set as "true" indicates a mine.
// GIVENS: length and width of the field, and the desired number of mines (numberMines).
// Hint: Consider using Math.random(), Math.floor()
// and type casting to generate random positions for the mines.
public static boolean [][] generateMineField ( int length, int width, int numberMines)
{
return (new boolean[length][width]); // Return something for now, to be able to compile.
}
// 2nd: TO COMPLETE
// METHOD calculateProximity: generate a matrix of integers where each
// cell indicates the number of adjacent mines (i.e., those
// who touch this cell directely). Use 0 for a
// position corresponding to a cell for a mine.
// GIVENS: a matrix of boolean values representing the mine field.
// Hint: Pay attention to the boundaries of the mine field!
public static int [][] calculateProximity ( boolean [][] mineField )
{
return (new int[mineField.length][mineField[0].length]); // Return something for now, to be able to compile.
}
// 3rd: TO COMPLETE
// METHOD allFound: determines if all the mines in the field were found.
// GIVENS: mineField: matrix of boolean values representing the mine field.
// tentatives: matrix of booleans representing the guesses of a player
// (true if a position represents a cell already clicked or a
// potential mine marked with an X in the game).
// The method returns true if all the cells non-clicked correspond to real mines.
// ASSUMPTION: the two matrices have the same size (no need to verify).
public static boolean allFound ( boolean[][] mineField, boolean[][] tentatives )
{
return true; // Return something for now, to be able to compile.
}
}