Question
The minesweeper project should be completed in two phases. The two phases provide distinct stopping points should you be unable to complete the entire assignment.
The minesweeper project should be completed in two phases. The two phases provide distinct "stopping points" should you be unable to complete the entire assignment. It is more important to submit a successfully working program, than to push through all of the phases. You will, however, certainly receive more points if you are able to complete both phases.
Phase I : The MineSweeper Class.
Phase II - The GUI.
Level 1 Mines, Tiles, & Board Your assignment is to implement a minesweeper class called minesweeper.java. Your minesweeper class will contain data and methods to partially implement a minesweeper game. While you are not creating a GUI interface in this assignment, you will be creating the data and methods that will support a GUI interface.
A shell program minesweeper.java is provided containing a partial implementation of the minesweeper class. Your assignment is to implement the methods listed below. Your minesweeper class must meet the requirements described in this assignment and the minesweeper class Java Doc. You may choose to add additional data or methods if necessary. All data should be private. Methods may be public or private as is appropriate. Note: methods and requirements for level 2 are indicated. You do NOT need to implement the Level 2 methods.
A sample test program shell minesweeperTest.java is provided. Modify the minesweeperTest.java program to demonstrate each of the methods in your minesweeper.java class.
Level 2. Logic and GUI test Your assignment is to implement the methods needed to support a complete working version of a minesweeper game. The level 2 requirements for each method are described in this assignment and in the minesweeper class Java Doc. Add your level 2. changes to the minesweeper class (minesweeper.java) from level 1. Modify the sample test program minesweeperTest.java from Level 1. to demonstrate each of the methods in your minesweeper.java class.
GUI test program After testing each of your methods using text output, you can test your minesweeper class using a GUI test program. The .class and image files for a GUI test program are provided.
Step 1 - Copy each of the following supporting GUI class and image files into the same directory as your minesweeper.class file
minesweeperGUI$1.class
minesweeperGUI$2.class
minesweeperGUI$3.class
minesweeperGUI$mineButton.class
minesweeperGUI.class
flag.jpg
mine.jpg
minered.jpg
minex.jpg
Step 2 - Run the GUI test program using your minesweeper.class
java minesweeperGUI
Minesweeper Demo
A minesweeper demo program is provided as an executable .jar file. (minesweeperDemo.jar)
Step 1 - Copy the following jar file
minesweeperDemo.jar
Step 2 - Run the GUI demo
If you are using a GUI environment you may be able to double-click on the file minesweeperDemo.jar
If this does not work, type the following from the command line
java -jar minesweeperDemo.jar
Bonus Modify the markTile method to open all adjacent blanks and clues when a tile is opened that covers a blank. Hint: use recursion.
minesweeper.java Class Summary
(*) indicates data and methods for Level 2.
public class minesweeper {
//Data public int[][] mines; //mines and clue values public int[][] tiles; //tiles covering mines and clues
(*)private String status; //game status play, win, loose
//Constructors public minesweeper() //default constructor 9 by 9 board public minesweeper(int newRows, int newCols) //alternate constructor
//Public Methods (*)public String getStatus()//current game status play, win, loose
public int getRows() //number of game board rows public int getCols() //number of game board columns
public int getMines(int r, int c) //mine array value at position r,c public int getTiles(int r, int c) //mine array value at position r,c public char getBoard(int r, int c) //board value for position r,c
public void markTile(int r, int c, int t) //change tile status
public String toStringMines() //mines array as String public String toStringTiles() //tiles array as String public String toStringBoard() //game board as String
private void initGame(int newRows, int newCols) //set-up game private void resetTiles() //set all tiles closed private void placeMines() //place randome mines private void calculateClues() //calculate clue values
private boolean validIndex(int r, int c) //verify index
(*)private boolean gameWon() //determine if game is won
}
Sample Test Program (minesweeperTest.java)
/* * * minesweeperTest.java * */ public class minesweeperTest {
public static void main(String[] args) {
//create new minesweeper instance 2 rows by 5 columns minesweeper game = new minesweeper(2, 5);
//display mines System.out.println( game.toStringMines() );
//display tiles System.out.println( game.toStringTiles() );
//display board System.out.println( game.toStringBoard() );
//mark tile at 0,0 as Open game.markTile(0,0,0);
//mark tile at 0,1 as Question game.markTile(0,1,2);
//mark tile at 0,0 as Mine game.markTile(0,2,3);
//display tiles System.out.println( game.toStringTiles() );
//display board System.out.println( game.toStringBoard() );
System.exit(0); }
}//minesweeperTest
Sample Output #1 for minesweeperTest.java
92100 29100 11111 11111
XXXXX XXXXX
02311 11111
*?FXX XXXXX
Sample Output #2 for minesweeperTest.java
29100 92100
11111 11111
XXXXX XXXXX
02311 11111
2?FXX XXXXX
Your assignment for phase II is to design and implement your own Applet version of the minesweeper game. Your program must have the equivalent functionality of the minesweeperGUI.java program demonstration in Option #2, but should be implemented as an Applet. Your GUI must use an instance of the minesweeper class developed in Option#2.
Additional Requirements
Use an array of buttons to generate the GUI interface
Use a single board size (ie. 9 x 9)
Use a text box or other GUI component to display the game status
Provide a File menu with
New - restarts the game and clears the board
Exit quits
You may use the images provided (or feel free to create your own)
flag.jpg | |
mine.jpg | |
minered.jpg | |
minex.jpg |
Bonus #1 Add a Level menu that allows the user to select at least three different board sizes. (ie. beginner 9 by 9, intermediate 16 by 16, expert 24 by 24)
Bonus #2 Add a timer to your Applet. The timer must start when the user begins a new game. The timer must stop when the game is over i.e. win or lose
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started