📄 crackwinminedlg.cpp
字号:
map[i][j]=k+1;
found=TRUE;
break;
}
}
if(!found)
{
c=::GetPixel(hDC,p.x+1,p.y);
if(c==color[6])
{
map[i][j]=7;
}
else
{
c=::GetPixel(hDC,p.x-7,p.y-7);
if(c==RGB(255,255,255))
{
}
else
{
map[i][j]=0;
}
}
}
}
}
}
void CCrackWinMineDlg::scanTheMap98()
{
//13 55 //left top corner
int i,j,k;
CPoint p;
COLORREF c;
BOOL found;
finish=TRUE;
hDC=::GetDC(NULL);
color[6]=RGB(128,0,128);
color[7]=RGB(0,0,0);
for(i=1;i<=width;++i)
{
for(j=1;j<=height;++j)
{
if(map[i][j]!=-1) continue;
finish=FALSE;
p.x=13+(i-1)*16+6;
p.y=56+(j-1)*16+6;
::ClientToScreen(hWnd,&p);
c=::GetPixel(hDC,p.x-1,p.y-1);
if(c==RGB(255,255,255))
{
//bomb
state=FAILURE;
return;
}
c=::GetPixel(hDC,p.x+1,p.y-1);
found=FALSE;
for(k=0;k<8;++k)
{
if(k==3 || k==6) continue;
if(c==color[k])
{
map[i][j]=k+1;
found=TRUE;
break;
}
}
if(!found)
{
c=::GetPixel(hDC,p.x+1,p.y);
if(c==color[3])
{
map[i][j]=4;
found=TRUE;
}
}
if(!found)
{
c=::GetPixel(hDC,p.x+1,p.y-4);
if(c==color[6])
{
map[i][j]=7;
}
else
{
c=::GetPixel(hDC,p.x-7,p.y-6);
if(c==RGB(255,255,255))
{
}
else
{
map[i][j]=0;
}
}
}
}
}
}
//普通决策
void CCrackWinMineDlg::makeDecision()
{
int i,j,k;
int blank,flag;
int x,y;
state=NOCHANGE;
for(i=1;i<=width;++i)
{
for(j=1;j<=height;++j)
{
if(map[i][j]<=0) continue;
count(i,j,&blank,&flag);
if((blank+flag)==map[i][j])
{
for(k=0;k<8;++k)
{
x=i+pos[k][0];
y=j+pos[k][1];
if(map[x][y]==-1)
{
x=13+(x-1)*16+7;
y=56+(y-1)*16+7;
::PostMessage(hWnd,WM_RBUTTONDOWN,MK_RBUTTON,MAKELPARAM (x,y));
map[i+pos[k][0]][j+pos[k][1]]=-2;
state=CHANGE;
}
}
}
if(flag==map[i][j] && blank>0)
{
x=13+(i-1)*16+7;
y=56+(j-1)*16+7;
::PostMessage(hWnd,WM_LBUTTONDOWN,MK_LBUTTON | MK_RBUTTON,MAKELPARAM (x,y));
::PostMessage(hWnd,WM_RBUTTONUP,0,MAKELPARAM (x,y));
state=CHANGE;
}
}
}
}
void CCrackWinMineDlg::count(int x,int y,int *blank, int *flag)
{
int i;
*blank=0;
*flag=0;
for(i=0;i<8;++i)
{
if(map[x+pos[i][0]][y+pos[i][1]]==-1) (*blank)++;
else if(map[x+pos[i][0]][y+pos[i][1]]==-2) (*flag)++;
}
}
void CCrackWinMineDlg::OnStopTime()
{
// TODO: Add your control notification handler code here
hWnd=::FindWindow(winMineClassName,NULL);
::KillTimer(hWnd,1);
KillTimer(1);
}
void CCrackWinMineDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
::PostMessage(hWnd,WM_TIMER,1,NULL);
CDialog::OnTimer(nIDEvent);
}
void CCrackWinMineDlg::getWinVer()
{
CString s;
dwVersion = GetVersion();
dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
dwWindowsMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));
// Get the build number for Windows NT/Windows 2000 or Win32s.
if (dwVersion < 0x80000000) // Windows NT/2000
dwBuild = (DWORD)(HIWORD(dwVersion));
else if (dwWindowsMajorVersion < 4) // Win32s
dwBuild = (DWORD)(HIWORD(dwVersion) & ~0x8000);
else // Windows 95/98 -- No build number
dwBuild = 0;
if(dwWindowsMajorVersion==5 && dwWindowsMinorVersion==2)
{
s.Format("Windows 2003 %d.%d.%d",dwWindowsMajorVersion,dwWindowsMinorVersion,dwBuild);
MessageBox(s,NULL,MB_OK | MB_ICONINFORMATION);
m_winver=s;
isInWin98=TRUE;
return;
}
if(dwWindowsMajorVersion==5 && dwWindowsMinorVersion==1)
{
s.Format("Windows XP %d.%d.%d",dwWindowsMajorVersion,dwWindowsMinorVersion,dwBuild);
MessageBox(s,NULL,MB_OK | MB_ICONINFORMATION);
m_winver=s;
isInWin98=FALSE;
return;
}
if(dwWindowsMajorVersion==5 && dwWindowsMinorVersion==0)
{
s.Format("Windows 2000 %d.%d.%d",dwWindowsMajorVersion,dwWindowsMinorVersion,dwBuild);
MessageBox(s,NULL,MB_OK | MB_ICONINFORMATION);
m_winver=s;
isInWin98=FALSE;
return;
}
if(dwWindowsMajorVersion==4 && dwWindowsMinorVersion==10)
{
s.Format("Windows 98 %d.%d.%d",dwWindowsMajorVersion,dwWindowsMinorVersion,dwBuild);
MessageBox(s,NULL,MB_OK | MB_ICONINFORMATION);
m_winver=s;
isInWin98=TRUE;
return;
}
s.Format("Unknow Windows %d.%d.%d",dwWindowsMajorVersion,dwWindowsMinorVersion,dwBuild);
MessageBox(s);
m_winver=s;
isInWin98=TRUE;
}
void CCrackWinMineDlg::getWinLan()
{
WORD lan=(WORD)::GetSystemDefaultLangID();
if(lan==0x0804)
{
MessageBox("监测到您的系统的语言是 简体中文版",NULL,MB_OK | MB_ICONINFORMATION);
m_exit.SetWindowText("退出");
m_start.SetWindowText("开始");
m_stoptime.SetWindowText("让时间停止");
m_timer.SetWindowText("时钟控制");
m_wait.SetWindowText("扫雷窗口刷新等待");
m_info.SetWindowText("系统信息");
m_about.SetWindowText("关于");
winMineClassName="扫雷";
failureMsg="对不起,失败了:(";
successMsg="恭喜:)";
hintMsg="对不起,没有找到扫雷窗口:( \n\n 您现在要运行扫雷吗?";
errMsg="运行扫雷程序时出错 :( \n\n请检查扫雷程序是否已安装";
iconicMsg="窗口正处于最小化状态。";
m_fast="快";
m_slow="慢";
m_sleeptime=30;
m_language="简体中文版";
m_ms="毫秒";
UpdateData(FALSE);
return;
}
if(lan==0x0409)
{
MessageBox("Detect your system language is English(USA)",NULL,MB_OK | MB_ICONINFORMATION);
m_exit.SetWindowText("Exit");
m_start.SetWindowText("Start");
m_stoptime.SetWindowText("StopTime");
m_timer.SetWindowText("Timer Control");
m_wait.SetWindowText("Refresh Wait");
m_info.SetWindowText("System Infomation");
m_about.SetWindowText("About");
winMineClassName="Minesweeper";
failureMsg="I'm so sorry to tell you , I fail :(";
successMsg="Congratulation :)";
hintMsg="Sorry , Can't find MineSweeper Window :( \n\n Do you want to run it at once ?";
errMsg="Encounter error while running MineSweeper :( \n\nPlease make sure MineSweeper has been installed";
iconicMsg="MineSweeper window is iconic";
m_fast="fast";
m_slow="slow";
m_sleeptime=30;
m_language="English(USA)";
m_ms="ms";
UpdateData(FALSE);
return;
}
CString s;
s.Format("Detect your system language Code is 0x%x",lan);
MessageBox(s);
}
void CCrackWinMineDlg::OnReleasedcaptureSliderSpeed(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int t;
t=m_speed.GetPos();
::KillTimer(hWnd,1);
SetTimer(1,t,NULL);
*pResult = 0;
}
//高级决策,做的不理想,屏蔽了:(
void CCrackWinMineDlg::advanceDecision()
{
int i,j,k;
int blank,flag;
int x,y;
int c;
int a[32][26];
needAdv=false;
Sleep(sleepTime);
if(isInWin98) scanTheMap98();
else scanTheMap();
for(i=0;i<32;i++)
for(j=0;j<26;j++)
a[i][j]=UNSPECIAL;
for(i=1;i<=width;++i)
{
for(j=1;j<=height;++j)
{
if(map[i][j]<=0) continue;
count(i,j,&blank,&flag);
if(blank!=2 || (map[i][j]-flag)!=1) continue;
for(k=0;k<8;++k)
{
x=i+pos[k][0];
y=j+pos[k][1];
if(map[x][y]==-1 && a[x][y]==UNSPECIAL)
{
a[x][y]=SEL1IN2;
}
}
}
}
for(i=1;i<=width;++i)
{
for(j=1;j<=height;++j)
{
if(map[i][j]<=0) continue;
count(i,j,&blank,&flag);
if(blank!=3) continue;
c=0;
for(k=0;k<8;++k)
{
x=i+pos[k][0];
y=j+pos[k][1];
if(a[x][y]==SEL1IN2) c++;
}
if(c==2 && (map[i][j]-flag)==2)
{
for(k=0;k<8;++k)
{
x=i+pos[k][0];
y=j+pos[k][1];
if(map[x][y]==-1 && a[x][y]==UNSPECIAL)
{
x=13+(x-1)*16+7;
y=56+(y-1)*16+7;
::PostMessage(hWnd,WM_RBUTTONDOWN,MK_RBUTTON,MAKELPARAM (x,y));
map[i+pos[k][0]][j+pos[k][1]]=-2;
needAdv=true;
}
}
}
else if(c==2 && (map[i][j]-flag)==1)
{
for(k=0;k<8;++k)
{
x=i+pos[k][0];
y=j+pos[k][1];
if(map[x][y]==-1 && a[x][y]==UNSPECIAL)
{
x=13+(x-1)*16+7;
y=56+(y-1)*16+7;
::PostMessage(hWnd,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM (x,y));
::PostMessage(hWnd,WM_LBUTTONUP,0,MAKELPARAM (x,y));
needAdv=true;
}
}
}
}
}
}
void CCrackWinMineDlg::OnAbout()
{
// TODO: Add your control notification handler code here
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -