当前位置:网站首页>Minesweeping simple version
Minesweeping simple version
2022-07-29 03:14:00 【Wind rises and falls】
Preface
Code interpretation is in code
1.test.c
#include"game.h"
void menu()
{
printf("***********************\n");
printf("*******1.play 0.exit***\n");
printf("***********************\n");
}
void game()
{
char mine[rows][cols] = {
0 };
char slow[rows][cols] = {
0 };// initialization Two more lines Just to not cross the line
initboard(mine, row+2, col+2,'0');// Assuming that 9*9 My thunder disk become 11*11 To prevent the coordinates on the extreme edge from looking around 8 When there are two coordinates Transboundary
initboard(slow, row+2, col+2, '*');// initialization The thunder plate we want to see
displayboard(slow, row, col);// Print thunder disk
setmine(mine, col, row);// Arrange thunder
findmine(mine,slow, row, col);// Demining
}
int main()
{
srand((unsigned int)time(NULL));
int input = 0;
do
{
menu();
printf(" Input number :>");
scanf("%d", &input);
switch(input)
{
case 1:
game();
break;
case 0:
printf(" Quit the game \n");
break;
default:
printf(" Input error \n");
break;
}
} while (input);
return 0;
}
2.game.h
#define _CRT_SECURE_NO_WARNINGS
#define row 9
#define col 9
#define rows row+2
#define cols col+2
#define easycount 10
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void initboard(char board[rows][cols], int Rows, int Cols);
void displayboard(char board[row][col], int Row, int Col);
void setmine(char mine[row][col], int Row, int Col);
void findmine(char mine[row][col],char slow[row][col], int Row, int Col);
3.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; i < Rows; i++)
{
for (j = 0; j < Cols; j++)
{
board[i][j] = set;// mine Thunder plate is used to bury thunder Pass it on '0'
} //slow The thunder disk is used to check thunder Pass it on '*'
}
}
void displayboard(char board[row][col], int Row, int Col)// Print thunder disk
{
int i = 0;
int j = 0;// Actually see 9*9 My thunder disk So it's coming That's ok 9 Column 9
for (i = 1; i <= Row; i++)
{
for (j = 1; j <= Col; j++)
{
printf("%c ", board[i][j]);
}
printf("\n");
}
}
void setmine(char mine[row][col], int Row, int Col)// Arrange thunder
{
int count = 10;// Set the number of mines to 10
while (count)
{
int x = rand() % row + 1;// take x y The coordinates of are set to random numbers
int y = rand() % col + 1;
if (mine[x][y] == '0')
{
mine[x][y] = '1';
count--;
}
}
}
int nofind(char mine[row][col], int x, int y)// Look around the coordinates 8 Whether there is thunder in the coordinates
{
return (mine[x - 1][y - 1] + mine[x - 1][y] + mine[x - 1][y + 1] + + mine[x][y - 1] + mine[x][y + 1]
+ mine[x + 1][y] + mine[x + 1][y + 1] + mine[x + 1][y - 1]) - 8 * '0';
}// Because it's a character number So you need to subtract characters 0 Into a digital
void findmine(char mine[row][col], char slow[row][col],int Row, int Col)// Check the thunder
{
int x = 0;
int y = 0;
int count = 0;
int win = 0;
while (win<row*col-easycount)// Lei Panwei 9*9 -10 A thunder If not all of Ray's have been found And then jump out of the loop
{
printf(" Enter the coordinates of the mine to be checked :>");
scanf("%d%d", &x, &y);
int s1 = x;
int s2 = y;
if(x>=1&&y<=Row&&y>=1&&y<=Col)// The scope of thunder
{
if (mine[x][y] == '1')
{
printf(" Was blown up \n");
displayboard(mine, row, col);
break;
}
count = nofind(mine, x, y);
slow[x][y] = count+'0';// Send the number of whether there is thunder around to slow In the thunder disk
displayboard(slow, row, col); // Because it stores characters So convert to characters
win++;
}
else
{
printf(" Illegal coordinates \n");
}
}
if (win == row * col - easycount)//easycount To set the number of Mines
{
printf(" Mine clearance is successful \n");
displayboard(mine, row, col);// Print the distribution of thunder
}
}
边栏推荐
- 12_ UE4 advanced_ Change a more beautiful character model
- 2. Nodejs -- path (\dirname, \filname), URL URL, querystring module, mime module, various paths (relative paths), web page loading (interview questions *)
- Plato Farm在Elephant Swap上铸造的ePLATO是什么?为何具备高溢价?
- Chapter 2 VRP command line
- 01-SDRAM:初始化模块的代码
- Feedback function of conference OA
- 简历竟然敢写精通并发编程,那你说说AQS为什么要用双向链表?
- 西瓜书学习第六章---SVM
- Algorithm --- paint the house (kotlin)
- Shell编程规范与变量
猜你喜欢

微信为之疯狂的Glide使用——之生命周期学习

西瓜书学习第六章---SVM

Learn more than 4000 words, understand the problem of this pointing in JS, and handwrite to realize call, apply and bind

力扣刷题之数组序号计算(每日一题7/28)

基于单片机烟雾温湿度甲醛监测设计

STC单片机驱动1.8‘TFT SPI屏幕演示示例(含资料包)

13_ UE4 advanced_ Montage animation realizes attack while walking

简历竟然敢写精通并发编程,那你说说AQS为什么要用双向链表?

Unable to start after idea installation

力扣刷题之分数加减运算(每日一题7/27)
随机推荐
会议OA之反馈功能
Watermelon book learning Chapter 6 -- SVM
Redis之sentinel哨兵集群怎么部署
JVM基础入门篇一(内存结构)
MySQL installation and configuration super detailed tutorial and simple database and table building method
[robot learning] matlab kinematics and ADMAS dynamics analysis of manipulator gripper
01-SDRAM:初始化模块的代码
年内首个“三连跌” 95号汽油回归“8元时代“
HTB-Blue
[QNX hypervisor 2.2 user manual]9.11 RAM (under update)
[freeswitch development practice] media bug obtains call voice flow
13_ue4进阶_蒙太奇动画实现一边走一边攻击
力扣刷题之数组序号计算(每日一题7/28)
Verilog: blocking assignment and non blocking assignment
Several methods of converting object to string
西瓜书学习第六章---SVM
单例模式(饿汉式 懒汉式)
[NPM error] - NPM err code eresolve and NPM err eresolve could not resolve problems
A case of gradually analyzing the splitting of classes -- colorful ball collisions
C traps and defects Chapter 3 semantic "traps" 3.8 operators &, |, and!