EasyX&C++实现扫雷小游戏

本文介绍如何使用EasyX库和C++编程实现扫雷小游戏,包括5X5、7X7、9X9三种难度,涉及游戏规则、操作说明及游戏胜利条件。同时,提供了背景音乐的下载链接和游戏的后续操作选项。
摘要由CSDN通过智能技术生成

规则:
1.鼠标左击选择(nXn)5X5,7X7,9X9方阵,分别含(m)5个,9个,15个地雷

2.鼠标左击灰色小方格,若为雷,显示红色,游戏失败,若非雷,显示绿色并显示方格附近八个方格中的非地雷方格,在方格中标注每个方格附近八个方格的地雷总数。鼠标右击灰色小方格,方格则被标记为地雷,显示红色,左侧地雷总数提示区,地雷数-1,若出现错误标记,则将等用户的地雷标记第m+1个时,自动展开全盘且游戏失败。

3.凡是已经展开或被红色标记的小方格再次点击无效

4.胜利:当所有地雷被右击选出,且无多选,错选,游戏获胜,记录最佳成绩,调整胜率(胜率=游戏获胜次数/总次数)。否则,判定游戏失败

5.每轮游戏结束展开所有方格,被错误标记为地雷的方格带"X"符号,正确标记地雷的方格带"V"符号,没被标记但含地雷的方格展开为红色,其余方格皆展开为绿色且标注周围八个方格地雷总数

6.鼠标左击
>Exit”,退出游戏,
>Back”,返回上一界面,
>Agin”,直接开始新一轮的该难度的游戏

7.游戏初始成绩和胜率皆为0

8.避免初次踩中雷功能(点击初次即踩中雷,方格会自动重新生成,耗时略长)


鼠标左键点击Play,进入游戏
在这里插入图片描述
以5X5难度为例(此难度含5个地雷),鼠标左键点击进入
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
鼠标左键点击"Exit"选择退出游戏
在这里插入图片描述
在这里插入图片描述
7X7,9X9难度情况(分别含9个,15个地雷)
在这里插入图片描述
在这里插入图片描述


背景音乐——>【点击获得】提取码:8fx2
(将音乐的MP3文件放入与.sln同个文件夹即可)


#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<string>
#include<cstring>
#include<time.h>
#include<stdlib.h>
#pragma comment(lib,"Winmm.lib")

using namespace std;
int sum[3] = {
    5,9,15 }, arr1[10][10] = {
    0 }, arr2[10][10] = {
    0 };
double times[3] = {
    0 }, time_win[3] = {
    0 }, PR_win[3] = {
    0 }, record[3] = {
    0 };
int Start(void)
{
   
	int choice = 0, i = 0;
	TCHAR s[] = _T("Minesweeper测"), s1[] = _T("> Play"), s2[] = _T("> Exit");
	initgraph(924, 724);
	setbkcolor(WHITE);
	settextstyle(70, 50, _T("Consolas"));
	settextcolor(BLACK);
	setbkmode(TRANSPARENT);
	cleardevice();
	outtextxy(152, 184, s);
	settextstyle(40, 20, _T("Consolas"));
	outtextxy(392, 384, s1);
	outtextxy(392, 452, s2);
	while (1)
	{
   
		MOUSEMSG M = GetMouseMsg();
		if (M.x >= 392 && M.x <= 512 && M.y >= 384 && M.y <= 424)
		{
   
			i = 1;
			settextcolor(RED);
			outtextxy(392, 384, s1);
			if (M.mkLButton)
			{
   
				choice = 1;
				break;
			}
		}
		else if (M.x >= 392 && M.x <= 512 && M.y >= 452 && M.y <= 492)
		{
   
			i = 1;
			settextcolor(RED);
			outtextxy(392, 452, s2);
			if (M.mkLButton)
			{
   
				choice = 2;
				break;
			}
		}
		else if(i)
		{
   
			settextcolor(BLACK);
			outtextxy(392, 384, s1);
			outtextxy(392, 452, s2);
			i = 0;
		}
	}
	return choice;
}

int Level(void)
{
   
	cleardevice();
	mciSendString(L"open .\\start.mp3 alias start", NULL, 0, NULL);
	mciSendString(L"play start repeat", NULL, 0, NULL);
	int n = 0, i = 0;
	TCHAR s1[] = _T("5X5"), s2[] = _T("7X7"), s3[] = _T("9X9"), s4[] = _T("< Back");
	setfillcolor(GREEN);
	setlinecolor(GREEN);
	settextcolor(WHITE);
	settextstyle(60, 60, _T("Consolas"));
	setbkmode(TRANSPARENT);
	fillrectangle(167, 62, 347, 262);
	outtextxy(172, 132, s1);
	fillrectangle(372, 62, 552, 262);
	outtextxy(377, 132, s2);
	fillrectangle(577, 62, 757, 262);
	outtextxy(582, 132, s3);
	settextcolor(BLACK);
	settextstyle(40, 20, _T("Consolas"));
	outtextxy(100, 524, s4);
	while (1)
	{
   
		MOUSEMSG M = GetMouseMsg();
		if (M.x >= 167 && M.x <= 347 && M.y >= 62 && M.y <= 262)
		{
   
			i = 1;
			settextcolor(WHITE);
			settextstyle(70, 70, _T("Consolas"));
			fillrectangle(157, 52, 357, 272);
			outtextxy(162, 122, s1);
			if (M.mkLButton)
			{
   
				n = 5;
				break;
			}
		}
		else if (M.x >= 372 && M.x <= 552 && M.y >= 62 && M.y <= 262)
		{
   
			i = 1;
			settextcolor(WHITE);
			settextstyle(70, 70, _T("Consolas"));
			fillrectangle(362, 52, 562, 272);
			outtextxy(367, 122, s2);
			if (M.mkLButton)
			{
   
				n = 7;
				break;
			}
		}
		else if (M.x >= 577 && M.x 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值