Click here to Skip to main content
15,867,686 members
Articles / Desktop Programming / Swing

Improved Minesweeper, I Think

Rate me:
Please Sign up or sign in to vote.
3.48/5 (9 votes)
28 Jan 2009CPOL2 min read 65.1K   762   10   8
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)


Written By
Software Developer Fortes Solutions BV
Netherlands Netherlands
It's good to be me.

Comments and Discussions

 
GeneralCool and Nifty DooDad Pin
sam.hill17-Apr-10 7:08
sam.hill17-Apr-10 7:08 
GeneralMy vote of 1 Pin
Shukaido4-Feb-09 7:28
Shukaido4-Feb-09 7:28 
QuestionNo comments in source code because the function should do what it does ? Pin
J_Gamin3-Feb-09 5:14
J_Gamin3-Feb-09 5:14 
AnswerRe: No comments in source code because the function should do what it does ? Pin
Shukaido4-Feb-09 7:27
Shukaido4-Feb-09 7:27 
GeneralRe: No comments in source code because the function should do what it does ? Pin
Eric Beijer1-Jun-12 15:17
Eric Beijer1-Jun-12 15:17 
AnswerRe: No comments in source code because the function should do what it does ? Pin
Eric Beijer1-Jun-12 15:33
Eric Beijer1-Jun-12 15:33 
GeneralMy vote of 2 Pin
Steve Maier28-Jan-09 10:54
professionalSteve Maier28-Jan-09 10:54 
GeneralMy vote of 2 Pin
tamash_ionut28-Jan-09 9:15
tamash_ionut28-Jan-09 9:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.