Background: Minesweeper has a long history, since minesweeper was developed to now countless optimizations, this game has become more and more people to put down, simple gameplay in addition to a good-looking game interface, every detail reflects the charm of minesweeper. JAVA language as the development environment, using Eclipse design and development of a similar Windows minesweeper game, to achieve its basic functions. The paper first introduces the background of the subject, and then carries on the demand analysis and feasibility analysis; Then design the game process, introduce how to place the thunder in the minefield and the random algorithm of generating thunder; Finally introduced the game may trigger a variety of time, such as a mouse click clear time and there is no ray of the grid, click the mouse events including the firing of ray hits or no events and click to start again and menu trigger events, clean up no ray grid will need to use the “recursive” methods to make the function can be simple to implement.

In 1964 there was a game called Cube, which was the original version of Minesweeper. Later, this game was changed to another game called “Rlogic”. In this game, the player takes on the role of a soldier in the army who is given the difficult task of finding his way to the command center. Of course, the game is not so easy, the road is full of mines, players need to carefully explore a safe road without mines, if the game is killed by lightning will end. A year later, Tom Anderson wrote a new game based on the previous one. It was Minesweeper. Minesweeper became popular around the world in 1979 when two engineers loaded it on their computer’s operating system. Nowadays, more and more people love this simple and easy to use small game, this small game can be played at any time on any platform, so that people can enjoy the fun in the game and also exercise the player’s thinking ability to a certain extent.

Minesweeper this game has a very long history, from minesweeper was developed to now countless optimization, this game has become more and more people to put down, simple gameplay in addition to a good-looking game interface, every detail reflects the charm of minesweeper.

Project address: github.com/sunmenglei/…

Homepage QQ group also has advanced compiler and information

How do I use Git to upload native code to Github

directory

1. Purpose and significance of the topic

1.1 Main contents of this paper

2 Demand Analysis

2.1 Feasibility Analysis

2.2 Function description of Minesweeper

2.3 Functional requirements of Minesweeper games

2.4 Interface requirements for Minesweeper games

2.5 Minesweeper function module

3 Design Concept

3.1 Process Planning

3.2 Interface Planning

3.3 Algorithm Idea

4. Detailed design of the game

4.1 Game initialization

4.2 Layout of minefields

4.3 Introduction and use of major modules in the game

4.3.1 Mouse Events

4.4 Surface detection of mines and minefields

4.5 Clear the grid that is not near the mine

4.6 Game difficulty selection

4.7 Menu Bar Functions

4.8 Game judgment

4.9 Successful completion of the game

4.10 Game failure

5. Class design

5.1 MineGame class

5.2 Block class

5.3 BlockView class

5.4 Record the class

5.5 ShowRecord class

5.6 MineArea class

5.7 LayMines class

6. Game implementation

6.1 Game difficulty customization

6.2 demining

6.3 Minesweeper by right clicking and displaying a red flag

6.4 The game ends when the player touches the thunder

6.5 Player minesweeper successfully

6.6 Display of players’ game data

6.7 Program packaging and release process

6.8 Game test results

6.9 Game difficulty custom test

7 Mine clearance testing

7.1 Player game data display test

7.2 Game data display area test

7.3 Recursive algorithm test

conclusion


Eclipse is a great compilation software that has been in development for a long time and is free software developed by a consortium of companies. In May 2011, the stable version 4.2 was released; Version 4.3, codenamed Ganymeode, was released in April 2012; Release 4.4, codenamed Galieleo, in May 2013; Version 4.5, codenamed Helomios, was released in July 2013; Version 4.6, codenamed Indigon, was released in November 2013; Release 5.1, code-named Jiuno, was released in March 2014; Version 5.2, codenamed Keplere, was released in July 2014; Release 5.3, code-named Lunam, was released in March 2015; Release 5.4, codenamed Marse, was released in August 2015.

Eclipse is the current mainstream software for writing code. It supports precompilation so that you can know if you have a typo as you write it, rather than having to wait until you run it. Originally this software can only write Java language, but after years of development design many plug-ins, these plug-ins can be installed into the writing of other languages, that is why it is loved by most people. Thanks to the use of plug-ins, Eclipse has become very flexible. Plug-ins can be installed to achieve functions that are not available, making the software more convenient.

Eclipse was originally designed and developed by two teams, and many companies joined the project because of the power of the software. And because the project was open source and anyone could make changes to it, Eclipse became so famous that even big companies like Oracle joined the project. This free development software is also popular with many companies and can be used in a variety of languages by installing plug-ins.

The Java language is a beloved language, because it is object-oriented, so after understanding this language will have a deeper understanding of code design.

Without the JDK, your Java code would not run. This is because we need to use its own class library to help us design. Since different software can write code, the language specification is very important, so it is important to have the JDK installed before you start writing code.

There are many, many JDK versions available on the web, with Sun publishing the best and others developing and publishing them. Some even outperform Sun’s JDK in performance, while others outperform Sun’s JDK in efficiency. But the reason we chose to use it is because it is the most stable JDK, unmatched by other JDKS after years of development and refinement. So we have to use it skillfully.

1. Purpose and significance of the topic

In the design process, I can integrate and improve my knowledge in practice, and find many problems that cannot be found in ordinary times. I hope to improve my ability again through this design. I will gain a lot this time, and I can easily be competent for any task in my future working life.

1.1This paper mainly studies the content

Minesweeper is popular all over the world and is loved by many people. After researching the minesweeper game, I found two key points:

The first point is the processing of mouse events, including clicking the button in the menu item, clicking any lattice in the minefield, clicking the button on the interface, etc.

The second point is to initialize the minefield, including random generation of lightning location, interface initialization, calculation of the number of surrounding lightning, etc.

Specific requirements are as follows:

(1) Minesweeper is divided into three levels of difficulty, namely, primary, medium and Advanced. Click on the “Game” menu in the upper left corner of the game and there will be “Primary”, “Intermediate” and “Advanced” options. Players can also customize the difficulty.

(2) After the player selects difficulty, the game will change the screen size and change the total number of mines. When the player clicks on the first grid the minefield begins and the timer starts.

(3) If the player wants to quit the game and start again, he can click the button in the minesweeper statistics area to end the current game and start a new one.

(4) When the player thinks a grid is not ray, he can directly click the grid with the mouse or put the mouse on the grid and press the space bar. If the player’s judgment is correct, the total number of mines in the surrounding 8 cells will be displayed. If the player’s judgment is wrong and there are mines hidden under this cell, the game is over, and the system automatically pops up to indicate that the player has failed.

(5) If the player thinks there is thunder under a grid, the right mouse button on the grid can mark an icon that the player thinks the grid is thunder, that is, mark a red flag pattern on the grid. Every time a player flags a red flag (regardless of whether the player is correct or not), the count area on the interface reduces the number of mines by one.

(6) When all the thunder are marked correctly, the game will automatically pop box display “you really good, please input your name, record list!” .

(7) If the player clicks the grid with thunder during the game, the game fails and stops with time, the game will display all the remaining thunder, and the automatic pop-up box will show “You lost, please continue to work hard!” After that, the player can start a new game.

(8) If the player does not know the game play, he can click on the menu bar to get the game play and game tips.

(9) For custom difficulty, the system will have a threshold between 9 and 16 rows, 9 and 30 columns, and 10 and 99 mines. If the player sets a value that exceeds this threshold, the system will automatically turn the exceeded value into a threshold.

2 Demand Analysis

2.1Feasibility analysis

Minesweeper is a simple game that can be played by children and the elderly in a relaxing and effective way to relieve stress. And a true minesweeper can also have fun by racing (minesweeper in the shortest time possible).

(1) Investment feasibility: Minesweeper takes up less memory and can be loaded on any platform, so it has investment value.

(2) Financial viability: From the perspective of the beneficiaries, this minesweeper mini game can be developed without too much money.

(3) Organizational feasibility: project planning with feasible system, personnel allocation, good communication among team members, regular meetings and discussions to ensure timely delivery of the project.

(4) Economic feasibility: It can create benefits for the enterprises, increase jobs for the society and improve people’s quality of life.

(5) Legal feasibility: any product needs to ensure that it does not violate the law before it can be designed. But minesweeper doesn’t break any laws and doesn’t run afoul of companies. The development of the game will not infringe on anyone’s interests, nor will it be illegal.

(6) Technical feasibility: Minesweeper games have simple functions and can be easily developed by experienced developers. Therefore, the technical aspect is not too big a problem. It is mainly necessary to understand the gameplay of minesweeper to better design and implement the game.

2.2 Function description of Minesweeper

The game interface can be divided into three modules: the menu bar, the game data display area and the minefield. The menu bar includes game difficulty selection and leaderboard query as well as game help. The game data display area includes the mine count area, the timing area, and the restart button. The minefield is the game area of the player. When the player clicks on a module with the mouse during the game, the system will automatically respond accordingly, which is the mouse event in the game.

When the player clicks on the first grid the minefield begins and the timer starts. The number of mines in the eight surrounding squares is then displayed on the grid (if there are no mines, the surrounding squares are automatically opened), and the player needs to determine the location of the mines by these numbers, and flag the boxes that are mines as red flags.

If the player thinks a marked grid is wrong, he can right click it again to unmark it. When a grid is marked, clicking on that grid is invalid (to prevent the player from accidentally clicking and causing the game to fail).

If the player marks one of the eight surrounding squares, double-clicking on that box will automatically click all the surrounding squares again, simplifying the player’s actions.

The game ends when the player has marked all mines and opened the other squares. However, if the player accidentally clicks on a mine, the game will fail and the system will automatically display all mines. If the number of mines the player identifies exceeds the number specified for that difficulty, the count area will show the number of mines exceeded as a negative number and the game will not end.

 

As can be seen from the above function description and use case diagram of minesweeper game, the operations that players can perform in the whole game include: selecting difficulty, starting the game, restarting the game, and recording and querying.

2.3 Functional requirements of Minesweeper games

The main functions to be realized in this mine clearance design are as follows:

(1) Players can choose the appropriate game difficulty

Click the “Game” menu in the menu bar at the upper left corner of the game interface, and four options of “Primary”, “Intermediate”, “Advanced” and “Custom” will appear. After the player chooses difficulty the game changes the screen size and changes the total number of mines. The first three mines have a fixed number and size and do not need to be set by the player, while customizations are defined by the player.

(2) Play minesweeper

The game interface includes the menu bar, the game data display area and the minefield. When the player clicks any one of the minefields, the game starts and the minefield starts to be mined randomly. The player needs to find all the mines in the minefield in the shortest time and mark them.

The basic operation of minesweeper includes two kinds of left click and right click. The left button is used to open the grid that the player thinks is not Thunder, and the right button marks the grid that the player thinks is thunder.

Left click: the player can open the grid by clicking on it when it is determined that there is no thunder under it. If there are mines around the cell, the number of mines around it will be displayed (since there are only 8 cells around, the maximum number of mines can be displayed is 8). If nothing is displayed on the cell (that is, empty), the system automatically calls a recursive method to open a nearby cell. If you click on a grid with mines, the game ends and the system displays the locations of all mines.

Right click: Players can use the right mouse click to mark the grid that they think is thunder, which can be marked to improve the efficiency of minesweeper. Right click on the grid again to unmark the grid, and the mouse click is invalid when the grid is marked (to prevent the player from misoperating and causing the game to fail).

(3) Game timing

When clicking any grid in the minefield, the minefield starts to be mined at the same time the timing starts. The timing standard is increased by 1 second. If the game fails, the timer stops. If the player starts a new game, the timer restarts.

(4) Marking mines

When the player thinks there is thunder under the grid can be right click to mark the grid, the marked grid shows a small red flag. A second right click unmarks the grid, and the mouse click is invalid when the grid is marked (to prevent players from misoperating and causing the game to fail). If the number of mines the player has identified exceeds the limit for that difficulty, the count area will show the number of mines exceeded as a negative number and the game will not end.

(5) Statistical function

When the player wins the game will pop box prompt and can input the player’s name, after confirming the game records will be saved. Players can click on the “Games” menu on the menu bar, and then click on the “Minesweeper List” to see the best records of the game.

(6)

Click the Close button to end the game.

2.4 Interface requirements for Minesweeper games

(1) Game menu

The player has 5 options to choose from. The size of the game interface will change to the primary size when the player clicks on the primary level. The minefield will be reinitialized into a total of 9*9 cells, of which 10 are mines. There are 16 x 16 tiles in the intermediate level, of which 40 are mines; There are a total of 16*30 cells in the advanced level, of which 99 are mines. In addition, players can customize the difficulty and fill in the number and size of mines in the pop-up box.

 

By clicking the right mouse button, players can mark the grid they think is mine, which can improve the efficiency of minesweeper by marking it, and clicking the right button again can unmark it.

Minesweeper board, which records the shortest time for different difficulty.

(2) Game area

The game area is composed of minesweeper information statistics area and minesweeper information statistics area is divided into counting area, timing area and restart button.

The number of mines in minefields varies for each difficulty level, with 10, 40, and 99 mines for the beginner, intermediate, and advanced levels.

The initial number of mines displayed in the count area is determined by difficulty, with the number of mines decreased by 1 for each mark. If the number of mines marked by the player exceeds the specified number of mines for that difficulty, the count area will show the number of mines exceeded as a negative number.

The timer starts when the player clicks on the first grid to start the mine. One second is added and the timer stops when the game is won or when the game is lost.

2.5Minesweeper game function module

The game is functionally divided into six modules:

(1) Game interface

(2)

(3) Mouse events

(4) Mine identification

(5) Victory of the game (end)

3 Design Concept

Many people in the world now use The Windows operating system, so they are familiar with the mini-games that come with the system. Minesweeper game play is simple, as long as players make certain judgments can be easy to play, so playing minesweeper can be very easy to play. In addition to the fun brought to people by the game itself, the game play is also to exercise the players’ thinking, now most people are dependent on mental work, this can be through playing minesweeper in leisure time to exercise themselves. So it’s understandable why this little game is available on all kinds of electronic products.

Although the game is relatively simple, but still need to be familiar with the rules.

Players need to find out all the mines in the minefield in the shortest time, and to mark, the other grid without mines all open after the game victory. But if you click on a mine, the game fails.

The operation of the game is very simple, when the player clicks on the grid that he thinks is not a mine with the left mouse button will point open the grid, click on the grid with the right mouse button will mark the grid, right click again can cancel the mark. Players can identify the mines hidden in the eight surrounding cells by the numbers displayed on the dotted cells in the minefield. For example, if the dotted cells show the number “2”, it means that there are two mines hidden in the eight surrounding cells.

If there is no lightning under the open grid and there is no lightning in the surrounding eight grids, the system will automatically open those eight grids and recursively determine whether there is lightning around these grids.

This minesweeper game design, need to write 7 Java classes: Java classes mineagamae.java, Mineara.java, block. jaav, Blockvaiw. Java, Layminas.java, Record.java, and ShowRecrd.java.

(1)  MineGame.java

The MineGame class is the entry point to the game and is used to initialize game resources such as interface dimensions and thunder count. It’s also responsible for the difficulty shift.

 (2)  MineArea.java 

The MineArea class is a mine that lays out minefields, in addition to initializing minefields and responding to player mouse movements.

(3)  Block.java 

The Block class is a POJO class that records the properties of each cell in a minefield, such as the name, the number of mines around it, and so on.

 (4)  BlockView.java 

The BlockView class displays the properties of a block and uses a card layout to divide the block into two layers. When the player clicks on the block, the properties below appear.

(5)  LayMines.java 

The LayMines class is a class that calculates the number of mines around non-mines and sets the image style when selected. The object created, Lay, is the most important member of MineArea.

(6)  Record.java 

Record class is through THE IO stream game records stored in the local file, the main realization of the pop-up window after clearance prompt clearance window, as well as Record results.

(7)  ShowRecord.java 

The ShowRecord class is a class that displays mine-clearance records.

3.1Process planning

There are three sections: after the game selects difficulty, the first time the player clicks on a grid, and the automatic opening of a grid that is not a mine.

After selecting difficulty, the game will get the number of thunder and the interface size display interface set by the difficulty, but there is no lightning. The system randomly mines and starts the timer when the player first taps the grid, so why not lay the mines after clicking the grid once? The point is to make the first time the player doesn’t click on a mine, otherwise the player will be upset, so that the player will want to play the game. Then is the most important step, is how to automatically open the grid around the grid without thunder, we can use the recursive method to skillfully judge and open the surrounding grid.

 

 

3.2 Interface Planning

 

The description is as follows: ① : The main Interface of the game.

② : Menu.

③ : MineNumberArea

④ : Restart.

⑤ : TimeArea of minesweeping.

⑥ : MineArea.

3.3Algorithm thought

(1) Random mines

Minesweeper requires that mines be laid randomly in a minefield, and the number of mines should not be too high, so that it is not a good judge of the surrounding mines; But not too little, so that there will be a click will open a large blank area. The Java math.random () method is used to generate a random number. After calculation, the random number is converted into an integer, which is the corner marker of the location of the thunder. The goal of the game is to mark all mines and open the other boxes that are not mines.

(2) Calculate the number of thunder around the grid

When a box without lightning is clicked, it displays the number of all the lightning in the eight surrounding squares. The player can determine the location of the lightning by this number, so the calculation of the number of lightning around the box is also important.

4. Detailed design of the game

4.1Game initialization

When the player clicks on the game, the system automatically loads the interface, including minefield, menu area and mine-clearing data display area.

The game interface is relatively simple compared to the computer mine clearance game, mainly composed of game data display areas and minefields.

We use the ImageIcon object to store the mine icon, but it is better to keep the icon size small, otherwise it will not display fully on the grid.

It is important to initialize the mine area, and we can do this using a loop. After PM game can click on the menu bar to choose the difficulty of the mine clearance game, the difficulty in a sequence represents the total number of different mines and size, the difficulty of the custom can also set the ray number and size, set up all the data stored in several variables, when the minefields to initialize program would call so variable attributes, and then through a cycle to complete initialization. The main code is as follows:

  

The loop initialization mentioned before is actually the loading component of the loop. The minefield is composed of components one by one. All the grids are arranged to the minefield through the loop, and then mines are randomly generated and arranged on the minefield.

Components are placed according to their position in the array. All grid components are stored in a two-dimensional array, and the subscript of the component in the array is its position in the layout.

The menu bar is made up of menu components, namely the JMenu component, this is the menu component, which defines the style of the menu when it is not clicked, and this component has the JMenauItem component, which is the name of the menu item, which is the submenu bar that is displayed when the player clicks on the menu.

Minesweeper’s timing and counting areas are done using another component called JTextField

This component is a text display component. After setting the non-editable property, the component will change the appearance of the display. The border will be grayed, meaning that the component cannot be clicked or typed. Then use a method that dynamically increments the time area by one second over time, and the count area decreases by one as the user marks the ray, which can be reduced to a negative number.

There are also some Settings that need to be made when setting up the interface, such as setting the properties so that when the player closes the game window, the system will automatically release resources and close the window.

4.2The placement of minefields

The system randomly mines and starts the timer when the player first taps the grid, but why not lay the mines after clicking the grid once? The idea is to make the first time the player doesn’t click on a mine, otherwise the player will be upset, so that the player will want to play the game. The specific implementation is as follows:

Determine whether the minefield is in a motable state:

 

Judged as left key and the grid is in undetected state:

   

Lay mines:

                             

Determine where mines should be placed:

               

4.3 the gameThe introduction and use of the main modules in

4.3.1 Mouse Events

We complete the game by clicking the left mouse button or right mouse button, and use the system’s own MouseDown and MouseUp events to respond to the player’s actions.

The function prototype is as follows:

Component name:

Component name:

The parameter in these two prototypes, the Button parameter value, represents what the player clicked with the left or right mouse Button, respectively. Its meaning is as follows:

1: left key 2: right key

If you press both keys at the same time, then the system returns 3, because left is 1, right is 2, and you start adding the two values.

In the minesweeper design, we will use the mouse MouseUp event to respond to the player’s actions, where the left mouse button is used to open the grid that the player thinks is not mined, and the right mouse button is used to mark the grid that the player thinks is hidden. The reason for using the MouseaUp event instead of the MouseaDown event is that the MouseaUp event is triggered when the mouse button is raised, while the MouseaDown event is triggered when the mouse button is pressed. If the player suddenly finds that the point seems to be wrong when clicking on a grid, the player only has to continue to press the right mouse button at this time, and then when lifting it will find that the grid is marked as a mine, now the game generally has this function, which can effectively improve the player’s game experience.

In the interface of human-computer interaction, the operation of the mouse is very important, but the design of the program is ignored so that the mouse can not play its due function. The use of MouseUp in response to mouse click events is also explained above, which can subtly let players feel the warmth of the game and effectively improve players’ game experience.

When the left mouse button is clicked on the grid:

When right clicking on a grid marked with thunder:

4.4 Surface detection of mines and minefields

In the minefield design, I used the method of looping loading components to fill the minefield with grids, and if the player clicked on a grid, the components hidden under that grid would be revealed

 

 

 

 

 

Players click on a grid to open it, and right-click to mark the mine. Due to the use of the two arrays record the position of the mines, and be open information, so can be judged by two layers of nested loop around the grid, the number of ray and the system will around 8 PM on the grid grid no ray in the grid, it need to use recursive calls to the PM on the grid and validation process, until it is not in conformity with the conditions. Using this nested loop and recursive call, will make a time-consuming problem become easy to solve, make the code structure also become clear, and will improve the system’s calculation speed.

4.5Clear those not near minesgrid

Before we begin, we need to introduce and learn about recursion. Recursion is a narrow definition of a method call itself, with a judgment statement deciding whether or not to terminate the call. It is also a very important structure in the design of the code, and writing code in this way makes the structure of the code look fairly straightforward. However, it should be noted that if the improper operation will be the system infinite loop call, making the game crash, so when writing the code must use a judgment statement to control the end of the loop call, to stop the recursive call of the method.

When the player clicks on any grid while playing the game, the system will detect whether mines are hidden under the surrounding 8 grids. If all the mines are marked or there are no mines, the mines will be clicked on and the loop will be called to continue to determine the number of mines around the clicked grid.

Judgment criteria to consider when designing: the player clicks on a grid to determine whether mines are hidden under that grid; If there is no thunder, judge the number of thunder around 8 grids and display; If all the rays are marked or there aren’t any rays in the first place, the recursion determines the rays around the dotted grid.

Since recursion is a loop calling the method itself, a judgment statement is needed to end the call, display the number of mines on the grid when there are mines around the dotted grid and end the recursive call.

The recursive approach, while good, has some disadvantages. In addition to the importance of selecting the end condition, if the size of the minefield is too large and the number of mines is too small in the mine-clearance design, it can make the loop call slower. Therefore, we should be careful in the gameplay design of the game, not random definition, so as not to create a burden on the system, so that the game can not proceed smoothly.

The code section is shown below

4.6 Game difficulty selection

Design of mine I have on the choice of difficulty there are three kinds of difficulty, the beginning, middle and senior respectively, these three difficult definition of ray number and the size of the minefield is fixed, if the players want to define the difficulty of mine sweeping ray number and size, can set themselves up as long as open the “custom” configuration window, later in the spring box according to the prompt for ray number and the size, number of rows up to 24, The maximum number of columns is 30, and if the number of mines the player sets exceeds the range (such as more than the total number of cells or less than zero), the system defaults to the number of mines multiplied by the number of rows minus one and the number of columns minus one.

4.7 Menu Bar Functions

Beginner: Set the total number of squares to 9 x 9, the total number of mines to 10, the size of 300 x 380 and restart the game.

Intermediate: Set the total number of squares to 16*16, total number of mines to 40, size 480*580 and restart the game.

Advanced: Set the total number of squares to 16 x 30, total number of mines to 99, size to 800 x 500 and restart the game.

Customization: Set the total number of squares to a maximum of 24*30, and a maximum of 24*30 thunder, then restart the game.

Minesweeper list: opens and displays minesweeper records with the shortest time, which can be updated and re-scored.

4.8 Game judgment

4.9Complete the game successfully

The game requires the player to complete the game in the shortest time, when the player will mark all the thunder out and other grid are opened after the game victory, the system will pop up a prompt box to tell the player “you are really good, please input your name, record list!” , the system records the shortest time the player has completed the game.

4.10The game failed

If the player unfortunately clicks on a grid with mines, the mines in that grid will detonate other mines, the game fails, and the system will display all the remaining mines, with a pop-up saying “You lost, please keep trying!” The player can start a new game by selecting the restart game option on the popbox.

An object of the grid class has an attribute that identifies whether the grid is a mine, and that attribute is used to determine whether the player is pointing at a mine. At the end of the game, this attribute is also used to determine which boxes have thunder and display it.

The specific code is as follows:

5. Class design

5.1MineGameclass

The MineGame class is responsible for starting the game, designing the menu, and switching the difficulty. Shows a UML diagram of the class

 

 

 

(1) Member variables

Bar is the menu bar variable of the form.

FileMenu1 is the menu for minesweeper called “Game”.

FileMenu2 is another minesweeper menu, called help.

Beginner is the difficulty variable of minesweeper.

Intermediate is the difficulty variable of minesweeper.

Advanced is the difficulty variable in minesweeper.

Mine clearance lists are statistical information variables for mine clearance.

MineArea is the object of mineArea mines and is the variable used to design minefields.

File is the file variable used to read mine-clearance records.

Hashtable is used to temporarily store mine-clearance records.

ShowHeroRecord is a variable used to display mine-clearance records.

 

(2) Member method

MiwneGaame () uses this method to set the overall position and layout of the game, implement menu bar functions, and initialize statistics.

ActionPerformed (ActionEvent E) is a method that responds to clicking on a menu item, allowing you to adjust the number and size of thunder for different levels of difficulty. Clicking on different menu items causes the method to perform different actions.

The main() method is the way to start the game by creating a New MineGame object.

5.2 Blockclass

The Block class is a POJO class that records the properties of each cell in a minefield, such as the name, the number of mines around it, and so on. Shows a UML diagram of the class

 

 

(1) Member variables

Name is the variable that records the Name of the grid.

IsMine is the variable that marks the presence of mines under the grid.

IsMark is a variable that marks the tagged state of the grid.

MineIcon records the variable of the block’s icon.

IsOpen is a variable that marks the open state of the grid.

ArounfdMinqeNmber is the variable that records the number of mines in the 8 cells around the grid.

(2) Member method.

Block() takes no arguments constructor to prevent the creation of an object with the wrong arguments.

Block (String name, int aroundMineNumber, ImageIcon mineIcon, Boolean isMine, Boolean isMark, Boolean isOpen) full constructor, can for the variable assignment.

The setNamqe() method sets the name of the block.

GetName () gets the name of the block.

The setAounMineNuber() method sets the number of mines around the block.

The setMineIicon() method sets the block icon.

GetMineIcon () gets the block icon.

The setIsMinae() method sets whether a block is a mine.

GetAroundMineNumber () gets the number of mines around the block.

GetIsMine () gets whether the block is a mine.

The setIsMarek() method sets whether a block is marked.

GetIsMark () gets whether the block is marked.

SetIsOpen (Boolean p) Sets whether the block is dug.

GetIsOpen () gets whether the block is dug.

ToString () prints the object as a string.

5.3BlockViewclass

The BlockView class inherits the JPanel class, which mainly arranges the layout of each grid and defines the properties of each grid. Figure 4-6 shows the UML diagram of this class.

 

(1) Member variables

BlockeNameOrIcona This variable is used to display the lattice’s name and icon properties.

BlockeCoverq is a tag variable.

Card Displays the components that are added for the first time.

(2) Member method

The BlockView() constructor initializes variables, sets the display position of the properties on the block to center, and adds components.

The giveView() method gives a view to each grid. If there is a mine under the grid, the method is called to give the grid an icon of “mine”, but it is overlaid underneath. If there are no mines below, the number of mines around the grid will be displayed, which will also be covered. This method displays thunder or numbers when called.

The seeBlouckNamerOrIcon() method is used to display the attributes of the block.

The seeBlouckCovear() method is to make the cover cover block property.

The getBlouckCovear() method gets the button for masking.

5.4Recordclass

Record class is mainly realized after customs clearance pop-up prompt customs clearance window, as well as Record results. When the player successfully minesweeper, this object provides an interface to save the score to a file. Figure 4-7 shows the UML diagram of this class.

 

(1) Member variables

Time is used to time the game.

Grade records variables of difficulty.

Key represents a variable of judgment.

Message Is the data variable that records grades.

TextName A text display component.

Label A component of an input text box.

Two button components, one for OK and one for cancel.

 

(2) Member method

The Record() constructor initializes variables and sets whether the window can be resized.

The setGrade() method sets the grade.

The writeRecord() method reads and writes records. If there is no record, a new document is created to save the record and the overwrite record is directly modified next time.

The setTime() method is used to set the time.

ActionPerformed (ActionEvent E) method is a method that responds to the mouse click event. It will be triggered when the player clicks on any position on the popover, but the action will only be performed when the correct position is clicked. Click OK, for example, to save the player’s game records to a local file.

5.5 ShowRecordclass

The ShowRecord class is a class that displays mine-clearance records. Figure 4-8 shows the UML diagram of this class.

 

  1. Member variables

File File that records grades.

The name names.

A hashtable is a variable that records grades.

Show is a button component variable that displays grades.

Rescore is a button component variable for the initial score.

Label1[] component that displays grades.

Label2[] component that displays grades.

Label3[] component that displays grades.

 

(2) Member method

The ShowRecord() method is the constructor of the class and initializes the member variables.

The readAndShow() method filters out the player’s progress recorded in the document (based on the shortest time it took to complete the game) and displays it in a pop-up dialog.

ActionPerformed (ActionEvent E) method is a method to respond to the player’s operation. When the player wants to display the game record, the system will respond to the player’s request and call the method to display the score, and refresh the score in the pop-up box.

5.6MineAreaclass

The MineArea class is mainly used to initialize minefields and respond to mouse events. Figure 4-9 shows the UML diagram of this class.

 

  1. Member variables

The reStart is used to display a reStart button.

A block is a two-dimensional array that defines the grid of all minefields.

BlockView is a two-dimensional array that provides a display view for each grid.

Lay is responsible for defining each grid with or without lightning.

Row, colum is the variable responsible for recording the number of rows and columns in a minefield.

MineCount is a variable that records the total number of mines.

MarkMount is a variable that records the number of mines marked by the player.

Mark is a variable of type ImageIcon used to store mine ICONS.

Time is a variable that records time.

Grade is the variable that records difficulty, and there are “elementary,” “Intermediate,” and “advanced.”

PCenter is a variable of type JPanel that defines the controls in the middle of the layout

PNorth is a variable of type JPanel located in the northern control of the layout.

ShowTime is the variable that displays the minesweeper time.

ShowMareedCoint is a variable that shows how many mines are left after the player marks.

Record is a dialog variable that displays the player’s best record, which is displayed when the player clicks on the heroes list in the menu.

Lose is the dialog variable that is displayed when the game fails.

SpendTime is a marker variable.

Panel A lightweight container variable nested in a dialog box.

STR a textbox variable that displays a failed prompt.

ReStart1 is a button object in the failure dialog box that the player clicks to trigger the same action as reStart.

  1. Members of the method

The MineArea() method is a constructor of this class that initializes the component and subobject, sets the font color, border color, etc., and initializes the MineArea by calling the MineArea initializer method.

The initMineArea() method is used to initialize minefields by setting the number of mines and the number of all grids in the game interface.

The initMine() method is the one that actually performs the initialization.

The setRow(int row) method sets the number of rows.

The setColum(int colum) method sets the number of columns.

The setMineCount(int mineCount) method is used to set the total number of mines.

The setGrade(int grade) method is used to set the difficulty.

The actionPerformed(ActionEvent) method is a method that responds to the event when the mouse clicks on a grid. If there are no mines below the clicked grid, the method displays the number of mines around the grid and the icon of mines if there are mines.

The show() method displays the contents of the grid and uses recursive calls to display the contents of the surrounding grid until there is thunder around it.

The mousePressed(MouseEvent) method responds to left and right mouse clicks on the grid.

The inquireWin() method is triggered when the player meets the win condition during the game, and other methods will be called to indicate the end of the game.

5.7LayMinesclass

LayMines is a class that calculates the number of mines around non-mines and sets the image style when selected. A UML diagram that identifies the class

 

  1. Member variables

MineIcon image resource variable.

  1. Members of the method

The LayMines() constructor defines the image resource.

The layMinesForBlock(Block Block [][], int mineCount) method determines if it is the first time the player clicked on a grid. If it is the first time the player clicked on a grid, it will start generating random thunder, but the thunder will not be placed on the first grid. If it is not the first click and there is no thunder, the number of thunder in the surrounding 8 cells will be counted and displayed.

6.The game to achieve

6.1Game difficulty customization

 

 

Game players can choose the difficulty, one of the primary, intermediate, advanced, and the custom four kinds of difficulty, corresponds to the size of the game interface is not the same, and the total number of mines were different, ray number, the more the greater the difficulty, at the same time, players can customize the game difficulty, by typing ranks number and set the size of the game interface and the difficulty of landmines.

The screen size and thunder count of the game are shown at the beginner, intermediate, advanced, and custom levels.

6.2Mine clearance

6.3Minesweeper is performed by right-clicking and displaying a red flag

 

During the game, the player will judge whether there is lightning around a certain grid. When the player thinks there is lightning under the grid, he can use the right mouse button to click the grid and mark it as a red flag, as shown in Figure 5-6.

6.4 The game ends when the player touches the thunder

As shown in Figure 5-7, when a player opens a box with mines, the game fails, and the system will automatically show all mines, and a window will pop up to remind the player: “You lost, please keep trying!” . In addition, there are two options: when the player selects the restart button, the game interface is initialized, all mines in the minefield are cancelled, and the mining starts after the player clicks the grid for the first time; If the user clicks Cancel, the prompt can be turned off.

6.5Player minesweeper successfully

 

As shown in Figure 5-8, when all the mines are marked with red flags and the non-mine grid is opened, the game ends and the timing stops. The system pops up to remind the player “You are so good, please input your name and record to be listed!” In this interface, players can input their name to save minesweeper scores.

6.6Player game data display

 

Every time the player successfully sweep all the thunder, the system will automatically record the results, saved in the local TXT document, the content is three kinds of difficulty, the player name and the corresponding difficulty of the player used the minimum game time. When the player clicks to view the heroes list, the system only shows three difficulties and anonymity by default.

 

When the player clicks close, this window will close the popover. When the player clicks re-score, the statistics information will be cleared, and when the player clicks Show score, it will refresh and display the best score in history. The interface will also change to show how long the game took.

6.7 Program packaging and release process

Now that the minesweeper game has been written, we can package the game and publish it. This requires the jar.exe command to package the class file of the written minesweeper game and publish it.

(1) Compile list files. First need to use “Notepad”, according to the requirements of their own to write a list file, format and content and here to look like the same, the specific content is as follows:

Save the manifest file to E:\workspace\ minesweeper \bin\com\zx\mine, in the same place as the bytecode generated by the minesweeper program you wrote. Make sure to keep these files in the same directory.

Note that everything in the manifest file is stored as key-value pairs, and the key-value pairs must be left blank.

 

  1. Generate the JAR file. Jarcfmgame.jarmymoon.mf *.class E: workspace minesweep.jarcfmgame.jarmymoon.mf *.class

The c parameter means that you want the system to generate a file called JAR.

② The f parameter means that the system should generate the name of the JAR file.

③ The parameter m means the name of the manifest file.

This JAR file can then be copied to any computer with a Java runtime environment installed (the JDK version on the computer is not too low), and the player can double-click the icon to run his minesweeper mini-game.

6.8Playtest Results

6.9Game difficulty custom test

Game difficulty custom test case:

The expected results Minefields can be correctly initialized by selecting different difficulty levels
The input conditions Click Elementary, Intermediate, Advanced, and Custom respectively
The test results The system will automatically change the size of the minefield and the number of mines after clicking on different difficulty levels

 

The design of the minesweeper game sets the difficulty of the game as the initial difficulty, medium difficulty, high difficulty and custom difficulty. The size of the game interface and the total number of mines corresponding to the first three difficulties are different. The more difficult the number of mines is, the larger the size is, the more the players need to think more when minesweeper to complete the game. In addition to the fixed difficulty can also be customized, players need to input their own size and thunder number, the system according to the player’s requirements to produce new games, difficulty can be more flexible, so that players can be more satisfied.

Four difficulty options were tested, and it can be seen from the figure that the difficulty options function properly and can freely change the size and total number of mines.

7 Mine clearance testing

Minesweeper victory test case:

The expected results Once all mines are successfully marked, the game ends immediately and a pop-up prompts you for your name
The input conditions Mark all mines and dot the non-mine grid
The test results The game ends and a pop-up box is displayed asking for the player’s name

 

Mine-clearing failure test cases:

The expected results The game ends immediately after clicking on a box with thunder and a popup notifies the player that the game has failed
The input conditions Click on the grid with thunder
The test results The game ends correctly and a popup prompts the game to fail

The player can complete the game by left-clicking on a grid to open it and right-clicking to identify a mine. The game is won when all mines are marked and all other squares are dotted. The system will prompt the player to successfully complete the game task “you really good, please input your name, record list!” . Players can enter their name in the pop-up box, otherwise the default is anonymous, and then the system will save the player’s game record. When clicking on the minesweeper board, players can see their shortest game record.

 

As shown in Figure 6-7, the player can complete the game by left-clicking on a grid to open it and right-clicking to identify a mine. When playing minesweeper, the player accidentally clicks on a mined grid, the mine detonates, and all unmarked and marked ones detonate, ending the game. At this point, the system will automatically display all mines, which is convenient for the player to check whether the previous mark is correct or not, and can sum up the experience. The system displays the message “You lost, please keep trying!” , the player can click the restart button to restart the game and continue playing minesweeper, or can choose to end the game.

7.1Player game data display test

Best Performance Test Cases:

The expected results Clicking the “Best Score” button will display the player’s best game record
The input conditions Open the game’s minesweeper list and click the “Best score” button
The test results The game can display the player’s game record correctly

Re-score test case:

The expected results Clicking the “rescore” button clears the player’s past games
The input conditions Open the game’s minesweeper board and click the “rescore” button
The test results After clicking the button, the game record disappears, and then clicking the “best result” button will only display the default result

As shown in Figure 6-8 and Figure 6-9, the system prompts you to save the game record if you successfully sweep lightning during the game. You can check it out on the minesweeper list. However, the shortest minesweeper time is automatically displayed after the player has completed the game repeatedly, so the player can only see the fastest minesweeper when viewing the record.

As you can see from Figure 6-10, when the player clicks the “Re-score” button, the previous game record is erased and only the default data is displayed: 999 seconds and the name is anonymous.

7.2 Game data display area test

The timing area displays test cases:

The expected results The first time you click on a grid in a minefield, the timer starts, the timer stops at the end of the game, and the timer goes to zero when you restart the game
The input conditions Click any square in the minefield, then end the game, and click the “Restart” button
The test results When clicking any grid in the minefield, the timer starts, and the timer is normal. Then click on the grid with thunder to end the game and find the timer stopped. After clicking “Restart”, the timing area is reset to zero correctly

When clicking any grid in the minefield, the timing zone starts to time normally. When the game ends, the timer stops, and when you click “Restart”, the timer goes to zero.

Test case of mine number display area:

The expected results The number in the count area is reduced by 1 after the mines are marked. If the number of markers exceeds the number of mines, the count area is displayed as a negative number
The input conditions Mark one mine, then mark all the mines
The test results After marking a mine, the counter area is correctly reduced by 1, and after all mines are marked, the counter area is correctly represented as a negative number if the mark continues

When a mine is marked, the number in the counter is reduced by one, indicating that a mine has been found. However, if the number of markers exceeds the number of mines, the counting area is shown as a negative number, indicating that some mines are incorrectly marked

7.3 Recursive algorithm test

Recursive call test case:

The expected results When you click on a grid without any of the eight surrounding squares, the system will open those eight squares as well
The input conditions Click on a box with no lightning around it
The test results The system correctly opens the eight surrounding cells and automatically opens them if there are no surrounding cells

When you click on a grid that has no mines in its eight surrounding squares, the system will open the surrounding squares, which will also show the number of mines in the surrounding squares. If there are still no mines around the opened grid, the system will recursively call to open the surrounding grid.

The code of minesweeper game is completed, and the basic functions have been realized. Although there are still some gaps in the interface compared with the minesweeper game on the computer, and some small details have not been improved, I am very satisfied with it. I will continue to improve these details in the future, so that this minesweeper game becomes more and more fun. After a brief test, the game met my expectations, so that’s the end of the design.

”    论

Although the minesweeper game looks simple, it involves GUI design, which I need to learn by myself. There are various components of the call, the use of various controls and so on

Through writing this minesweeper game, I deeply realized the importance of details. These problems seem insignificant, but if ignored, they will form bad programming habits. Therefore, we should focus on details and be good at finding some small things around us, so as to constantly improve our level. And my programming ability has been significantly improved in the process of constantly writing code. Most of the time, people think that knowledge has been learned, but when they actually use it, they will find how strange the knowledge is. So I think the learned knowledge should be used, with practical operation to make the knowledge really become their own.