Click here to Skip to main content
15,887,214 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.3K   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 
Hi,

First of all, this is a bad article, I know. Next this is a Java application and one of the powers of Java is that the programmer should use explanatory variable and method names.

1. The xml comments aren't common use in java. Just use javadoc;
2. Java programmers will not use a method name like MyCoolFunction, because;
- Camel case, please use camelCase;
- MyCoolFunction does not explain any use of whatever this method does.

Let me be clear about this subject. At this moment I work as a developer and I learned that comments can come in handy in case of development on big projects. Still if you follow the Java code conventions, comments are only needed to explain why you made a developer decision.

Comments are mostly added to explain what a method does. In case of this application the methods are that simple and named for what they perform. The method does what is saying it will, that is what a methods should be named.

My two main reasons for not using comments are:
- Comments aren't reliable. In case of adjustments of code, comments are often not updated. Double administration isn't desirable, so there are two solutions. The first solution is to make sure the development team keeps comments up to date. Second solution is to use explanatory method and variable naming which should be default if following the java code conventions.
- Comments are taking in space. This sounds dull but some programmers tempt to write 10 lines of comment for 3 line method body. This behavior isn't helping in any way, it is easier to read the code.

Next, if you are a starting developer and you really want to learn, you should first learn to read code. Read it and try to figure out what is going on. You should never rely on comments as a programmer.

Comments are for helping to understand, not for explanation.

I know I will never win this argument, but don't come at me with arguments which doesn't make any sense in the world of Java. If you really want to be a Java developer, you should read some books, read articles on the interwebs, follow tutorials. Both your arguments aren't Java related.

Sorry for being rude, but you really pissed me of with your arguments and please stop using caps. Using caps is for the dump screaming guys.

Regards, Eric
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.