import javax.swing.*;public class SweeperBoard { private int diffLevel; // 0, 1, 2 (beginner, intermediate, expert) private boolean custom; private int width; private int height; private int numOfTiles; // Represents # of potential mines, for example // for an 8x8 grid, numOfTiles == 64 private int numMines; private boolean[][] mineBoard; private JButton[][] buttonBoard; public static final int BEGINNER_WIDTH = 8; public static final int BEGINNER_HEIGHT = 8; public static final int BEG_NUM_MINES = 10; public static final int INTER_WIDTH = 16; public static final int INTER_HEIGHT = 16; public static final int INTER_NUM_MINES = 40; public static final int EXPERT_WIDTH = 30; public static final int EXPERT_HEIGHT = 16; public static final int EXP_NUM_MINES = 99;/** public SweeperBoard () { // Beginner level, the default numMines = BEG_NUM_MINES; height = BEGINNER_HEIGHT; width = BEGINNER_WIDTH; numOfTiles = width * height; diffLevel = 0; mineBoard = new boolean [height][width]; buttonBoard = new JButton [height][width]; int i = 0; int x; int y; // Generates mine board while (i < numMines) { x = (int) (Math.random() * height); y = (int) (Math.random() * width); if (mineBoard[x][y] == false) { mineBoard[x][y] = true; i++; } } //Generates accompanying JButton board for (int k = 0; i < width; k++) { for (int j = 0; j < height; j++) { buttonBoard[k][j] = new JButton(); } } }**/ public SweeperBoard (int difficulty) { // !(beginner) if (difficulty == 0) { numMines = BEG_NUM_MINES; height = BEGINNER_HEIGHT; width = BEGINNER_WIDTH; numOfTiles = width * height; diffLevel = 0; mineBoard = new boolean [height][width]; buttonBoard = new JButton [height][width]; int i = 0; int x; int y; // Generates mine board while (i < numMines) { x = (int) (Math.random() * height); y = (int) (Math.random() * width); if (mineBoard[x][y] == false) { mineBoard[x][y] = true; i++; } } //Generates accompanying JButton board for (int k = 0; i < width; k++) { for (int j = 0; j < height; j++) { buttonBoard[k][j] = new JButton(); } } } else if (difficulty == 1) { numMines = INTER_NUM_MINES; height = INTER_HEIGHT; width = INTER_WIDTH; numOfTiles = width * height; diffLevel = 1; mineBoard = new boolean [height][width]; int i = 0; int x; int y; while (i < numMines) { x = (int) (Math.random() * height); y = (int) (Math.random() * width); if (mineBoard[x][y] == false) { mineBoard[x][y] = true; i++; } } } else if (difficulty == 2) { numMines = EXP_NUM_MINES; height = EXPERT_HEIGHT; width = EXPERT_WIDTH; numOfTiles = width * height; diffLevel = 2; mineBoard = new boolean [height][width]; int i = 0; int x; int y; while (i < numMines) { x = (int) (Math.random() * height); y = (int) (Math.random() * width); if (mineBoard[x][y] == false) { mineBoard[x][y] = true; i++; } } } } public SweeperBoard (boolean custGame, int boardWidth, int boardHeight, int mines) { // Constructor of custom game custom = custGame; numMines = mines; height = boardHeight; width = boardWidth; numOfTiles = width * height; mineBoard = new boolean [height][width]; int i = 0; int x; int y; // Generates mine board while (i < numMines) { x = (int) (Math.random() * height); y = (int) (Math.random() * width); if (mineBoard[x][y] == false) { mineBoard[x][y] = true; i++; } } } public int getNumMines () { return numMines; } public int getWidth () { return width; } public int getHeight () { return height; } public int getNumTiles () { return numOfTiles; } public boolean[][] getMineBoard () { return mineBoard; } public int getDifficulty () { return diffLevel; }}