扫雷游戏(测试版)

目录

游戏介绍(废话)

玩法

代码


游戏介绍(废话)

扫雷是一款经典的计算机游戏,目标是在没有踩雷的情况下,揭露所有的方格。游戏开始时,玩家需要选择难度级别,并放置一定数量的地雷在一个网格中。玩家需要逐个揭开网格,并根据数字提示来确定周围的格子是否有地雷。如果玩家揭开的格子上有地雷,游戏结束。如果玩家揭开的格子上没有地雷,则显示数字表示周围的格子中有几个地雷,玩家可以根据数字来确定哪些格子是安全的。玩家需要细心思考,并使用逻辑推理来找到所有的安全方格,直到揭开了所有的安全方格或者找到了所有的地雷。

玩法

内有提示,这里就不多说了

代码

废话少说(敲黑板),上代码!

#include<bits/stdc++.h>
#include<windows.h>
#include<stdlib.h>
#include<stdio.h>
#include<wchar.h>
using namespace std;
int dir[8][2]={{-0,0},{0,0},{0,-0},{0,0},{-0,-0},{0,0},{-0,0},{0,-0}};
int main(){
	SetConsoleTitle("扫雷游戏(测试版)");
	system("color F4");
	int dls=0;
	cout<<"      加载中…\n";
	int temp=800;
	for(int i=0;i<=20;i++){
		cout<<"-";
		temp-=20;
		Sleep(temp);
	}
	cout<<"\n";
	Sleep(3000);
	system("cls");
	system("color 02");
	system("color B1");
	cout<<"欢迎来到扫雷游戏!\n"; 
	system("pause");
	system("cls");
	cout<<"游戏开始!";
	Sleep(1000);
	system("cls");
	while(1){
		char a[5][5]={'0'};
		int c[5][5]={0};
		bool t=0;
		for(int i=0;i<=5;i++){
		    int x=rand()%(4-0)+0;
			int y=rand()%(4-0)+0;
	    	if(a[x][y]!='*'){
	    		a[x][y]='*';
	    		dls++;
			}
	    	else i-=1;
		}
		dls--;
		int cx,cy;
		for(int i=0;i<5;i++){
			for(int j=0;j<5;j++){
				if(a[i][j]=='*')continue;
				int sum=0;
				for(int k=0;k<8;k++){
			    	int newi=i+dir[k][0];
				    int newj=j+dir[k][0];
				    if(a[newi][newj]=='*')sum++;
				}
				a[i][j]=sum+'0';
			}
		}
		for(int i=0;i<5;i++){
			for(int j=0;j<5;j++)cout<<"?";
			cout<<endl;
		}
		int ans=0;
		int bx,by;
		system("color 02");
		while(cout<<"点击一个坐标(x:0-4,y:0-4):"&&cin>>cx>>cy&&cout<<"标记一个坐标(如果标记的坐标越界,则默认为不标记):"&&cin>>bx>>by&&(dls>=1&&ans<20)){
			system("cls");
			c[cx][cy]=1;
			if(bx>4&&by>4){
				for(int i=0;i<5;i++){
					for(int j=0;j<5;j++){
						if(c[i][j]!=0)cout<<a[i][j];
						else cout<<"?";
					}
					cout<<endl;
				}
				continue;
			}
			if(c[bx][by]==2) cout<<"这个坐标您已经标记过了,所以本次标记无效\n";
			else if(a[bx][by]=='*'){
				dls--;
				cout<<"您标记的坐标是一个地雷!还剩"<<dls<<"个地雷。\n" ;
				c[bx][by]=2; 
			}
			else cout<<"很遗憾,您标记的坐标不是地雷\n"; 
			for(int i=0;i<5;i++){
				for(int j=0;j<5;j++){
					if(c[i][j]!=0)cout<<a[i][j];
					else cout<<"?";
				}
				cout<<endl;
			} 
			if(a[cx][cy]=='*'&&a[bx][by]!='*'){
				system("color 40");
				MessageBox(NULL,("Boom!Game over"),("Game over"),MB_YESNO);
				system("pause"); 
				system("color 8F");
				if(MessageBox(NULL,("是否继续游戏"),("Game over"),MB_YESNO | MB_ICONQUESTION) == IDYES)continue;
				else {
					MessageBox(NULL,("欢迎下次再玩!"),("Game over"),MB_OK);
					return 0;
				}
			}
			else ans+=2;
		}
		if(t)continue;
		system("color C4");
		MessageBox(NULL,("恭喜您取得了胜利!"),("Win"),MB_OK);
	    system("pause"); 
	    system("color 8F");
	    if(MessageBox(NULL,("是否继续游戏"),("Win"),MB_YESNO | MB_ICONQUESTION) == IDYES)continue;
		else {
			MessageBox(NULL,("欢迎下次再玩!"),("Win"),MB_OK);
			return 0;
		}
	}
	return 0;
} 
/*
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
作者版权©                拒绝盗版游戏
如有抄袭                 低于不良内容
后果自负                 支持正版!!
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*/

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值