只是一个游戏而已
好像把点赞数变成双数啊!!!
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
#define KEY_DOWN(VK_NONAME)((GetAsyncKeyState(VK_NONAME)&0x8000)?1:0)
#define n 11
#define m 11
int x,y;
char a[n+1][m+1]={' '};
bool t[n+1][m+1]={1},l[n+1][m+1]={1};
POINT p;
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
HWND h=GetForegroundWindow();
CONSOLE_FONT_INFO consoleCurrentFont;
void gotoxy(int x, int y)
{
COORD pos = {x,y};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut, pos);
}
void HideTheCursor()
{
CONSOLE_CURSOR_INFO cciCursor;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if(GetConsoleCursorInfo(hStdOut, &cciCursor))
{
cciCursor.bVisible = FALSE;
SetConsoleCursorInfo(hStdOut, &cciCursor);
}
}
void down()
{
int xx,yy;
again:
if(!KEY_DOWN(VK_RBUTTON)&&!KEY_DOWN(VK_LBUTTON))
{
Sleep(10);
goto again;
}
else if(KEY_DOWN(VK_LBUTTON))
{
POINT p;
GetCursorPos(&p);
ScreenToClient(h,&p);
GetCurrentConsoleFont(hOutput, FALSE, &consoleCurrentFont);
yy=p.x/consoleCurrentFont.dwFontSize.X+1;
xx=p.y/consoleCurrentFont.dwFontSize.Y+1;
Sleep(10);
}
else if(KEY_DOWN(VK_RBUTTON))
{
POINT p;
GetCursorPos(&p);
ScreenToClient(h,&p);
GetCurrentConsoleFont(hOutput, FALSE, &consoleCurrentFont);
yy=p.x/consoleCurrentFont.dwFontSize.X+1;
xx=p.y/consoleCurrentFont.dwFontSize.Y+1;
bb=1;
Sleep(10);
}
x=xx;
y=yy;
b=bb;
return;
}
void print()
{
int s=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(t[i][j])
{
cout<<"■";
s++;
}
else if(a[i][j]=='0')cout<<"0";
else if(a[i][j]=='1')cout<<"1";
else if(a[i][j]=='2')cout<<"2";
else if(a[i][j]=='3')cout<<"3";
else if(a[i][j]=='4')cout<<"4";
else if(a[i][j]=='5')cout<<"5";
else if(a[i][j]=='6')cout<<"6";
else if(a[i][j]=='7')cout<<"7";
else if(a[i][j]=='8')cout<<"8";
else if(a[i][j]=='9')cout<<"9";
else if(a[i][j]=='*')cout<<"◎";
else if(a[i][j]=='?')cout<<"?";
else if(a[i][j]==' ')cout<<" ";
}
cout<<endl;
}
cout<<"一一一一一一一一一一一\n◎:雷";
if(s==10)
{
system("cls");
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(a[i][j]=='1')cout<<"1";
else if(a[i][j]=='2')cout<<"2";
else if(a[i][j]=='3')cout<<"3";
else if(a[i][j]=='4')cout<<"4";
else if(a[i][j]=='5')cout<<"5";
else if(a[i][j]=='6')cout<<"6";
else if(a[i][j]=='7')cout<<"7";
else if(a[i][j]=='8')cout<<"8";
else if(a[i][j]=='9')cout<<"9";
else if(a[i][j]=='0')cout<<"0";
else if(a[i][j]=='*')cout<<"◎";
else if(a[i][j]=='?')cout<<"?";
else if(a[i][j]==' ')cout<<" ";
}
cout<<endl;
}
cout<<"一一一一一一一一一一一\n◎:雷";
Sleep(3000);
cout<<"you win!";
}
}
void q(int i,int j,bool l[n+1][m+1])
{
if(i==0||j==0||i==n+1||j==m+1||l[i][j]==1||a[i][j]=='*')return;
l[i][j]=1;
t[i][j]=0;
if(a[i][j]!=' ')return;
q(i+1,j,l);
q(i,j+1,l);
q(i-1,j,l);
q(i,j-1,l);
q(i+1,j+1,l);
q(i-1,j+1,l);
q(i-1,j-1,l);
q(i+1,j-1,l);
return;
}
int main()
{
HideTheCursor();
HANDLE hStdin=GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
GetConsoleMode(hStdin,&mode);
mode&=~ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(hStdin, mode);
SetConsoleTitle("扫雷");
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize=sizeof(cfi);
cfi.nFont=0;
cfi.dwFontSize.X=0;
cfi.dwFontSize.Y=24;
cfi.FontFamily=FF_DONTCARE;
cfi.FontWeight=FW_NORMAL;
std::wcscpy(cfi.FaceName,L"Consolas");
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE),FALSE,&cfi);
int i,j=0,k[n+1];
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
t[i][j]=true;
for(i=896;i<=100896;i+=10000)
{
srand(time(NULL)+i);
a[(rand()+i)%n+1][(rand()+i*2)%n+1]='*';
}
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(a[i][j]=='*')continue;
int s=0;
if(i==1&&j==1)
{
if(a[i+1][j]=='*')s++;
if(a[i][j+1]=='*')s++;
if(a[i+1][j+1]=='*')s++;
}
else if(i==1&&j==m)
{
if(a[i+1][j]=='*')s++;
if(a[i][j-1]=='*')s++;
if(a[i+1][j-1]=='*')s++;
}
else if(i==n&&j==1)
{
if(a[i][j+1]=='*')s++;
if(a[i-1][j]=='*')s++;
if(a[i][j-1]=='*')s++;
if(a[i-1][j-1]=='*')s++;
if(a[i-1][j+1]=='*')s++;
}
else if(i==n&&j==m)
{
if(a[i-1][j]=='*')s++;
if(a[i][j-1]=='*')s++;
if(a[i-1][j-1]=='*')s++;
}
else if(i==1)
{
if(a[i+1][j]=='*')s++;
if(a[i][j+1]=='*')s++;
if(a[i+1][j+1]=='*')s++;
if(a[i][j-1]=='*')s++;
if(a[i+1][j-1]=='*')s++;
}
else if(i==n)
{
if(a[i][j+1]=='*')s++;
if(a[i-1][j]=='*')s++;
if(a[i][j-1]=='*')s++;
if(a[i-1][j-1]=='*')s++;
if(a[i-1][j+1]=='*')s++;
}
else if(j==1)
{
if(a[i+1][j]=='*')s++;
if(a[i][j+1]=='*')s++;
if(a[i+1][j+1]=='*')s++;
if(a[i-1][j]=='*')s++;
if(a[i-1][j+1]=='*')s++;
}
else if(j==m)
{
if(a[i+1][j]=='*')s++;
if(a[i-1][j]=='*')s++;
if(a[i][j-1]=='*')s++;
if(a[i-1][j-1]=='*')s++;
if(a[i+1][j-1]=='*')s++;
}
else
{
if(a[i+1][j]=='*')s++;
if(a[i][j+1]=='*')s++;
if(a[i+1][j+1]=='*')s++;
if(a[i-1][j]=='*')s++;
if(a[i][j-1]=='*')s++;
if(a[i-1][j-1]=='*')s++;
if(a[i+1][j-1]=='*')s++;
if(a[i-1][j+1]=='*')s++;
}
if(s==0)a[i][j]=' ';
else a[i][j]=s+48;
}
}
system("color F0");
system("mode con cols=22 lines=15");
while(1)
{
system("cls");
print();
down();
if(a[x][(y+1)/2]=='*')
{
system("cls");
t[x][(y+1)/2]=0;
print();
Sleep(2000);
system("cls");
cout<<"BOOM!";
return 0;
}
if(a[x][(y+1)/2]==' ')
q(x,(y+1)/2,l);
t[x][(y+1)/2]=0;
Sleep(10);
}
return 0;
}