2018-6-18-鼠标操作已完成,代码在最下面
想着用鼠标操控来着,然而没弄明白鼠标事件,就先这样吧,有空了在弄
4个模式,简单,一般,困难,自定义= =
我玩一局简单的吧
<*-------------------------------------------------*>
<*---------------[Mine Clearance]------------------*>
<*-------------------------------------------------*>
<*------------------扫雷2.01版---------------------*>
<*-------------------------------------------------*>
<*-------------------[Simple]----------------------*>
<*-------------------[Common]----------------------*>
<*-------------------[Incubi]----------------------*>
<*-------------------[Custom]----------------------*>
<*---------------------------Made-by--revolIA------*>
<*-----------------------------------2018--06--16--*>
输入1---4
1
1 2 3 4 5 6 7 8 9 0
1 . . . . . . . . . .
2 . . . . . . . . . .
3 . . . . . . . . . .
4 . . . . . . . . . .
5 . . . . . . . . . .
6 . . . . . . . . . .
7 . . . . . . . . . .
8 . . . . . . . . . .
9 . . . . . . . . . .
0 . . . . . . . . . .
1 2 3 4 5 6 7 8 9 0
1
2 1 1
3 . 1
4 . 1 1 1 1
5 . . 1 1 . 1
6 . . 1 1 . . 1
7 1 1 . 1 1 1 . .
8 1 . 1 1 1 1
9 1 1 1
0
1 2 3 4 5 6 7 8 9 0
1
2 1 1
3 * 1
4 . 1 1 1 1
5 . . 1 1 * 1
6 . * 1 1 . . 1
7 1 1 . 1 1 1 * .
8 1 * 1 1 1 1
9 1 1 1
0
Game over!
Continue?1/0
死掉了= =,嘛大概就是这样子
#include <bits/stdc++.h>
#define ms(a) memset(a,0,sizeof(a))
using namespace std;
char a[233][233];
int b[233][233];
int boom,n,m;
struct point
{
int x,y;
}P;
void Selection();
void showMenu();
void format();
void Bfs(int,int);
int jude();
void Show();
void play();
int main()
{
showMenu();
while(1)
{
ms(a),ms(b);
Selection();
format();
play();
printf("Continue?1/0\n");
int tx;
scanf("%d",&tx);
if(!tx)
break;
system("cls");
}
return 0;
}
void Selection()
{
system("cls");
printf("<*-------------------------------------------------*>\n");
printf("<*---------------[Mine Clearance]------------------*>\n");
printf("<*-------------------------------------------------*>\n");
printf("<*------------------扫雷2.01版---------------------*>\n");
printf("<*-------------------------------------------------*>\n");
printf("<*-------------------[Simple]----------------------*>\n");
printf("<*-------------------[Common]----------------------*>\n");
printf("<*-------------------[Incubi]----------------------*>\n");
printf("<*-------------------[Custom]----------------------*>\n");
printf("<*---------------------------Made-by--revolIA------*>\n");
printf("<*-----------------------------------2018--06--16--*>\n");
printf("输入1---4\n");
int s;
scanf("%d",&s);
if(s==1)
n=m=10,boom=5;
else if(s<=3)
n=m=20,boom=50*(s-1);
else
printf("长?宽?雷?\n"),scanf("%d%d%d",&m,&n,&boom);
}
void showMenu()
{
printf("<*-------------------------------------------------*>\n");
printf("<*---------------[Mine Clearance]------------------*>\n");
printf("<*-------------------------------------------------*>\n");
printf("<*-------------------扫雷2.01版--------------------*>\n");
printf("<*-------------------------------------------------*>\n");
printf("<*-------------------[Start]-----------------------*>\n");
printf("<*-------------------------------------------------*>\n");
printf("<*------------[鼠标点击Start开始游戏]--------------*>\n");
printf("<*-------------------------------------------------*>\n");
printf("<*---------------------------Made-by--revolIA------*>\n");
printf("<*-----------------------------------2018--06--16--*>\n");
int s,e;
s=e=time(0);
while(e-s<2)e=time(0);
}
void format()
{
srand(time(0));
for(int i=0;i<boom;i++)
{
int tx=rand()%n+1;
int ty=rand()%m+1;
if(a[tx][ty]!='*')
a[tx][ty]='*';
else
i--;
}
int dir[8][2]={
1,1, 1,0, 1,-1,
0,1, 0,-1,
-1,1, -1,0, -1,-1
};
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
for(int k=0;k<8;k++)
{
int tx=i+dir[k][0];
int ty=j+dir[k][1];
if(tx>0 && ty>0 && tx<=n && ty<=m)
{
if(a[tx][ty]=='*')
b[i][j]++;
}
}
}
}
}
void Bfs(int x,int y)
{
int dir[4][2]={
1,0, 0,1, -1,0, 0,-1
};
queue<point> Q;
point t1,t2;
t1.x=x,t1.y=y;
Q.push(t1);
while(!Q.empty())
{
t2=Q.front();
Q.pop();
for(int i=0;i<4;i++)
{
t1.x=t2.x+dir[i][0];
t1.y=t2.y+dir[i][1];
if(t1.x>0 && t1.y>0 && t1.x<=n && t1.y<=m)
{
if(a[t1.x][t1.y]!='*'&&a[t1.x][t1.y]!='@')
{
a[t1.x][t1.y]='@';
if(!b[t1.x][t1.y])
Q.push(t1);
}
}
}
}
}
int jude()
{
int cnt=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(a[i][j]=='@')
cnt++;
if(cnt==n*m-boom)
return 1;
return 0;
}
void Show(int flag)
{
system("cls");
printf(" ");
for(int j=1;j<=m;j++)
printf("%3d",j%10);
printf("\n");
for(int i=1;i<=n;i++)
{
printf("%3d",i%10);
for(int j=1;j<=m;j++)
{
if(a[i][j]=='@')
{
printf(" %c",!b[i][j] ? ' ':'0'+b[i][j]);
}
else
{
if(flag && a[i][j]=='*')
printf(" *");
else
printf(" .");
}
}
printf("\n");
}
}
void play()
{
Show(0);
int x,y;
scanf("%d%d",&y,&x);
if(a[x][y]=='*')
{
Show(1);
printf("Game over!\n");
return;
}
if(a[x][y]!='@')
a[x][y]='@',Bfs(x,y);
if(jude())
Show(1),printf("You Win!\n");
else
play();
}
#include <bits/stdc++.h>
#include <windows.h>
#define ms(a) memset(a,0,sizeof(a))
using namespace std;
char a[233][233];
int b[233][233];
int boom,n,m,F;
struct point
{
int x,y;
}P;
void Selection();
void showMenu();
void format();
void Bfs(int,int);
int jude();
void Show(int);
void play(int,int);
int main()
{
Selection();
ms(a),ms(b);
format();
Show(0);
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO bInfo;
INPUT_RECORD mouseRec;
DWORD res;
COORD crPos, crHome = {0, 0};
while (1)
{
ReadConsoleInput(hIn, &mouseRec, 1, &res);
if (mouseRec.EventType == MOUSE_EVENT)
{
crPos = mouseRec.Event.MouseEvent.dwMousePosition;
GetConsoleScreenBufferInfo(hOut, &bInfo);
SetConsoleCursorPosition(hOut, crHome);
printf("[Cursor Position] X: %2lu Y: %2lu", (crPos.X+1)/3, crPos.Y);
SetConsoleCursorPosition(hOut, bInfo.dwCursorPosition);
if (mouseRec.Event.MouseEvent.dwButtonState==FROM_LEFT_1ST_BUTTON_PRESSED)
{
if((crPos.X+1)%3==0&&(crPos.X+1)/3>0&&(crPos.X+1)/3<=m && crPos.Y>0 && crPos.Y<=n)
{
play(crPos.Y,(crPos.X+1)/3);
COORD cos = { 0, 0 };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), cos);
Show(F);
if(F==1)
{
printf("Game over!\n");
break;
}
else if(F==2)
{
printf("You Win!\n");
break;
}
}
}
}
}
CloseHandle(hOut); // 关闭标准输出设备句柄
CloseHandle(hIn); // 关闭标准输入设备句柄
return 0;
}
void Selection()
{
printf("<*-------------------------------------------------*>\n");
printf("<*---------------[Mine Clearance]------------------*>\n");
printf("<*-------------------------------------------------*>\n");
printf("<*------------------扫雷2.01版---------------------*>\n");
printf("<*-------------------------------------------------*>\n");
printf("<*-------------------[Simple]----------------------*>\n");
printf("<*-------------------[Common]----------------------*>\n");
printf("<*-------------------[Incubi]----------------------*>\n");
printf("<*-------------------[Custom]----------------------*>\n");
printf("<*---------------------------Made-by--revolIA------*>\n");
printf("<*-----------------------------------2018--06--16--*>\n");
printf("输入1---4\n");
int s;
scanf("%d",&s);
if(s==1)
n=m=10,boom=5;
else if(s<=3)
n=m=20,boom=50*(s-1);
else
printf("长?宽?雷?\n"),scanf("%d%d%d",&m,&n,&boom);
}
void format()
{
srand(time(0));
for(int i=0;i<boom;i++)
{
int tx=rand()%n+1;
int ty=rand()%m+1;
if(a[tx][ty]!='*')
a[tx][ty]='*';
else
i--;
}
int dir[8][2]={
1,1, 1,0, 1,-1,
0,1, 0,-1,
-1,1, -1,0, -1,-1
};
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
for(int k=0;k<8;k++)
{
int tx=i+dir[k][0];
int ty=j+dir[k][1];
if(tx>0 && ty>0 && tx<=n && ty<=m)
{
if(a[tx][ty]=='*')
b[i][j]++;
}
}
}
}
}
void Bfs(int x,int y)
{
int dir[4][2]={
1,0, 0,1, -1,0, 0,-1
};
queue<point> Q;
point t1,t2;
t1.x=x,t1.y=y;
Q.push(t1);
while(!Q.empty())
{
t2=Q.front();
Q.pop();
for(int i=0;i<4;i++)
{
t1.x=t2.x+dir[i][0];
t1.y=t2.y+dir[i][1];
if(t1.x>0 && t1.y>0 && t1.x<=n && t1.y<=m)
{
if(a[t1.x][t1.y]!='*'&&a[t1.x][t1.y]!='@')
{
a[t1.x][t1.y]='@';
if(!b[t1.x][t1.y])
Q.push(t1);
}
}
}
}
}
int jude()
{
int cnt=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(a[i][j]=='@')
cnt++;
if(cnt==n*m-boom)
return 1;
return 0;
}
void Show(int flag)
{
COORD cos = { 0, 0 };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), cos);
for(int i=0;i<999;i++)printf(" ");
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), cos);
for(int j=1;j<=m;j++)
printf(" ");
printf("\n");
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(a[i][j]=='@')
{
printf(" %c",!b[i][j] ? ' ':'0'+b[i][j]);
}
else
{
if(flag && a[i][j]=='*')
printf(" *");
else
printf(" .");
}
}
printf("\n");
}
}
void play(int x,int y)
{
if(a[x][y]=='*')
{
F=1;
return;
}
if(a[x][y]!='@')
a[x][y]='@',Bfs(x,y);
if(jude())
F=2;
}