Project: Minesweeper

Minesweeper Screenshot

Click the picture, open the .zip, and run the .jar file to play!

So we've all seen it. We've all played it. I wanted to try to make it. Here is another cool Minesweeper implementation if you're looking to try a few out: Nonosweeper.

For those of you who haven't played a Minesweeper game before, the idea is simple. There are some mines scattered randomly throughout the grid and your job is to find out where they are. When you click on a square, one of many things can happen. If the square ...

1) Is a mine, then you lose the game. Sorry.

2) Is not a mine but is neighboring one or more mines, then the square exposes itself as not being a mine, and furthermore labels itself with a number. That number represents the number of mines adjacent to that square (including diagonally adjacent).

3) Is not a mine, and is not neighboring any mines, then the square exposes itself. Additionally, all of the square's eight neighbors are automatically "clicked on" by the computer (this procedure recurses for each of the square's neighbors). Why that last step? Because if instead the square were just exposed with the number "0" (to indicate that it is not adjacent to any mines), then the user would have waste time clicking each of the eight neighbors one by one. This is just like a shortcut the computer does to save time for the player.

The objective of the game is to use the clues given by the labeled numbers to reveal where the hidden mines are in the grid.

Building something like this taught me a lot of small things about Java's GUI, such as mastering the grid layout, figuring out how to recognize and distinguish between right and left mouse clicks, and loading graphics properly on buttons. I know Microsoft probably won't come asking me for my code to include for the newest version of Windows, but if they do, I'll be ready.

Want the source code for this project?

Your Name
Your Email