In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is to share with you the content of an example analysis of the implementation of minesweeping games in C language. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
One, create a menu
First make it clear what to do and choose the appropriate sentence to implement the idea:
Test.c void menu () {printf ("*\ n"); printf ("* 1.play *\ n"); printf ("* 0.exit * *\ n"); printf ("*\ n") } void test () {int input = 0; do {menu (); printf ("Please select:"); scanf ("% d", & input) Switch (input) {case 1: / / minesweeping break; case 0: printf ("quit the game\ n"); break Default: printf ("selection error\ n"); break;}} while (input);} int main () {test (); return 0;} II, create game content
Create a heavy blow in the game function. In the test () function, case1: call game.
Case 1 game / minesweeping (); 1. Scene creation and initialization
Here we have to understand that the mine in our game is arranged in advance, and the scene presented in front of us is masked, so we create two scenes, mine and show, both of which are two-dimensional arrays.
When minesweeping, we have to calculate whether there is a circle around the input coordinates, so we have to consider the problem of crossing the boundary in the boundary coordinates, so if the array shown in front of us is the array of xroomy, then the size of the actual array should be the size of (xroom2) * (yellow2).
To make it easy to change the size of the scene, we use the macro definition (in game.h) when creating rows and columns.
Game.h # include / / scene size for players # define ROW 9#define COL 9 / / scene true size anti-crossing limit # define ROWS ROW+2#define COLS COL+2 / / function declaration void initboard (char board [ROWS] [COLS], int rows, int cols, char set); / / initialize game.c / / function definition void initboard (char board [ROWS] [COLS], int rows, int cols, char set) / / initialize scene {int I = 0 Int j = 0; for (I = 0; I < rows; iTunes +) {for (j = 0; j < cols; jacks +) {board [I] [j] = set / / set receives characters from test.h} test.c void game () {/ / create array char mine [ROWS] [COLS] = {0}; / / char show [ROWS] [COLS] = {0} / / check mine / / initialize the mine array to full'0' initboard (mine,ROWS,COLS,'0'); / / initialize the show array to full'* 'initboard (show, ROWS,COLS,' *);} 2. Scene printing game.h # include / / scene size for players # define ROW 9#define COL 9 / / scene true size anti-crossing limit # define ROWS ROW+2#define COLS COL+2 / / function declaration void initboard (char board [ROWS] [COLS], int rows, int cols, char set); / / initialize void displayboard (char board [ROWS] [COLS], int row, int col) / / print scene game.c void displayboard (char board [ROWS] [COLS], int row, int col) / / print scene {int iTuno; int j = 0; for
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: 214
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.