#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//思路->
//1.打印菜单
//2.制作2个扫雷地图,初始化数组(11*11)
//3.11*11数组只打印show9*9(打印带上行列标识)
//4.放置雷、记录雷的次数进行--循环
//5.排查雷,count++统计周围一圈雷的个数、或者用字符特性统计
//6.统计的雷个数显示在show上
//7.判断胜利
//8.自动释放没有雷的区域a.该坐标不是雷 b.该坐标周围没有雷 c.该坐标没有被排查过
int num = 1;
void DisplayBoard(char arr[11][11])
{
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 9; j++)
{
printf("%c ", arr[i][j]);
}
printf("\n");
}
}
int main()
{
srand((unsigned int)time(NULL));
do
{
printf("**********************************\n");
printf("********* 1.play *********\n");
printf("********* 2.exit *********\n");
printf("**********************************\n");
int choose = 0;
scanf("%d", &choose);
switch (choose)
{
case 1:
printf(" 扫雷\n");
//初始化mine show棋盘
char mine[11][11];
for (int i = 0; i < 11; i++)
{
for (int j = 0; j < 11; j++)
{
mine[i][j] = '0';
}
}
char show[11][11];
for (int i = 0; i < 11; i++)
{
for (int j = 0; j < 11; j++)
{
show[i][j] = '*';
}
}
//打印show9*9棋盘
DisplayBoard(show);
//放置雷:10
int count = 10;
while (count)
{
int num1 = rand() % 9 + 1;
int num2 = rand() % 9 + 1;
if (mine[num1][num2] == '0')
{
mine[num1][num2] = '1';
}
count--;
}
DisplayBoard(mine);
printf("\n");
//排查雷 count1累加
int win = 0;
while (1)
{
int count1 = 0;
int x = 0;
int y = 0;
printf("请输入需要排查的坐标:>");
scanf("%d %d", &x,&y);
if (mine[x][y] == '1')
{
printf("排雷失败,此处是炸弹!\n");
DisplayBoard(mine);
break;
}
else
{
if (mine[x - 1][y - 1] == '1')
{
count1++;
}
if (mine[x - 1][y] == '1')
{
count1++;
}
if (mine[x - 1][y + 1] == '1')
{
count1++;
}
if (mine[x][y - 1] == '1')
{
count1++;
}
if (mine[x][y + 1] == '1')
{
count1++;
}
if (mine[x + 1][y - 1] == '1')
{
count1++;
}
if (mine[x + 1][y] == '1')
{
count1++;
}
if (mine[x + 1][y + 1] == '1')
{
count1++;
}
show[x][y] = count1 + '0';//统计的雷显示在show上
}
DisplayBoard(show);
//判断胜利
win++;
if (win == 71)
{
break;
}
}
break;
case 2:
printf("退出成功");
num = 0;
break;
default:
printf("输入有误,请重新输入指令->");
break;
}
} while (num);
return 0;
}
【扫雷简易版】
最新推荐文章于 2024-07-19 19:11:19 发布