一不小心把它也开始连载了,最近又有考试,只能偶尔更新一下了
更新:选中的格子可以取消选中,程序结束时暂停,直到用户输入enter
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME)&0x8000)?true:false)
#define Esc 27
#define NC 14
#define BC 240
bool a[8][8]={false};
struct gqhs
{
void ycksbj();
void ycgb();
void ys(int n);
void ydgb(int x,int y);
bool pdgbwz(long x,long y,long w,long hi);
bool pdsbzt();
bool anniu(long x,long y,long w,long hi,const string world,int oldcolor,int newcolor);
};
void gqhs::ycksbj()
{
HANDLE hStdin=GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
GetConsoleMode(hStdin,&mode);
mode&=~ENABLE_QUICK_EDIT_MODE; //移除快速编辑模式
mode&=~ENABLE_INSERT_MODE; //移除插入模式
mode&=~ENABLE_MOUSE_INPUT;
SetConsoleMode(hStdin, mode);
return;
}
void gqhs::ycgb()
{
HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
GetConsoleCursorInfo(handle,&CursorInfo);//获取控制台光标信息
CursorInfo.bVisible=false; //隐藏控制台光标
SetConsoleCursorInfo(handle,&CursorInfo);//设置控制台光标状态
return;
}
void gqhs::ys(int n)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),n); //n代表的是第几号颜色 前面的GetStdHandle(STD_OUTPUT_HANDLE)是获取当前窗口权柄,简单来说就是让这个颜色加在这个页面
return;
}
void gqhs::ydgb(int x,int y) //光标移动到x,y
{
HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X=x;
pos.Y=y;
SetConsoleCursorPosition(handle,pos);
return;
}
bool gqhs::pdgbwz(long x,long y,long w,long hi)
{
HANDLE hOutput=GetStdHandle(STD_OUTPUT_HANDLE);
HWND h=GetForegroundWindow();
CONSOLE_FONT_INFO consoleCurrentFont;
POINT p;
GetCursorPos(&p);
ScreenToClient(h,&p);
GetCurrentConsoleFont(hOutput,FALSE,&consoleCurrentFont);
p.x/=consoleCurrentFont.dwFontSize.X;
p.y/=consoleCurrentFont.dwFontSize.Y;
return p.x>=x&&p.x<=x+w&&p.y>=y&&p.y<=y+hi;
}
bool gqhs::pdsbzt()
{
return KEY_DOWN(VK_LBUTTON);
}
bool gqhs::anniu(long x,long y,long w,long hi,const string world,int oldcolor,int newcolor)
{
bool pd=false;
if(pdgbwz(x,y,w,hi))
{
ydgb(x,y);
ys(newcolor);
cout<<world;
ys(oldcolor);
if(pdsbzt()&&pdgbwz(x,y,w,hi))
{
pd=true;
}
}
else
{
ydgb(x,y);
ys(oldcolor);
cout<<world;
}
return pd;
}
gqhs qumo;
bool hs(int x,int y)
{
qumo.ydgb(x,y);
qumo.ys(NC);
cout<<"■";
qumo.ys(BC);
return false;
}
int main()
{
qumo.ycgb();
qumo.ycksbj();
for(;;)
{
if(kbhit()!=0)
{
char x=getch();
if(x==Esc)
{
break;
}
}
for(int i=0;i<8;i++)
{
for(int j=0;j<8;j++)
{
if(!a[j][i]?qumo.anniu(i*2,j,1,0,"■",BC,NC):qumo.anniu(i*2,j,1,0,"■",NC,BC))
{
a[j][i]=!a[j][i];
Sleep(100);
}
}
}
}
qumo.ys(NC);
cout<<endl;
for(int i=0;i<8;i++)
{
int x=0;
for(int j=0;j<8;j++)
{
x=(x<<1)+int(a[i][j]);
}
printf("0x%02lx\n",x);
}
while(getchar()!=Esc);
}