In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use C++ code to achieve mine clearance Mini Game related knowledge, the content is detailed and easy to understand, simple and fast operation, has a certain reference value, I believe that everyone after reading this article on how to use C++ code to achieve mine clearance Mini Game will have a harvest, let's take a look.
Split into two source files and a header file
Note: this string of code is not complete and cannot be used to expand the surrounding coordinates directly when the number of mines around the checked coordinates is 0.
Header file: game.h
# include # define count 10 / / number of defined rows-ROW, column-COL#define ROW 9#define COL 9#define ROWS ROW+2 / / add more to facilitate code # define COLS COL+2// to initialize the chessboard, and all declared functions implement void InitBoard (char board [ROWS] [COLS], int rows,int cols) in game.c; / / print chessboard void DisplayBoard (char board [ROW] [COL], int row.int col) / / Mine void SetMine (char board [ROW] [COLS], int row,int col); / / Mine finding void FindMine (char mine [] [COLS], char show [] [COLS], int row,int col)
First source file: saolei.c
# include "game.h" / / what needs to be included and declared is completed in game.h void menu () {printf ("\ n"); printf ("1.play\ n"); printf ("0.exit\ n"); printf ("\ n");} void game () {/ / ROW and COL defines char mine [ROWS] [COLS] in game.h / / Mine-buried chessboard char show [ROWS] [COLS]; / / displayed chessboard / / initialize chessboard / / functions in game () are declared in game.h to implement InitBoard (mine,ROWS,COLS,'0') in game.c; / / 0 means mine-free, 1 means mine-free InitBOard (show,ROWS,COLS,'*'); / / print chessboard DisplayBoard (show,ROW,COL) / / Mine SetMine (mine,ROW,COL); / / Mine finding FindMine (mine,show,ROW,COL);} int main () {srand ((unsigned int) time (NULL)); / / generate random number int input = 0; do / / do-while cycle {menu (); / / (1--play 0--exit) is also the conditional printf of do-while cycle ("Please choose:") Scanf (% d, & input); switch (input) {case 1: printf ("start the game\ n"); game (); break; case 0: printf ("quit the game"); break; default: printf ("wrong choice, please re-enter"); break;}} while (input) return 0;}
Second source file: game.c
# include "game.h" void InitBoard (char board [ROWS] [COLS], int rows,int cols,char set) {int I = 0; int j = 0; for (I = 0 x I < rows;i++) {for (j = 0 x j < cols;j++) {board [I] [j] = set;} void DisplayBoard (char board [ROWS] [COLS], int row,int col) {int I = 0; int j = 0; for (I = 0 x I)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.