当前位置:网站首页>Isn't there anyone who doesn't know how to write mine sweeping games in C language
Isn't there anyone who doesn't know how to write mine sweeping games in C language
2022-07-06 10:24:00 【East-sunrise】
Catalog
Two . Minesweeping game display and introduction
3、 ... and . Programming of mine sweeping game
1. Initial menu and general program structure
2.game( ) Implementation of function
2. Initialize minesweeping map
3. Mine sweeping function function implementation (game( ) The core of the function )
1. The basic framework of mine sweeping function code
2.“ Statistical thunder ” Function realization
3.“ Spread out a piece of ” Function realization
4.“ Mark ray ” Function realization
Four . The final code presentation
One . Preface
The Minesweeper game , Is a simple rule , Easy to use a puzzle game . No one has never played it ? In my last blog, I shared through C Language implementation of the three Gobang . Then whether the minesweeping game can also be passed by ourselves C language ? No, no, no, No , There should be no one who doesn't know how to use C Write a minesweeping game in language ?? I won't ! because , Next , I will teach you hand in hand to realize !
Two . Minesweeping game display and introduction
Here we first present our final results , Understand what we want to achieve , Only then can we have ideas to implement ️
- When we run the program, there will be a selection menu for players to choose to start the game or sign out
- After choosing to start the game, a thunder disk will be presented for players to play
- When the player enters the coordinates to start minesweeping , If you don't step on the thunder and around this coordinate 8 If there is thunder in the position , The coordinates checked by the player will show the information of the number of mines around
- If there is no thunder around the coordinates selected by the player , That will automatically expand a piece , Expand to the place with thunder around and stop .
- When the player determines which position is thunder , Then you can open “ Mark ” function , Mark the thunder .
- If you succeed in marking the positions of all mines , Then the game wins . If you step on a mine in the process of minesweeping , Then the game fails
Understand the minesweeping we will achieve , Is it roughly the same as the real minesweeping game !?
Then let's start our programming journey !!
3、 ... and . Programming of mine sweeping game
1. Initial menu and general program structure
- Every game will have its initial menu , Let players choose . Here we simply provide players with games or Exit both options ️
- And we want to make players finish one game at a time , You can continue and choose to continue or sign out , Then we should build a loop structure . And because the initial menu must be presented before the game starts , It means that it has been executed before the circular judgment ———> Then we will think that we should use do...while Loop structure ️
Code display :
void menu()
{
printf("************************\n");
printf("****** 1.play ******\n");
printf("****** 0.exit ******\n");
printf("************************\n");
}
int main()
{
int input = 0;
do
{
menu();
printf(" Please make a choice :");
scanf("%d", &input);
switch (input)
{
case 1:
game();
break;
case 0:
printf(" Quit the game \n");
break;
default:
printf(" Input error , Please reselect \n");
break;
}
} while (input);
return 0;
}
2.game( ) Implementation of function
1. Think and prepare
game Function encapsulates all the functions of the game , perform game Function is to start the game .
And what functions do we need to achieve as game developers ?
1. Present thunder disk
2. Arrange thunder
3.“ Spread out a piece of ” function
4. Check the thunder and mark the thunder
5. Win or lose judgment
️ Because we need to encapsulate many functions , So for the readability of the code , We can create one with .c For the suffix test.c Source file for storage main function ; Create a game.c The source file is used to store the implementation of various functions ; Create another one to .h For the suffix game.h Used to store the declarations of various functions
2. Initialize minesweeping map
- From the screenshot of the game above, we can see , This is a 9x9 Mine clearance map of . According to the knowledge we have learned, it is easy to think of , We should use a two-dimensional array to implement it .
- When initializing an array , We can define the elements by ourselves ️. In this case, I stipulate that it is a ‘*’ character , And I'm ready to use the array with which Lei is arranged : In characters ‘ 1 ’ For ray , Instead of Lei's position, use characters ‘ 0 ’
- And the two-dimensional array we used to arrange the thunder certainly can't be presented , That's tantamount to opening and hanging up ? And because when players are checking thunder , When marking thunder, the elements of the array will be changed , Then we can create two arrays . One is for arranging thunder , Store the location information of the mine ; Another one is presented for players to operate
- When we want to check the thunder, we need to count the number of thunder around , If the position to be counted is at the edge of the thunder disk , There will be an array cross-border access problem when counting the surrounding circle !️
So we have to judge the legitimacy of coordinates when making statistics , That's too much trouble . In order to prevent cross-border , You might as well add another line around the array , Then you won't cross the line when checking
In this case, both arrays will become 11 That's ok 11 Column
Code display :
void game()
{
char mine[ROWS][COLS] = { 0 };// Define an array of layout mines
char show[ROWS][COLS] = { 0 };// Define an array for players to operate
InitBoard(mine, ROWS, COLS, '0');// Initialize array
InitBoard(show, ROWS, COLS, '*');// Initialize array
}
// Traverse the array for initialization
InitBoard(char board[ROWS][COLS], int rows, int cols, char set)
{
int i = 0;
int j = 0;
for (i = 0; i < rows; i++)
{
for (j = 0; j < cols; j++)
{
board[i][j] = set;
}
}
}
️ What should be noted here is that , We don't define rows and columns directly with numbers , Instead, use variables . If we directly use numbers to define , Want to change the difficulty of the game later , Expand Lei pan ( Increase the number of rows and columns ), Then don't you want to change all the rows and columns of the whole program ? That kind of program coupling is too high , Poor expansion , Not a good code .
So we can game.h Macro definition of the number of rows and columns in the header file , Then use... In the two source files respectively #include"game.h" Statement contains this header file .
3. Print thunder disk
The operation of printing thunder disk needs to be executed many times in the process of the game , So I'm going to package a function :DisplayBoard(show, ROW, COL); Used to print thunder disk ( Print array )
🥲🥲 There is one saying. , Bloggers spent a lot of time writing this function ... In fact, the knowledge of printing two-dimensional arrays is not solid enough .
When we print , First think about what elements make up each row and column , When printing, you need to use circulation , And the cycle , As the name suggests, it is a thing we do repeatedly . So we should classify the content we want to print
In conclusion, it is : Try to catch some repeating elements , Then... As needed ( How many lines do you need ? How many columns are needed ?) To print circularly . For some special cycles , We will add judgment conditions to its cycle ( Or deal with it alone ).
Code display :
DisplayBoard(char board[ROWS][COLS], int row, int col)
{
int i = 0;
int j = 0;
printf("-------------- The Minesweeper game ---------------\n");
for (i = 0; i <= row; i++)
{
if (i == 0)
{
for (j = 0; j <= col; j++)
{
printf("| %d ", j);
}
printf("|\n");
for (j = 0; j <= col; j++)
{
printf("|---");
}
printf("|\n");
}
else
{
for (j = 0; j <= col; j++)
{
if (j == 0)
{
printf("| %d ", i);
}
else
{
printf("|");
printf(" %c ", board[i][j]);
}
}
printf("|\n");
if (i < col)
{
for (j = 0; j <= col; j++)
{
printf("|---");
}
printf("|\n");
}
}
}
printf("-------------- The Minesweeper game ---------------\n");
}
4. Arrange thunder
We are going to randomly arrange thunder in the thunder tray , So we need to generate random numbers ( I believe you guys are familiar with this operation )
We can also define the number of Lei like rows and columns
Code display :
SetMine(char board[ROWS][COLS], int row, int col)
{
int count = EASY_COUNT;
while (count)
{
int x = rand() % row + 1;
int y = rand() % col + 1;
// Judge
if (board[x][y] == '0')
{
board[x][y] = '1';
count--;
}
}
}
- count It represents the number of thunder , We can put this variable in while In the judgment condition of the cycle , Cleverly combined 0 For false , Not 0 For the truth ️ As long as a thunder is arranged count Just -1, When count Not yet 0 It means that Lei hasn't finished the layout , Then the loop continues
- in addition , When the code is written here, brothers, don't forget to be in main Function to generate random numbers srand((unsigned)time(NULL)); There is also a header file #include<stdlib.h>、#include<time.h>
3. Mine sweeping function function implementation (game( ) The core of the function )
if ,game( ) Function is the core of the minesweeping game code , Then the next minesweeping function is game( ) The core of the function !! The key is coming. !! On the blackboard !!
Similarly, we encapsulate the minesweeping function as a function FindMine(mine, show, ROW, COL);
- In fact, when the minesweeping function is executed , Is the beginning of player operation . What we wrote above is just some preparations for players to clear mines
- So what can players do ? That is, what functions do we need to realize in the minesweeping function ?
- When the player has not determined the location of thunder , Is the player just checking , After the investigation, we will further determine the location of the thunder according to the information of the thunder fed back by the game ?
- When the location of the mine is determined, it is necessary to mark . And does the player also need to judge whether to win or lose in each step of operation ?( Whether the player stepped on the thunder )
- So next , Let's chew on this hard bone !️
1. The basic framework of mine sweeping function code
When preparing to realize the minesweeping function , Because the process of minesweeping will perform many functions , There are also some problems we need to pay attention to . At first, I may feel a little confused about where to start .
Then we can simulate that we are about to clear mines , What to do (= What we need to achieve ), Then when we encounter the function we want to implement, we can first define it as a function , Build the basic framework of the code and then implement .
First of all, we see a thunder disk that has not been checked in every coordinate , Then we will enter a coordinate ( We may press the wrong coordinates ?—— Judge the legitimacy of coordinates ), When there is no thunder in a circle or even a larger range around the coordinate we choose to check , The thunder disk automatically changes the non thunder positions into spaces , Automatically expand to the position of thunder information and stop ——“ Spread out a piece of ” The function of spread( ) function . When the coordinates we checked were not thunder, but there was thunder around it , This position will become a number indicating the number of mines around —— The function of statistical thunder get_mine_count( ) function . When we infer Ray's information , It is confirmed that a certain coordinate is thunder , So we want to mark him —— Mark the function of thunder SignMin( ) function . When the positions we marked are all thunder and the thunder in the thunder disk is marked by us, the game wins —— The function of winning or losing judgment
When we have a general idea of the game process of minesweeping , You can create a basic code framework step by step , When you encounter the above functions that need to be implemented , It can be defined as a function first and then implemented .
Code display :
FindMine(char mine[ROWS][COLS], char show[ROWS][COLS], int row, int col)
{
int count = COUNT_M;
int x = 0;
int y = 0;
while (count)
{
printf(" Directly enter the coordinates to check \n");
printf(" Input 0 0 Then turn on the marking mine function ( Input again to close )\n");
printf(" Please enter the coordinates :-> ");
scanf("%d %d", &x, &y);
if (x > 0 && x <= ROW && y > 0 && y <= COL)
{
if (mine[x][y] == '1')
{
printf(" You're killed in the blast !\n");
break;
}
else if (show[x][y] == ' ')
{
printf(" This location has been checked , Please reselect \n");
}
else if (show[x][y] == '!')
{
printf(" This position is the Lei you marked , Please reselect \n");
}
else
{
if (get_mine_count( ) != 0)
{
int count = get_mine_count( );
show[x][y] = count + '0';
DisplayBoard(show, ROW, COL);
}
else
{
show[x][y] = ' ';
spread( );
DisplayBoard(show, ROW, COL);
}
}
}
// Turn on the marking function
else if (x == 0 && y == 0)
{
SignMin( );
if (count == 0)
break;
DisplayBoard(show, ROW, COL);
printf(" The number of remaining thunder :%d\n", count);
}
else
{
printf(" The coordinates entered are illegal , Please re-enter \n");
}
}
printf(" The number of remaining thunder :%d\n", count);
if (count == 0)
printf(" Mine clearance succeeded , Game wins !!\n");
return 1;
}
2.“ Statistical thunder ” Function realization
We know , During the minesweeping game , When players choose to check a coordinate , The game will make a circle around its coordinates 8 Check at two locations , Then count the number of mines around it and reflect its number . So we need to design a statistical mine function
Because the array contains characters , Want to count the number of mines around the coordinates , If one by one if It's too much trouble to judge
So we can think of , Because if it's not thunder, it's ‘0’, If it's ray, it's ‘1’, Then we can add up the eight coordinates around , subtracting 8*‘0’notes : character ‘0’ Of ASCII The code value is 48, character ‘1’ Of ASCII The value is 49
Finally, we will have a 3x3 Draw the array coordinates of , You can operate on the array
Code display :
int get_mine_count(char board[ROWS][COLS], int x, int y)
{
return(board[x - 1][y] + board[x - 1][y - 1] +
board[x][y - 1] + board[x + 1][y + 1] +
board[x + 1][y] + board[x + 1][y - 1] +
board[x - 1][y + 1] + board[x][y + 1] - 8 * '0');
}
Another explanation :
When we know 3x3 The value of each coordinate in the array , Since it can be added up one by one , So can we also use circulation ?
Suppose the coordinates we choose to check are x , y, When the pair includes this coordinate and its surrounding circle, there are 9 When traversing coordinates , It's actually an array ( Abscissa ) Subscript x-1,x,x+1, and ( Ordinate ) Subscript y-1,y,y+1 A total of two combinations 9 Traverse coordinates , Then we can solve this problem by using cycles ️
Code display :
int get_mine_count(char board[ROWS][COLS], int x, int y)
{
int sum = 0;
for (int i = -1; i <= 1; i++)
{
for (int j = -1;j <= 1; j++)
{
sum += (board[i][j] - '0');
return sum;
}
}
}
3.“ Spread out a piece of ” Function realization
Minesweeping game in order to avoid wasting players' time , I know that there is no thunder in that area , But we still need to go one by one , So there is one “ Spread out a piece of ” The function of . And how do we achieve it ? Then you should think about the preconditions for realizing .
️BUG And —— Dead recursion
We will think : Just choose a coordinate , Then this position is not ray ( Conditions 1), Then this position automatically becomes a space , There is no thunder around it ( Conditions 2), And if there is no thunder around the coordinates around the circle , Then all become spaces , In the end, it's like a serial explosion , Spread out a piece of ......—— At this point, you will think of “ Recursive function ” This sharp weapon ️
however !
️ When you want to implement it, you will find that you will finally fall into dead recursion ( It's like a dead cycle , There is no termination ) The reason is shown in the figure
We directly print out the array of arrangement mines , Simulate the recursive function idea we mentioned above
The condition that the expansion function can be executed is :1. This position is not thunder 2. There is no thunder around it
So let's assume that we choose to check the location of the red circle at the beginning , The red circle is not thunder , So judge the circle around the red circle . A circle around the red circle is not thunder's words , Let the coordinates around it recursively call the expansion function . Suppose the position of the green circle also calls the expansion function , Meet the conditions 1 And conditions 2 Then let the coordinates of a circle around the position of the green circle be called recursively , At this time, it will return to the red circle position ———— Fall into dead recursion
So to sum up , Implementing a recursive function that expands a piece requires 3 Conditions :1. This position is not thunder 2. There is no thunder around it 3. This coordinate has not been checked . Recursive functions must have a termination condition , This condition is : Expand to the surrounding circle of thunder coordinates and stop recursive calls
Code display :
spread(char mine[ROWS][COLS], char show[ROWS][COLS], int x, int y)
{
for (int i = x - 1; i <= x + 1; i++)
{
for (int j = y - 1; j <= y + 1; j++)
{
if ((i > 0) && (i <= ROW) && (j > 0) && (j <= COL))
{
if ((mine[i][j] == '0') && (show[i][j] != ' ') && (get_mine_count(mine, i, j) == 0))
{
show[i][j] = ' ';
spread(mine, show, i, j);
}
if (get_mine_count(mine, i, j) != 0)
{
int count = get_mine_count(mine, i, j);
show[i][j] = count + '0';
}
}
}
}
}
4.“ Mark ray ” Function realization
After the player has checked and confirmed the coordinates of Lei , Mark it
So we think : It is to wait for players to check and want to mark , To turn on the function of this marking mine . Then we need to design this function so that the player decides when to turn it on
In fact, it is not difficult to achieve . Just like our game initial menu , Players can choose to start the game or Quit the game , Then we can specify here that the marking function will be turned on after the player enters something , Input again to turn off the marking function
secondly , When we are marking ray , Because it's about whether the game wins , So we can design every time after the player marks , We present the remaining mine numbers .
Code display :
void SignMin(char mine[ROWS][COLS], char show[ROWS][COLS],int row,int col,int* win)
{
int x = 0;
int y = 0;
while (1)
{
printf(" Please enter the coordinates to be marked ( Input 0 0 Then exit the marking function ):-> ");
scanf("%d %d", &x, &y);
if ((x > 0 && x <= row) && (y > 0 && y <= col))
{
if (show[x][y] == '*')// It indicates that it has not been checked or marked
{
show[x][y] = '!';// The specified mark is ‘!’
if (mine[x][y] == '1')// Indicates that the mark is correct ( It's marked with thunder )
{
(* win)--;// It can't be *win-- ah
}
if (*win == 0)
return 1;
DisplayBoard(show, ROW, COL);
printf(" The number of remaining thunder :%d\n", *win);
}
else
{
if (show[x][y] == '!')// Provide players with the option of unmarking
{
show[x][y] = '*';
if (mine[x][y] == '1')
{
(*win)++;
}
DisplayBoard(show, ROW, COL);
printf(" The number of remaining thunder :%d\n", *win);
}
else
printf(" This coordinate has been scanned , No need to mark \n");
continue;
}
}
else
{
if (x == 0 && y == 0)// Exit the marking function
{
return 1;
}
printf(" Coordinates out of bounds , Please re mark \n");
continue;
}
}
}
Here from 2 Something to pay attention to :
We want the number of remaining mines to change after the execution of the marked mine function , The number of mines is a global variable , If we pass in function parameters directly ( Value passed ), After modifying it in the marking mine function , When the function ends , Its actual value will not change . So we need to use pointers here , The problem can be solved by passing function parameters as addresses ️
Another thing to watch out for , When increasing or decreasing the pointer in a function , Bloggers started by writing :*win++, But when it comes to execution bug. It's actually because of the pointer operator * Lower priority , If you follow the initial writing , Is the first address -1 And then dereference . So we can add brackets :(*win)++ Problem solvable ️
Four . The final code presentation
When we implement the expected functions one by one , Our programming journey is about to end. Here is the final code presentation , If there is something that can be optimized in any link, you are also welcome to make suggestions , Let's talk , Move forward together !
1.test.c Source code
#define _CRT_SECURE_NO_WARNINGS 1
#include"game.h"
void menu()
{
printf("************************\n");
printf("****** 1. play ******\n");
printf("****** 0. exit ******\n");
printf("************************\n");
}
void game()
{
char mine[ROWS][COLS] = { 0 };// Store the information of the arranged mine
char show[ROWS][COLS] = { 0 };// Store the information of the detected mine
// Initialize the contents of the array to the specified contents
//mine Arrays are all characters when there is no thunder 0
InitBoard(mine, ROWS, COLS,'0');
//show The array is always when there is no thunder check * It means mystery
InitBoard(show, ROWS, COLS,'*');
// Set ray
SetMine(mine, ROW, COL);
DisplayBoard(show, ROW, COL);// Printing only requires printing 9x9 that will do
// Check the thunder
FindMine(mine, show, ROW, COL);
}
int main()
{
int input = 0;
srand((unsigned)time(NULL));
do
{
menu();
printf(" Please select :");
scanf("%d", &input);
switch (input)
{
case 1:
game();
break;
case 0:
printf(" Quit the game !\n");
break;
default:
printf(" Wrong choice , Please reselect \n");
break;
}
} while (input);
return 0;
}
2.game.h Header file code
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define ROW 9
#define COL 9
#define ROWS ROW+2
#define COLS COL+2
#define COUNT_M 10
// Initialize thunder disk
InitBoard(char board[ROWS][COLS], int rows, int cols, char set);
// Set ray
SetMine(char board[ROWS][COLS],int row,int col);
// Print
DisplayBoard(char board[ROWS][COLS],int row,int col);
// Mine clearance
FindMine(char mine[ROWS][COLS],char show[ROWS][COLS],int row,int col);
3.game.c Source code
#define _CRT_SECURE_NO_WARNINGS 1
#include"game.h"
InitBoard(char board[ROWS][COLS], int rows, int cols, char set)
{
int i = 0;
int j = 0;
for (i = 0; i < rows; i++)
{
for (j = 0; j < cols; j++)
{
board[i][j] = set;
}
}
}
// Arrange thunder
SetMine(char board[ROWS][COLS], int row, int col)
{
int x = 0;
int y = 0;
int count = COUNT_M;// Macro defines the number of thunder
while (count)
{
x = rand() % row + 1;//x The scope is 0 — row
y = rand() % col + 1;
if (board[x][y] != '1')
{
board[x][y] = '1';
count--;
}
}
}
// Print thunder disk
DisplayBoard(char board[ROWS][COLS], int row, int col)
{
int i = 0;
int j = 0;
printf("-------------- The Minesweeper game ---------------\n");
for (i = 0; i <= row; i++)
{
if (i == 0)
{
for (j = 0; j <= col; j++)
{
printf("| %d ", j);
}
printf("|\n");
for (j = 0; j <= col; j++)
{
printf("|---");
}
printf("|\n");
}
else
{
for (j = 0; j <= col; j++)
{
if (j == 0)
{
printf("| %d ", i);
}
else
{
printf("|");
printf(" %c ", board[i][j]);
}
}
printf("|\n");
if (i < col)
{
for (j = 0; j <= col; j++)
{
printf("|---");
}
printf("|\n");
}
}
}
printf("-------------- The Minesweeper game ---------------\n");
}
// Statistical thunder
int get_mine_count(char board[ROWS][COLS],int x,int y)
{
int count = (board[x - 1][y - 1] + board[x - 1][y]
+ board[x - 1][y + 1] + board[x][y - 1]
+ board[x][y + 1] + board[x + 1][y - 1]
+ board[x + 1][y] + board[x + 1][y + 1]) - 8 * '0';
return count;
}
// Spread out a piece of
spread(char mine[ROWS][COLS], char show[ROWS][COLS], int x, int y)
{
for (int i = x - 1; i <= x + 1; i++)
{
for (int j = y - 1; j <= y + 1; j++)
{
if ((i > 0) && (i <= ROW) && (j > 0) && (j <= COL))
{
if ((mine[i][j] == '0') && (show[i][j] != ' ') && (get_mine_count(mine, i, j) == 0))
{
show[i][j] = ' ';
spread(mine, show, i, j);
}
if (get_mine_count(mine, i, j) != 0)
{
int count = get_mine_count(mine, i, j);
show[i][j] = count + '0';
}
}
}
}
}
// Mark ray
void SignMin(char mine[ROWS][COLS], char show[ROWS][COLS],int row,int col,int* win)
{
int x = 0;
int y = 0;
while (1)
{
printf(" Please enter the coordinates to be marked ( Input 0 0 Then exit the marking function ):-> ");
scanf("%d %d", &x, &y);
if ((x > 0 && x <= row) && (y > 0 && y <= col))
{
if (show[x][y] == '*')
{
show[x][y] = '!';
if (mine[x][y] == '1')
{
(* win)--;
}
if (*win == 0)
return 1;
DisplayBoard(show, ROW, COL);
printf(" The number of remaining thunder :%d\n", *win);
}
else
{
if (show[x][y] == '!')
{
show[x][y] = '*';
if (mine[x][y] == '1')
{
(*win)++;
}
DisplayBoard(show, ROW, COL);
printf(" The number of remaining thunder :%d\n", *win);
}
else
printf(" This coordinate has been scanned , No need to mark \n");
continue;
}
}
else
{
if (x == 0 && y == 0)// Exit the marking function
{
return 1;
}
printf(" Coordinates out of bounds , Please re mark \n");
continue;
}
}
}
// Check the thunder
FindMine(char mine[ROWS][COLS], char show[ROWS][COLS], int row, int col)
{
int win = COUNT_M;
int* p = &win;
int x = 0;
int y = 0;
while (win)
{
printf(" Directly enter the coordinates to check \n");
printf(" Input 0 0 Then turn on the marking mine function ( Input again to close )\n");
printf(" Please enter the coordinates :-> ");
scanf("%d %d", &x, &y);
if (x > 0 && x <= ROW && y > 0 && y <= COL)
{
if (mine[x][y] == '1')
{
printf(" You're killed in the blast !\n");
break;
}
else if (show[x][y] == ' ')
{
printf(" This location has been checked , Please reselect \n");
}
else if (show[x][y] == '!')
{
printf(" This position is the Lei you marked , Please reselect \n");
}
else
{
if (get_mine_count(mine, x, y) != 0)
{
int count = get_mine_count(mine, x, y);
show[x][y] = count + '0';
DisplayBoard(show, ROW, COL);
}
else
{
show[x][y] = ' ';
spread(mine, show, x, y);
DisplayBoard(show, ROW, COL);
}
}
}
// Turn on the marking function
else if (x == 0 && y == 0)
{
SignMin(mine,show,row, col, p);
if (win == 0)
break;
DisplayBoard(show, ROW, COL);
printf(" The number of remaining thunder :%d\n", win);
}
else
{
printf(" The coordinates entered are illegal , Please re-enter \n");
}
}
printf(" The number of remaining thunder :%d\n", win);
if(win == 0)
printf(" Mine clearance succeeded , Game wins !!\n");
return 1;
}
5、 ... and . summary
This minesweeping game programming , It's more difficult to program than the previous three piece chess game . We are required to master arrays 、 Functions and other knowledge , Recursion is also used 、 Knowledge of the pointer , And the logic of the whole code is more complex ️ So I think it's very worthwhile for us to study and practice . In the process of writing, we will inevitably encounter bug, But we should treat it with a good attitude bug, You can become stronger without experience , After we look for reasoning again and again bug The reason is , After we optimize the code again and again bug when , Even in the process of our becoming stronger, thank you for watching , If there is anything wrong in the text or Areas for improvement , Also welcome your suggestions , Let's talk , Move forward together !
It's not easy to code words ,️ Praise and pay attention to a wave !respct!
边栏推荐
- 保姆级手把手教你用C语言写三子棋
- 17 medical registration system_ [wechat Payment]
- Time complexity (see which sentence is executed the most times)
- MySQL storage engine
- MySQL combat optimization expert 07 production experience: how to conduct 360 degree dead angle pressure test on the database in the production environment?
- Use JUnit unit test & transaction usage
- Record the first JDBC
- C miscellaneous lecture continued
- Not registered via @EnableConfigurationProperties, marked(@ConfigurationProperties的使用)
- AI的路线和资源
猜你喜欢
17 medical registration system_ [wechat Payment]
保姆级手把手教你用C语言写三子棋
C miscellaneous two-way circular linked list
History of object recognition
Target detection -- yolov2 paper intensive reading
Jar runs with error no main manifest attribute
使用OVF Tool工具从Esxi 6.7中导出虚拟机
如何让shell脚本变成可执行文件
MySQL combat optimization expert 03 uses a data update process to preliminarily understand the architecture design of InnoDB storage engine
Redis集群方案应该怎么做?都有哪些方案?
随机推荐
颜值爆表,推荐两款JSON可视化工具,配合Swagger使用真香
13 医疗挂号系统_【 微信登录】
美疾控中心:美国李斯特菌疫情暴发与冰激凌产品有关
[programmers' English growth path] English learning serial one (verb general tense)
The governor of New Jersey signed seven bills to improve gun safety
Set shell script execution error to exit automatically
ByteTrack: Multi-Object Tracking by Associating Every Detection Box 论文阅读笔记()
In fact, the implementation of current limiting is not complicated
MySQL combat optimization expert 05 production experience: how to plan the database machine configuration in the real production environment?
宝塔的安装和flask项目部署
基于Pytorch的LSTM实战160万条评论情感分类
MySQL底层的逻辑架构
A necessary soft skill for Software Test Engineers: structured thinking
如何搭建接口自动化测试框架?
实现以form-data参数发送post请求
Super detailed steps for pushing wechat official account H5 messages
Security design verification of API interface: ticket, signature, timestamp
PyTorch RNN 实战案例_MNIST手写字体识别
Record the first JDBC
C杂讲 浅拷贝 与 深拷贝