For this assignment, you are to implement the game Mine Sweeper using the Java Swing Library. You can find the game on any Windows Machine. You only have to implement the simpliest version of the game, which consists of locating 10 mines on a 10 by 10 grid.
For this program, you will need to click on buttons with both a left and right button. Follow this link for code that shows how this is done.
For the game, you will need to create a playing grid of 10x10 buttons. All 100 of the buttons will have no text displayed on the button. The game begins with the program randomly placing 10 mines "under" 10 of the 100 buttons. The game is over when either the player left clicks on a button containing a mine (the player loses) or when the 90 buttons that do not have mines have been cleared (the player wins).
If the user clicks on a button with the right mouse button, the program is to mark that button as containing a mine. The program is to now change the text of the button from having no text to the character of M (in upper case). This indicates the user believes a mine is hidden under the button. If the user clicks again on this button, the character is changed to a question mark, "?". This indicates the user thinks there may be a mine hidden under the button. If the user clicks on this button a third time, the no text is displayed. Repeated right clicks is to repeat the sequence of characters displayed from no text to "M" to "?" to no text. While a button is marked with an "M" or a "?", the button cannot be left clicked (see next paragraph).
If the user clicks on the button with the left mouse button, the program must first check what the text on the button is. If the text on the button is "M" or "?", nothing occurs. If the button has no text, the program must check if that button "hides" a mine. If it does, the mine explodes. Then all mines are shown and the game is over. If it does not hide a mine, the button is disabled and the text of the button is to be changed to give the number of mines that are hidden under buttons adjacent to the current button. We will call this "clearing a button". A button can have a maximum of 8 adjacent buttons (those on the edge of the grid will have less). If no adjacent button hides a mine, display the value 0 (See additional comments #1 below for reason on striking out this instruction.) and your program is to automatically clear all adjacent buttons. If one of the buttons that is automatically cleared also has no adjacent adjacent hidden mines, this button should also be automatically cleared.
Apart from the 10x10 grid, your program must have another area of the program to display some game information. This information will contain three GUI elements: an output text field that shows the number of mines left to be found, a reset button and an output text field that shows the amount of elapsed time for the game. These three elements should be separate from the 10x10 grid of buttons (i.e. contained in their own JPanel).
The top ten scorers is a list of the top ten fastest users to solve a game. There must also be a way to reset/clear the top ten scorers (perhaps another button on the Game drop down menu). When a user makes the top ten scorers list, you must prompt for the user's name and record both the user's name and elapsed time for the game. This information must be kept from each time your program is run; therefore, you will need to keep this information in a file (in the same directory as the java bytecode for the program). This file will be need to be read in when the program begins and save out this information as the program ends.
For 10 points extra credit instead of using text to indicate a mine, use images. You may need to create your own images.
This program will also require a 1-2 page write up of the data structures used in the program. Remember that this write-up is to be written in ASCII format and is to be electronically turned in with your program. The name of this file should be "readme.txt".
The main class for your program is to be called mp5. Therefore, the TA will type in:
$> javac mp5.javato compile it. The TA will type in
$> java mp5to run it. Failure to do this will result in the loss of a few points on the assignment.
Your program must be written in good programming style. This includes (but is not limited to) meaningful identifier names, a file header at the beginning of each source code file, a function header at the beginning of the function, proper use of blank lines and indentation to aide in the reading of your code, explanatory "value-added" in-line comments, etc.
The work you turn in must be 100% your own. You are not allowed to share code with any other person (inside this class or not). You may discuss the project with other persons; however, you may not show any code you write to another person nor may you look at any other person's written code.
You are to submit this project using the CS Department's UNIX machine's turnin command. The project name for this assignment is mp5. Be sure to submit all source code, header files, make file as well as your program description. Failure to turnin all required pieces will result in a lower grade for the assignment.
For 5 points extra credit:
Create a feature that allows the user to click the left and right
buttons at the same time on a position that has already been clicked
and has a number. This feature will then check to make sure that there
is the right amount of flagged positions surrounding the clicked
position (for instance, there should be 2 flagged places surrounding a 2).
If this checks out, then the game will clear all the unflagged
positions surrounding the original position. If any of the unflagged
positions that are cleared have mines in them, the player will lose
just as if he/she had clicked on that box directly.
Additional Comments and Hints
Additional Extra Credit
The following was suggested as an additional feature for extra credit.
For 5 points extra credit:
Create a feature that allows the user to click the left and right buttons at the same time on a position that has already been clicked and has a number. This feature will then check to make sure that there is the right amount of flagged positions surrounding the clicked position (for instance, there should be 2 flagged places surrounding a 2). If this checks out, then the game will clear all the unflagged positions surrounding the original position. If any of the unflagged positions that are cleared have mines in them, the player will lose just as if he/she had clicked on that box directly.