• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Just for fun: working program of the Game of Mines

 
Saloon Keeper
Posts: 6416
60
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just for fun, a working program of the Game of Mines.
 
Saloon Keeper
Posts: 10762
229
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BAM
great-success.png
[Thumbnail for great-success.png]
 
Bartender
Posts: 2402
106
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done !!! I played it a while and it worked for me Took me a while to figure out that right click was reset.
Waiting for your middle mouse implementation, that would make it interesting. A seconds timer would make it more exciting. I didnt understand the reason to have a code block in line 90, 97, 114. The variables modified in them are instance level so scoping isnt benefiting here (Unless I missed something)

Some nitpicks about the code:
Everything is done in a single class.
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE) instead of dispose
 
Carey Brown
Saloon Keeper
Posts: 6416
60
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
Stephan van Hulst
Saloon Keeper
Posts: 10762
229
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you kinda shot yourself in the foot by making the State class' memory representation so dense. It looks like you packed all of the following properties in a single integer value:

  • Whether the square is empty.
  • Whether the square contains a mine.
  • Whether the square has adjacent mines.
  • How many other mines the square is adjacent to.
  • Whether the player put a flag on the square.
  • Whether the square is revealed.
  • Whether the square is selected.

  • Not only is the handling of these flags tricky, the meaning of some of them are not disjoined. For instance, EMPTY is redundant because it is implied when QTY, MINE and FLAG are not set. QTY is redundant because you can infer it from the most significant three bytes. VISIBLE and SELECTED have no place in the square at all, because they are properties of the user interface, not the game model.

    As I see it, squares have two definite properties: Whether they contain a mine and whether they are concealed, flagged or revealed. A third property can be either how many mines they are adjacent to, or a list of neighboring squares. Keeping track of how many mines a square is adjacent to probably makes for a simpler model, so let's go with that. I would then write a basic Square class like this:

    Now, I can use this Square class to make a MineField:

    As you can see, there is no UI code in here. One can easily write a Swing user interface in a separate package that reacts to events on the model by adding a SquareChangeListener to the MineField.
     
    Run away! Run away! Here, take this tiny ad with you:
    Java file APIs (DOC, XLS, PDF, and many more)
    https://products.aspose.com/total/java
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!