Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / Swing

Improved Minesweeper, I Think

3.48/5 (9 votes)
28 Jan 2009CPOL2 min read 67.3K   763  
A simulation of Minesweeper by Microsoft with improvement, I think
Image 1

Introduction

This Minesweeper game is a simulation of the one made by Microsoft. The playing field and the mine- and time counter are an exact copy of the one made by Microsoft. I've not copied the smiley thing, I don't like it.

Background

Since I am using Microsoft Windows Vista or Microsoft Windows 7, I really dislike the Minesweeper game. I think the one shipped with Microsoft Windows XP is the best. Except the use of left and right button simultaneously for opening fields after setting some flags. Why should I want to use two buttons while using only the left button is much more useful? Especially since it's not taken by any other function.

Using the Code

MinesweeperPanel

This JPanel creates the playing field based on the difficulty. There are three levels of difficulty: beginner, intermediate and expert. It contains a 2 dimensional array of fields.

Field

A field knows its x and y coordinates for painting at the right spot, how many neighbour fields contain a mine, if it is clicked, if it is a mine, if the user made it a flag and if the user clicked it while it is a flag.

The numbers, flag and mine are painted by hand so they will look the same on any OS. At least, I hope so.

The method setGameOver is used for setting up the playing field after the user has clicked a mine. The method setWon is used for setting up the playing field after the user has removed all non mine fields.

Display & Digit

Displays are the mine counter and the time display. A display consists of three digits.

Disclaimer

English isn't my main language, so it can be unreadable. I'm sorry. I don't use comments in my coding, it scares me and I think comments makes the code unreadable. After all, methods should do what they are called.

History

  • 28th January, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)