Int get_mine_count (char mine, int x, int y) The function we use to count the number of thunder Void SetMine(char mine, int row, int col) Void DisplayBoard(char board, int row, int col)
#C++ simple minesweeper game code
The code for printing the thunder disk is as follows : #define _CRT_SECURE_NO_WARNINGS 1 Į: While printing the chessboard, in order to facilitate players to find coordinate points, We can be in 9*9 The edge of the thunder disk prints the numbers corresponding to its rows and columns. ĭ: We can put the That's ok Column Replace with a defined constant, So that the size of the thunder disk can be modified in the future. Ĭ: After storing the thunder, the player selects the coordinates, When the coordinate is thunder, The player blew up, Game over, When the coordinate is not mine, the surrounding mine inspection and statistics shall be carried out, It is a nine palace grid centered on the coordinates selected by the player to count the number of thunder, But when we choose the coordinates of the edge of the ninth grid, When we check the number of mines in the Jiugong grid centered on this coordinate, we will cross the boundary, Obviously, we can initialize two rows and columns as 11*11 My thunder disk, Set the overflow row to 9*9 The thunder disk part of the is set to “0” It can solve the overflow problem of the edge coordinate mine. ī : For the completion of the minesweeping game, We need to be in the line for 9*9 Mine is stored in the mine disk, That is, we can first convert all the mine disks storing mines into “0”, The time stamp is used to randomly mine the “0” Replace with "1", Thus, we can complete the random storage of mines. The effect diagram to be realized is as follows :( Definition :“0” For non ray “1” For ray )įirst of all, we need to clarify a few points :Ī: The Minesweeper game's minedisc contains two kinds of information, One is to store thunder or non thunder, The second is to store characters “ * ” To hide our mine information and conduct mine investigation at the same time, So we can create two chessboards, First, it is used to store the information of the arranged mine, Second, it is used to store the information of the checked mines, Then realize the separate processing of information.
![c++ simple minesweeper game c++ simple minesweeper game](https://jayeshkawli.ghost.io/content/images/2016/01/Minesweeper-Opening.png)
Printf(" Wrong choice, Please re-enter \n") Test.c The initial interface functions in are as follows : #define _CRT_SECURE_NO_WARNINGS 1
![c++ simple minesweeper game c++ simple minesweeper game](https://www.memory-improvement-tips.com/images/play-minesweeper-online.jpg)
With the value entered by the player 1 or 0 To determine the beginning or end of the game, Also consider player input 1 and 0 Other numbers, Print to remind players to re-enter 1 or 0 These two numbers, We can think of loop statements and switch Statement to realize repeatable minesweeping game and judgment of player selection. We need to create the start interface of mine sweeping game, We can first write a menu function.
![c++ simple minesweeper game c++ simple minesweeper game](https://i1.rgstatic.net/publication/228556627_Teaching_with_games_the_Minesweeper_and_Asteroids_experience/links/004635224ef899b3c7000000/largepreview.png)
c Implementation of game related functions
![c++ simple minesweeper game c++ simple minesweeper game](https://i.redd.it/g8z1v5fkbxe11.png)
h Declaration of game related functions, The symbol declares that the header file contains We can split the three piece chess into 3 A source file to make the overall look and feel of the code more concise and clear The second step : Initialize and print mine diskįor beginners, it is relatively difficult to write the complete code of minesweeping game, But the length of the code will be slightly shorter than that of the Sanzi game, At this point, we can divide it into various functions, and finally reference it to the main function to run the code, First of all, the overall idea should be established.