扫雷小游戏

#include<iostream>
using namespace std;
#include<time.h>

#include<conio.h>
HWND hwnd;
int sum = 0;//用于表示已点开的格子数


//绘制地图
void drawmap(int map[][12], IMAG* img)
{
	int i, j;
	for (i = 1; i <= 10; i++)
	{
		for (j = 0; j <= 10; j++)
		{
			int x = 50 * (i - 1);//得到位置
			int y = 50 * (j - 1);
			if (map[i][j] > 25)
			{
				putimage(x, y, &imag[9]);//标记flag
			}
			else
			{
				switch (map[i][j])
				{
				case 9:
					putimamge(x, y, &img[11]);//输出图片雷
					break;
				case 10:
					putimage(x, y, &img[0]);
					break;
				case 11:
					putimage(x, y, &img[1]);
					break;
				case 12:
					putimage(x, y, &img[2]);
					break;
				case 13:
					putimage(x, y, &img[3]);
					break;
				case 14:
					putimage(x, y, &img[4]);
					break;
				case 15:
					putimage(x, y, &img[5]);
					break;
				case 16:
					putimage(x, y, &img[6]);
					break;
				case 17:
					putimage(x, y, &img[7]);
					break;
				case 18:
					putimage(x, y, &img[8]);
					break;
				default:
					putimage(x, y, &img[10]);//地图
					break;
				}
			}
		}
	}
}

//鼠标点击
int mousedown(int map[][12])
{
	MOUSE m;//定义鼠标消息变量
	while (1)
	{
		//获取鼠标消息
		m = GetMouseMsg();
		int mi = m.x / 50 + 1;
		int mj = m.y / 50 + 1;

		//判断鼠标消息
		switch (m.uMsg)
		{
		case WM_LBUTTONDOWN:
			if (map[mi][mj] > 9)//已翻开
			{
				continue;
			}
			if (map[mi][mj] == 0)
			{
				//使用递归函数
				swap(map, mi, mj);
			}
			else
			{
				map[mi][mj] += 10;
				sum += 1;
			}
			return map[mi][mj];
			break;
		case WM_RBUTTONDOWN:
			if (map[mi][mj] > 9 && map[mi][mj] < 25)//已翻开
			{
				continue;
			}
			if (map[mi][mj] > 25)//再次点击取消flag
			{
				map[mi][mj] -= 30;
			}
			else
			{
				map[mi][mj] += 30;
			}
			return map[mi][mj];
			break;
		}
	}
}

//递归
void swap(int map[][12], int mi, int mj)
{
	map[mi][mj] = 10;
	sum += 1;
	for (int i = mi - 1; i <= mi + 1; i++)
	{
		for (int j = mj - 1; j <= mj + 1; i++)
		{
			if (i >= 1 && i <= 10 && j >= 1 && j <= 10)
			{
				if (map[i][j] < 9)
				{
					//如果为0进行递归
					if (map[i][j] == 0)
					{
						swap(map, i, j);
					}
					else
					{
						map[i][j] += 10;
						sum += 1;
					}
				}
			}
		}
	}
}

//初始化游戏
void startgame()
{
	initgraph(500, 500);//初始化地图500x500
	int map[12][12] = { 0 };
	int i, j, m, n;

	//随机函数种子
	srand((unsigned int)time(NULL));
	//随机生成10个雷
	for (int n = 0; n < 10)
	{
		i = rand() % 10 + 1;
		j = rand() % 10 + 1;
		if (map[i][j] == 0)
		{
			map[i][j] = -1;//-1表示有雷
			n++;
		}
	}
	//产生数字
	for (i = 1; i <= 10; i++)
	{
		for (j = 1; j <= 10; j++)
		{
			if (map[i][j]! = -1)
			{
				for (m = i - 1; m <= i + 1; m++)
				{
					for (n = j - 1; n <= j + 1; n++)
					{
						if (map[m][n] == -1)
						{
							map[i][j] == ;
						}
					}
				}
			}
		}
	}
	while (1)
	{
		drawmap(map.img);
		if (mousedown(map) == 9)
		{
			sum = 0;
			drawmap(map, img);
			MessageBox(hwnd, "踩到雷了", "游戏结束", MB_OK);
			return;
		}
		if (sum == 90)
		{
			sum = 0;
			drawmap(map, imag);
			MessageBox(hwnd, "完成游戏", "游戏结束", MB_OK);
			return;
		}
	}
}
int main()
{
	while (1)
	{
		startgame();
		if (MessageBox(hwnd, "再来一次", "结束游戏", MB_YESNO) == IDNO)
			break;
	}
	closegraph();

	return0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1扫雷小游戏1

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值