Original

A salute to classic - Mine Sweeper in Java


In the summer semester I was taking a class in which we were asked to apply software engineer principles using a group project. Due to the limited time and resources (3-people group), we decided to do a small project, which is a replica of the iconic Windows game Mine Sweeper. Another reason we pick up this game is because each team member is more or less familiar with the game so we don't have to spend a lot of on the requirement part.

Requirement

It is a little surprise that the original version of game once shipped by default with Windows is now actually hard to find. There are updated versions of the game in the Store, but they are very fancy. Finally, we found an online version of the game (http://minesweeperonline.com/) that is quite close to original game. We use this version as the requirement benchmark. The user of game should be able to do the following:

  • Select game level from Beginner, Intermediate and Expert.
  • Restart the game at any time,
  • View the number of mines and time elapsed,
  • Left-click an empty square to reveal it.
  • Right-click an empty square to flag it.
  • Left+Right click a number to reveal its adjacent squares (this only works on Windows). We have a formal SRS file with more details about each requirement.

Design

I made the overall design which follows strictly the MVC pattern.

The class diagram was generated using Eclipse plugin – ObjectAid.

Implementation and testing

The model/data part is the center of any system. We decide to use two integers to presents the status of each grid, one for the cover and the other for the underlining mines or number of mines in its neighbor.

After the model was finalized, we started working separately on parts and I was mainly working the View part.

The most tricky issue in View part is how to differentiate the Left+Right mouse click from the Left or Right only click. The Left+Right click is actually two separate events. If you don't add specific logic, it can be identified as Left+Right, but always followed by additional Left or Right click event. It held me for 2 days until I saw a solution from another developer using a set of Booleans to identify the states of the mouse and eventually differentiate the both-click from single click.

I setup the project repository on my Github account and we use two branches(dev/master) and Collaborator mode which is perfect for a small team working on the same repository.

Unit tests were done using JUnit on the Model and Controller part and integration tests were done manually.

Summary

Although this is a very small project, but I do achieve a lot during the process.

  • gain in-depth understanding of MVC design pattern,
  • refresh Java graphic programming using SWING/AWT,
  • use Github as version control in a group environment.
  • final code: https://github.com/leon541/minesweeper
  • use Eclipse plugin for class diagram generation,
  • coordinate the team members with different background

Credits

Credits are given to my teammates Robert and Harika
and this project uses icons from

https://github.com/mengzhinan/MineGame


A Dry Run

frontend
backend