【扫雷简易版】

#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;
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值