[Open-Source project] Mine Clearance and open-source project mine clearance
I would like to express my gratitude to you for your reference to the project course provided by Mr. Wang Guilin.
Project address: https://github.com/xiaoxi666/mines_sweeperdescription:
1. Development Tool: Qt5.6.1
2. Development language: C ++
Technical points: 1. Data support:
1.1 because the data is globally unique, it is designed as a singleton mode. The default layout is also set here (the width is 20, the height is 15, and the number of mines is 50 ).
1.2 about brew: for the random algorithm, pay attention to the judgment boundary. if the location of the brew is determined (I use-1), 1 is added to the data in the eight directions around it;
1.3 about game settings:
1.3.1 The game supports configuring the width, height, and number of mines on its own. Two sets of data are used here. One is the configuration data field and the other is the basic data field. When we set the data field successfully, we need to transfer the field, delete the old scenario (the basic data domain is used at this time) and create a new scenario (then pass the configuration data to the basic data domain, and the basic data domain is updated ), set the view to the current scenario. Here, the data transmission is clever, so pay attention to it;
1.3.2 Data Validity Check using the QIntValidator class automatic check saves a lot of effort (my current limit width is 1 ~ 30, the height is 1 ~ 19. The number of mines cannot exceed half of the "width * height" value );
2. Graphic framework and rendering:
2.1 QGraphicsPixmapItem is responsible for generating each lattice element item;
2.2 Use lattice elements to generate Scene;
2.3 add Scene to the QGraphicsView;
2.4 note coordinate processing:
2.4.1 views and scene coordinates are automatically processed by the framework to ensure that the overall view is in the center;
2.4.2 search for the corresponding grid element with the mouse and use the itemAt function (note that the parameter of this function is int, so it cannot be too precise. This is also a reason for the overall screen size limit, another reason is visual aesthetics );
3. Automatic route search extension:
3.1 if there are no mines around the click grid and automatic scaling is required, two factors should be taken into account: one is the expansion of underlying data and the other is the expansion of views;
3.2 both use the queue idea to find out if there are no mines around the grid elements (underlying data) in eight directions. If so, add the elements to the queue. If not, open them; you need to add a flag to indicate whether it has been opened. If it has already been accessed, you do not need to add it to the queue;
3.3 based on the search direction of the basic data, synchronize the extension pointer coordinates (equivalent to automatic Mouse clicking), find the corresponding grid element, and then perform corresponding operations based on the underlying data; I originally wanted to directly obtain the grid elements around the current grid element, but I didn't find a method. Then I simulated the mouse to automatically expand it. Thank you for your advice;
3.4 Note that image scaling may occur here (although I have reduced the burden of image scaling in the end). During Scaling, you must consider the mouse pointer transformation synchronously, which must be of high precision (int is not acceptable, double can be used, but the double is not enough when the number of mines is too large (about 50*30), because the itemAt function parameter in the upper layer is int );
4. Handling of various tags:
4.1 As we know, the game has flag, question mark, and so on, so it needs to be processed separately; when the automatic seek extension does not consider the flag, but will consider the question mark, as long as you query its status and then corresponding processing;
5. Winning and losing:
It is better to lose 5.1 yuan in judgment. You only need to click on a mine to directly lose the sentence;
5.2 method of winning: two variables are used to represent the number of unopened grids and the number of currently marked mines. If the two variables are the same at a time point, the two variables are used to win; check the check every time you flip the grid (you do not need to enable multiple threads for global judgment );
6. Image Scaling:
6.1 The size of our grid elements should be adjusted automatically based on the screen size, but I haven't done this yet. The initial idea is that we can add window change events for processing. It is now maximized for the sake of beauty;
Project Establishment and packaging and publishing:Comparison with the traditional wndows clearance program:Attachment:
1. The source code can be downloaded from github (including windows programs ).
2. The windows execution program is provided by dynamically linking the library. The program itself only has 78 k, and the dll has a dozen MB. Be sure to verify the verification code.
MD5: 91A4699F89F275B14E9CB90D721409EE
SHA1: AA72FC1C154198CE36276741D96B9729D5BF8281
3. If you need to play on linux, recompile it;
Run several images:
Comments or improvements are welcome.