当前位置:网站首页>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;
}边栏推荐
- What is showcase? What should showcase pay attention to?
- UART communication (STM32F103 library function)
- How does the video platform import the old database into the new database?
- 首个大众可用PyTorch版AlphaFold2复现,哥大开源OpenFold,star量破千
- Coinbase will launch the first encryption derivative for individual investors
- Bytebase 加入阿里云 PolarDB 开源数据库社区
- Coinbase将推出首个针对个人投资者的加密衍生产品
- gateway
- 物联网?快来看 Arduino 上云啦
- Redis installation of CentOS system under Linux, adding, querying, deleting, and querying all keys
猜你喜欢

Microsoft Office Excel 2013 2016 graphic tutorial on how to enable macro function

JMeter environment deployment

《梦华录》“超点”,鹅被骂冤吗?

Using dynamic time warping (DTW) to solve the similarity measurement of time series and the similarity identification analysis of pollution concentration in upstream and downstream rivers

Behind Tiantian Jianbao storm: tens of millions in arrears, APP shutdown, and the founder's premeditated plan to run away?

宅男救不了元宇宙

物聯網?快來看 Arduino 上雲啦

Application practice | massive data, second level analysis! Flink+doris build a real-time data warehouse scheme

Bytebase joins Alibaba cloud polardb open source database community

Teach you how to cancel computer hibernation
随机推荐
[R tidyverse] use of select verb
托管服务与SASE,纵享网络与安全融合 | 一期一会回顾
unity实战之lol技能释放范围
Compressed list of redis data structures
【CANN文档速递04期】揭秘昇腾CANN算子开发
Zadig + cave Iast: let safety dissolve in continuous delivery
RF_DC系统时钟设置GEN1/GEN2
RF_ DC system clock setting gen1/gen2
Bytebase加入阿里云PolarDB开源数据库社区
Introduction: continuously update the self-study version of the learning manual for junior test development engineers
Error in Android connection database query statement
Audio and video 2020 2021 2022 basic operation and parameter setting graphic tutorial
顺序表的基本操作
大一女生废话编程爆火!懂不懂编程的看完都拴Q了
Ribbon source code analysis @loadbalanced and loadbalancerclient
16 excellent business process management tools
How does the video platform import the old database into the new database?
Maps are grouped according to the values of the passed in parameters (similar to database groupby)
实现基于Socket自定义的redis简单客户端
Nodered has no return value after successfully inserting into the database (the request cannot be ended)