C++小游戏(原创)——扫雷

 C++小游戏(原创)——扫雷_第1张图片

C++小游戏(原创)——扫雷_第2张图片

#include
#include
#include
#include
#include
#include
#include
#include
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)

using namespace std;
int maxn=16;
int maxm=30;
int square[100][100];
bool flag[100][100];
int move_x[8]={0,0,1,-1,1,1,-1,-1};
int move_y[8]={1,-1,0,0,1,-1,1,-1};
int xxx,yyy;
bool gameover=true; 
/*
用dfs鼠标点击的那个点,如果是数字,则直接翻开;如果是空格,则进行搜索。 
*/
void dfs(int x,int y){
	flag[x][y]=false;
	if(square[x][y]==-1) gameover=false;
	if(!gameover) return;
	if(square[x][y]!=0) return;
	for(int i=0;i<8;i++)
	{
		int now_x=move_x[i]+x;
		int now_y=move_y[i]+y;
		if(square[now_x][now_y]!=0){
			flag[now_x][now_y]=false;
		}
	}
	for(int i=0;i<4;i++)
	{
		int now_x=move_x[i]+x;
		int now_y=move_y[i]+y;
		if(flag[now_x][now_y]){
			flag[now_x][now_y]=false;
			dfs(now_x,now_y);
		}
	}
}
/*
数第x,y个格子,周围有多少个雷
*/ 
int count_num(int x,int y)
{
	int sum=0;
	for(int i=x-1;i<=x+1;i++)
		for(int j=y-1;j<=y+1;j++)
			if (square[i][j]==-1) sum++;
	return sum;
}

/*
将下面将要输出的东西改变颜色
*/ 
void SetColor(unsigned short ForeColor=7,unsigned short BackGroundColor=0)
{
	HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hCon,ForeColor|BackGroundColor);
}

/*
初始化,随机生成一个雷阵 
*/ 
void intt(){
	srand(time(NULL));
	for(int i=0;i>xxx>>yyy;
	}
}

/*
隐藏光标 
*/ 
void HideCursor()
{
	CONSOLE_CURSOR_INFO cursor_info = {1, 0}; 
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
int main(){
	system("color 0F");//设置背景颜色 
	system("mode con cols=60 lines=19");//设置黑框大小 
	HideCursor();
	intt();
	display();
	work();
	return 0;
} 

 

你可能感兴趣的:(c++小游戏)