当前位置:网站首页>C language to realize mine sweeping (simple version)
C language to realize mine sweeping (simple version)
2022-06-24 20:27:00 【AKA. Tong Yuan Zhi】
#define ROW 9
#define COL 9
#define ROWS 2 + ROW
#define COLS 2 + COL
#define shuliang 10
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<Windows.h>
void quyu(char mine[ROWS][COLS], int rows, int cols, char n)
{
int i = 0;
int j = 0;
for (i = 0; i < rows; i++)
{
for (j = 0; j < cols; j++)
{
mine[i][j] = n;
}
}
}
void xianshi(char show[ROWS][COLS], int row, int col)
{
int i = 0;
int j = 0;
for (i = 0; i <= col; i++)
{
printf("%d ", i);
}
printf("\n");
for (i = 1; i <= row; i++)
{
printf("%d ", i);
for (j = 1; j <= col; j++)
{
printf("%c ", show[i][j]);
}
printf("\n");
}
printf("\n");
}
void buzhi(char mine[ROWS][COLS], int row, int col)
{
int m = shuliang;
int x = 0;
int y = 0;
while (m)
{
x = rand() % row + 1;
y = rand() % row + 1;
if (mine[x][y] == '0')
{
mine[x][y] = '1';
m--;
}
}
}
int zhouweilei(char mine[ROWS][COLS], int x, int y)
{
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 - 1] +
mine[x + 1][y] +
mine[x + 1][y + 1] -
8 * '0';
}
void play(char mine[ROWS][COLS], char show[ROWS][COLS], int row, int col)
{
int x = 0;
int y = 0;
int win = 0;
while (win < row * col - shuliang)
{
printf(" Please enter the coordinates :");
scanf("%d %d", &x, &y);
if (x >= 1 && x <= row && y >= 1 && y <= col)
{
if (mine[x][y] == '1')
{
printf(" die \n");
xianshi(mine, ROW, COL);
printf(" Game over \n");
break;
}
else
{
int m = zhouweilei(mine, x, y);
show[x][y] = m + '0';
xianshi(show, ROW, COL);
}
}
else
{
printf(" Please re-enter \n");
continue;
}
win++;
}
if (win == row * col - shuliang)
{
printf(" Win. \n");
xianshi(mine, ROW, COL);
}
}
void meun()
{
Sleep(5000);
char a1[] = "******** 1. play *******";
char a2[] = "******** 0. exit *******";
char a3[] = "######## #######";
char a4[] = "######## #######";
int left1 = 0;
int right1 = strlen(a1) - 1;
int left2 = 0;
int right2 = strlen(a2) - 1;
while (left1 < right1 && left2 < right2)
{
a3[left1] = a1[left1];
a3[right1] = a1[right1];
a4[left2] = a2[left2];
a4[right2] = a2[right2];
printf("%s\n", a3);
printf("%s\n", a4);
left1++;
right1--;
left2++;
right2--;
Sleep(100);
system("cls");
}
printf("%s\n", a3);
printf("%s\n", a4);
}
void game()
{
char mine[ROWS][COLS] = { 0 };
char show[ROWS][COLS] = { 0 };
quyu(mine, ROWS, COLS, '0');
quyu(show, ROWS, COLS, '*');
buzhi(mine, ROW, COL);
xianshi(show, ROW, COL);
play(mine, show, ROW, COL);
}
void saolei()
{
int xuanze = 0;
srand((unsigned int)time(NULL));
do
{
meun();
printf(" Please enter :");
scanf("%d", &xuanze);
switch (xuanze)
{
case 1:
printf(" Start the game \n");
game();
break;
case 0:
printf(" Quit the game \n");
break;
default:
printf(" Input error \n");
break;
}
} while (xuanze);
}
int main()
{
saolei();
return 0;
}边栏推荐
- 苹果、微软、谷歌不再掐架,今年要合力干一件大事
- redis数据结构之压缩列表
- What is CNN (convolutional neural network)
- Anti epidemic through science and technology: white paper on network insight and practice of operators | cloud sharing library No.20 recommendation
- Win7 10 tips for installing Office2010 five solutions for installing MSXML components
- "Ningwang" was sold and bought at the same time, and Hillhouse capital has cashed in billions by "selling high and absorbing low"
- Bat learning notes
- Docker installing MySQL
- Dongyuhui is not enough to bring goods to "rescue" live broadcast
- UART communication (STM32F103 library function)
猜你喜欢

二叉树的基本性质与遍历

16 excellent business process management tools

Redis installation of CentOS system under Linux, adding, querying, deleting, and querying all keys

Making startup U disk -- Chinese cabbage U disk startup disk making tool V5.1

Methods for comparing float types in the kernel

Digital twin industry case: Digital Smart port

Test drive citus 11.0 beta (official blog)
![[go Language brossage] go from 0 to Getting started 4: Advanced use of slice, Primary Review and Map Getting started Learning](/img/3a/db240deb4c66b219ef86f40d4c7b7d.png)
[go Language brossage] go from 0 to Getting started 4: Advanced use of slice, Primary Review and Map Getting started Learning

The Network Security Review Office launched a network security review on HowNet, saying that it "has a large amount of important data and sensitive information"

Nodered has no return value after successfully inserting into the database (the request cannot be ended)
随机推荐
Audio and video 2020 2021 2022 basic operation and parameter setting graphic tutorial
You can capture fingerprints with a mobile camera?! Accuracy comparable to signature and monogram, expert: you are aggravating discrimination
Zadig + cave Iast: let safety dissolve in continuous delivery
The difference between the lazy man mode and the hungry man mode
顺序栈1.0版本
“拯救”直播带货,一个董宇辉还不够
Bytebase 加入阿裏雲 PolarDB 開源數據庫社區
Map跟object 的区别
Clustered index (clustered index), nonclustered index (nonclustered index)
C语言实现扫雷(简易版)
大一女生废话编程爆火!懂不懂编程的看完都拴Q了
Test drive citus 11.0 beta (official blog)
思源笔记工具栏中的按钮名称变成了 undefined,有人遇到过吗?
1、 Downloading and installing appium
What about the Golden Angel of thunder one? Golden Angel mission details
UART communication (STM32F103 library function)
What is showcase? What should showcase pay attention to?
The first public available pytorch version alphafold2 is reproduced, and Columbia University is open source openfold, with more than 1000 stars
Otaku can't save yuan universe
[video tutorial] functions that need to be turned off in win10 system. How to turn off the privacy option in win10 computer