Minesweeper game based on Qt (c++)

resource link

Game name : minessweeper

Use qt to realize visualization.

This program is inspired by the classic minesweeper game of windows system, and strives to restore the game experience. However, due to my limited programming level, there are still deficiencies.

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-2ZiCwPm9-1627265532774)(file:///C:/Users/ADMINI~1/AppData/Local/Temp /msohtmlclip1/01/clip_image002.jpg)]

The game area includes a minefield , a mine counter (located in the upper left corner, recording the number of remaining mines) and a timer (located in the upper right corner, recording the game time), and a certain number of mines are randomly arranged in a rectangular minefield of a determined size (99 for the primary level ) There are 10 mines in squares, 16 mines in 16 squares and 40 mines in intermediate level, 99 mines in 16*30 squares in advanced level, and you can set the size and number of minefields by yourself at the custom level). Players need to find out the minefields in the minefield as soon as possible. All squares that are not landmines are not allowed to step on landmines. The game setting defaults to primary.

The basic operations of the game include left-click , right-click , and left-click . Among them, the left button is used to open a safe grid and advance the game progress; the right button is used to mark mines to assist in judgment, or to prepare for the next double-click; Each open block is left-clicked:

Left-click : Press the left button on a block judged not to be mine to open the block. If a number appears on a block, the number represents the number of mines in the surrounding 3×3 area (usually 8 grids, 5 grids for side blocks, and 3 grids for corner blocks. So the largest number in minesweeper is 8); if the square is empty (equivalent to 0), you can recursively open the square adjacent to the empty; if unfortunately hit a mine, the game ends.

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-Te7KevYq-1627265532776)(file:///C:/Users/ADMINI~1/AppData/Local/Temp /msohtmlclip1/01/clip_image004.jpg)]

Right-click : Press the right button on the square judged as a mine to mark the mine (displayed as a small red flag). Repeat the operation once to mark the uncertain grid with question marks, and repeat the operation twice to cancel the marking.

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-7iGxwllW-1627265532778)(file:///C:/Users/ADMINI~1/AppData/Local/Temp /msohtmlclip1/01/clip_image006.jpg)]
[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-PQcEZp6n-1627265532781)(file:///C:/Users/ADMINI~1/AppData/Local/Temp /msohtmlclip1/01/clip_image008.jpg)]

Left-click double-click : When the number of marked lightning around the double-click position is equal to the number of the position, the operation is valid, which is equivalent to performing a left-click operation on all unopened squares around the number. Double-tapping does not work when the mine is not fully marked. If there are mismarked mines around the number, the game is over, and an "×" will be displayed on the mismarked mines

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-3WMY5CrH-1627265532784)(file:///C:/Users/ADMINI~1/AppData/Local/Temp /msohtmlclip1/01/clip_image010.jpg)]
[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-fOZBvpF4-1627265532785)(file:///C:/Users/ADMINI~1/AppData/Local/Temp /msohtmlclip1/01/clip_image012.jpg)]

**The game is successful:** When all the mines are found and marked with flags, and there are no mistakes in the game, the game ends, the timing is suspended, and it is [External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-m892UVcc-1627265532786)(file:///C:/Users/ADMINI~1/AppData/Local/Temp /msohtmlclip1/01/clip_image013.gif)]
displayed as[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-aPhPYh1m-1627265532787)(file:///C:/Users/ADMINI~1/AppData/Local/Temp /msohtmlclip1/01/clip_image014.gif)].

Game development process:

First of all, the mine was buried, the number of each grid was initialized, and the page was initialized.

Then realize the functions of left-clicking to expand the grid and start timing, displaying different numbers as different colors, and clicking the mine to end the game;

Later, the function of right-clicking to insert a flag and a question mark was realized, as well as the effect of inserting a flag and subtracting 1 from the number in the upper left corner.

Then implement the function of judging whether the game is successful or not. ( But the disadvantage is that success can only be confirmed after all mines are correctly marked and all grids are turned out)

Finally, the function of double-clicking the left button is realized.

Weaknesses : Success is only judged when all mines are flagged and there are no misjudgments. But in fact, in the original software, it is only necessary to find all the grids other than Lei, and there is no requirement as to whether the grid of Lei is marked or not.

And when the game is over, the icon switching will be a little slow, because it is judged every second, instead of changing the icon at the same time the game is over. Room for improvement.

Switching will be a little slow, because it is judged every second, instead of switching icons at the end of the game. Room for improvement.

Guess you like

Origin blog.csdn.net/jinniulema/article/details/119103776