📄 mine32dlg.cpp
字号:
RegSetValueEx(hKey, "Height", NULL, REG_DWORD, (BYTE*)&nHeight, 4);
RegSetValueEx(hKey, "Difficulty", NULL, REG_DWORD, (BYTE*)&nDifficulty, 4);
RegSetValueEx(hKey, "Mark", NULL, REG_DWORD, (BYTE*)&bMark, 4);
RegSetValueEx(hKey, "Mines", NULL, REG_DWORD, (BYTE*)&nMines, 4);
RegSetValueEx(hKey, "Time1", NULL, REG_DWORD, (BYTE*)&nTime[0], 4);
RegSetValueEx(hKey, "Time2", NULL, REG_DWORD, (BYTE*)&nTime[1], 4);
RegSetValueEx(hKey, "Time3", NULL, REG_DWORD, (BYTE*)&nTime[2], 4);
TCHAR* lpsz;
lpsz = strName[0].GetBufferSetLength(strName[0].GetLength());
RegSetValueEx(hKey, "Name1", NULL, REG_SZ, (BYTE*)lpsz, strName[0].GetLength()+1);
strName[0].ReleaseBuffer();
lpsz = strName[1].GetBufferSetLength(strName[1].GetLength());
RegSetValueEx(hKey, "Name2", NULL, REG_SZ, (BYTE*)lpsz, strName[1].GetLength()+1);
strName[1].ReleaseBuffer();
lpsz = strName[2].GetBufferSetLength(strName[2].GetLength());
RegSetValueEx(hKey, "Name3", NULL, REG_SZ, (BYTE*)lpsz, strName[2].GetLength()+1);
strName[2].ReleaseBuffer();
}
void CMine32Dlg::OnUpdateBeginner(CCmdUI* pCmdUI)
{
CMenu *menu = GetMenu();
menu->CheckMenuItem(IDM_BEGINNER, MF_CHECKED);
menu->CheckMenuItem(IDM_MIDDLE, MF_UNCHECKED);
menu->CheckMenuItem(IDM_EXPERT, MF_UNCHECKED);
menu->CheckMenuItem(IDM_CUSTOM, MF_UNCHECKED);
nDifficulty = 0;
nWidth = 8;
nHeight = 8;
nMines = 10;
OnBegin();
// TODO: Add your command update UI handler code here
}
void CMine32Dlg::OnUpdateMiddle(CCmdUI* pCmdUI)
{
CMenu *menu = GetMenu();
menu->CheckMenuItem(IDM_BEGINNER, MF_UNCHECKED);
menu->CheckMenuItem(IDM_MIDDLE, MF_CHECKED);
menu->CheckMenuItem(IDM_EXPERT, MF_UNCHECKED);
menu->CheckMenuItem(IDM_CUSTOM, MF_UNCHECKED);
nDifficulty = 1;
nWidth = 16;
nHeight = 16;
nMines = 40;
OnBegin();
}
void CMine32Dlg::OnUpdateExpert(CCmdUI* pCmdUI)
{
CMenu *menu = GetMenu();
menu->CheckMenuItem(IDM_BEGINNER, MF_UNCHECKED);
menu->CheckMenuItem(IDM_MIDDLE, MF_UNCHECKED);
menu->CheckMenuItem(IDM_EXPERT, MF_CHECKED);
menu->CheckMenuItem(IDM_CUSTOM, MF_UNCHECKED);
nDifficulty = 2;
nWidth = 30;
nHeight = 16;
nMines = 99;
OnBegin();
}
void CMine32Dlg::OnUpdateCustom(CCmdUI* pCmdUI)
{
CMenu *menu = GetMenu();
menu->CheckMenuItem(IDM_BEGINNER, MF_UNCHECKED);
menu->CheckMenuItem(IDM_MIDDLE, MF_UNCHECKED);
menu->CheckMenuItem(IDM_EXPERT, MF_UNCHECKED);
menu->CheckMenuItem(IDM_CUSTOM, MF_CHECKED);
CCustomDlg CustomDlg;
CustomDlg.DoModal();
nDifficulty = 3;
OnBegin();
}
void CMine32Dlg::OnUpdateMark(CCmdUI* pCmdUI)
{
CMenu *menu = GetMenu();
if (menu->GetMenuState(IDM_MARK, MF_BYCOMMAND) == MF_UNCHECKED)
bMark = FALSE;
else
bMark = TRUE;
}
void CMine32Dlg::DrawMines()
{
int s[3];
if (nMines >= 0)
s[2] = 253 - 23 * ((nMines / 100) % 10);
else
s[2] = 0;
s[0] = 253 - 23 * (abs(nMines) % 10);
s[1] = 253 - 23 * ((abs(nMines) / 10) % 10);
MemDC.BitBlt(m_Mines.left + 26, m_Mines.top, 13, 23, &NumsDC, 0, s[0], SRCCOPY);
MemDC.BitBlt(m_Mines.left + 13, m_Mines.top, 13, 23, &NumsDC, 0, s[1], SRCCOPY);
MemDC.BitBlt(m_Mines.left, m_Mines.top, 13, 23, &NumsDC, 0, s[2], SRCCOPY);
}
void CMine32Dlg::IniData()
{
nWidth = nWidth < 8 ? 8 : nWidth;
nWidth = nWidth > 30 ? 30 : nWidth;
nHeight = nHeight < 8 ? 8 : nHeight;
nHeight = nHeight > 16 ? 16 : nHeight;
nTotalMines = nMines = nMines < 10 ? 10 : nMines;
nTotalMines = nMines = nMines > 99 ? 99 : nMines;
nDifficulty = nDifficulty < 0 ? 0 : nDifficulty;
nDifficulty = nDifficulty > 3 ? 3 : nDifficulty;
CMenu *menu = GetMenu();
menu->CheckMenuItem(IDM_BEGINNER, MF_UNCHECKED);
menu->CheckMenuItem(IDM_MIDDLE, MF_UNCHECKED);
menu->CheckMenuItem(IDM_EXPERT, MF_UNCHECKED);
menu->CheckMenuItem(IDM_CUSTOM, MF_CHECKED);
if (nDifficulty == 0)
{
nWidth = 8;
nHeight = 8;
nTotalMines = nMines = 10;
menu->CheckMenuItem(IDM_BEGINNER, MF_CHECKED);
menu->CheckMenuItem(IDM_CUSTOM, MF_UNCHECKED);
}
if (nDifficulty == 1)
{
nWidth = 16;
nHeight = 16;
nTotalMines = nMines = 40;
menu->CheckMenuItem(IDM_MIDDLE, MF_CHECKED);
menu->CheckMenuItem(IDM_CUSTOM, MF_UNCHECKED);
}
if (nDifficulty == 2)
{
nWidth = 30;
nHeight = 16;
nTotalMines = nMines = 99;
menu->CheckMenuItem(IDM_EXPERT, MF_CHECKED);
menu->CheckMenuItem(IDM_CUSTOM, MF_UNCHECKED);
}
if (nDifficulty == 3 && nWidth == 8 && nHeight == 8)
nTotalMines = nMines = nMines > 49 ? 49 : nMines;
m_Ground.SetRect(XPos, YPos, XPos + (nWidth << 4), YPos + (nHeight << 4));
m_BeginButton.SetRect(XPos + (nWidth << 3) - 12, 16, XPos + (nWidth << 3) + 12, 40);
m_Mines.SetRect(17, 16, 56, 39);
m_Time.SetRect(m_Ground.right - 45, 16, m_Ground.right - 6, 39);
SetWindowPos(NULL, 0, 0, m_Ground.Width() + 32, m_Ground.Height() + 111, SWP_NOZORDER | SWP_NOMOVE);
}
void CMine32Dlg::Sweep(int x, int y)
{
int i, nCount = 0;
for (i = 0; i < 8; i ++)
nCount += GetBit(x + x0[i] + 1, y + y0[i] + 1);
MemDC.BitBlt(XPos + (x << 4), YPos + (y << 4), 16, 16, &IconsDC, 0, 240-nCount*16, SRCCOPY);
SetLClicked(x + 1, y + 1);
}
void CMine32Dlg::Flag(int x, int y)
{
if (GetRClicked(x + 1, y + 1))
{
MemDC.BitBlt(XPos + (x << 4), YPos + (y<< 4), 16, 16, &IconsDC, 0, 0, SRCCOPY);
SetR0Clicked(x + 1, y + 1);
nMines ++;
}
else
{
MemDC.BitBlt(XPos + (x << 4), YPos + (y<< 4), 16, 16, &IconsDC, 0, 16, SRCCOPY);
SetR1Clicked(x + 1, y + 1);
nMines --;
}
}
void CMine32Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
if (nFlags & MK_RBUTTON)
{
OnMButtonDown(nFlags, point);
return;
}
CClientDC dc(this);
if (m_BeginButton.PtInRect(point))
{
dc.BitBlt(m_BeginButton.left, m_BeginButton.top, 24, 24, &FacesDC, 0, 0, SRCCOPY);
MemDC.BitBlt(m_BeginButton.left, m_BeginButton.top, 24, 24, &FacesDC, 0, 0, SRCCOPY);
}
if (bBomb | bWin)
return;
if (!m_Ground.PtInRect(point))
return;
dc.BitBlt(m_BeginButton.left, m_BeginButton.top, 24, 24, &FacesDC, 0, 72, SRCCOPY);
MemDC.BitBlt(m_BeginButton.left, m_BeginButton.top, 24, 24, &FacesDC, 0, 72, SRCCOPY);
int x, y;
x = (point.x - XPos) >> 4;
y = (point.y - YPos) >> 4;
if (GetLClicked(x + 1, y + 1) || GetRClicked(x + 1, y + 1))
return;
dc.BitBlt(XPos + (x << 4), YPos + (y << 4), 16, 16, &IconsDC, 0, 240, SRCCOPY);
m_LastPoint.x = x;
m_LastPoint.y = y;
InvalidateRect(&m_Ground, FALSE);
CDialog::OnLButtonDown(nFlags, point);
}
void CMine32Dlg::OnLButtonUp(UINT nFlags, CPoint point)
{
if (nFlags & MK_RBUTTON)
{
OnMButtonUp(nFlags, point);
return;
}
int i, nCount = 0;
if (m_BeginButton.PtInRect(point))
{
OnBegin();
return;
}
if (bBomb | bWin)
return;
if (!bTime)
{
SetTimer(1, 1000, NULL);
bTime = TRUE;
}
CClientDC dc(this);
dc.BitBlt(m_BeginButton.left, m_BeginButton.top, 24, 24, &FacesDC, 0, 96, SRCCOPY);
MemDC.BitBlt(m_BeginButton.left, m_BeginButton.top, 24, 24, &FacesDC, 0, 96, SRCCOPY);
if (!m_Ground.PtInRect(point))
return;
int x, y;
x = (point.x - XPos) >> 4;
y = (point.y - YPos) >> 4;
if (GetLClicked(x + 1, y + 1) || GetRClicked(x + 1, y + 1))
return;
if (GetBit(x + 1, y + 1) == 1)
{
bBomb = TRUE;
dc.BitBlt(m_BeginButton.left, m_BeginButton.top, 24, 24, &FacesDC, 0, 48, SRCCOPY);
MemDC.BitBlt(m_BeginButton.left, m_BeginButton.top, 24, 24, &FacesDC, 0, 48, SRCCOPY);
MemDC.BitBlt(XPos + (x << 4), YPos + (y << 4), 16, 16, &IconsDC, 0, 48, SRCCOPY);
KillTimer(1);
bTime = FALSE;
}
else
{
//Sweep(x, y);
for (i = 0; i < 8; i ++)
nCount += GetBit(x + x0[i] + 1, y + y0[i] + 1);
CClientDC dc(this);
MemDC.BitBlt(XPos + (x << 4), YPos + (y << 4), 16, 16, &IconsDC, 0, 240 - (nCount << 4), SRCCOPY);
SetLClicked(x + 1, y + 1);
nClicked ++;
if (nClicked == nWidth * nHeight - nTotalMines)
{
dc.BitBlt(m_BeginButton.left, m_BeginButton.top, 24, 24, &FacesDC, 0, 24, SRCCOPY);
MemDC.BitBlt(m_BeginButton.left, m_BeginButton.top, 24, 24, &FacesDC, 0, 24, SRCCOPY);
int j;
CPoint pt;
for (i = 0; i < nWidth; i ++)
for (j = 0; j < nHeight; j ++)
if (!(GetLClicked(i + 1, j + 1) || GetRClicked(i + 1, j + 1)))
{
pt.x = XPos + (i << 4);
pt.y = YPos + (j << 4);
nMines = 0;
DrawMines();
Flag(i, j);
}
KillTimer(1);
bWin = TRUE;
if (nSeconds < nTime[nDifficulty])
{
nTime[nDifficulty] = nSeconds;
CGetName GNDlg;
GNDlg.DoModal();
}
}
}
InvalidateRect(&m_Ground, FALSE);
if (nCount == 0)
{
CPoint pt;
for (i = 0; i < 8; i ++)
{
pt.x = point.x + (x0[i] << 4);
pt.y = point.y + (y0[i] << 4);
OnLButtonUp(MK_LBUTTON, pt);
}
}
CDialog::OnLButtonUp(nFlags, point);
}
void CMine32Dlg::OnRButtonDown(UINT nFlags, CPoint point)
{
if (bBomb | bWin)
return;
int x, y;
x = (point.x - XPos) >> 4;
y = (point.y - YPos) >> 4;
if (!m_Ground.PtInRect(point))
return;
if (nFlags & MK_LBUTTON)
{
OnMButtonDown(nFlags, point);
return;
}
if (GetLClicked(x + 1, y + 1))
return;
Flag(x, y);
DrawMines();
InvalidateRect(&m_Ground, FALSE);
CDialog::OnRButtonDown(nFlags, point);
}
void CMine32Dlg::OnRButtonUp(UINT nFlags, CPoint point)
{
if (bBomb | bWin)
return;
if (nFlags & MK_LBUTTON)
{
OnMButtonUp(nFlags, point);
return;
}
CDialog::OnRButtonUp(nFlags, point);
}
void CMine32Dlg::OnMButtonUp(UINT nFlags, CPoint point)
{
if (bBomb | bWin)
return;
if (!m_Ground.PtInRect(point))
return;
CClientDC dc(this);
dc.BitBlt(m_BeginButton.left, m_BeginButton.top, 24, 24, &FacesDC, 0, 96, SRCCOPY);
CPoint pt;
int i, nCountL = 0, nCountR = 0;
int x = (point.x - XPos) >> 4;
int y = (point.y - YPos) >> 4;
for (i = 0; i < 8; i ++)
{
nCountL += GetBit(x + x0[i] + 1, y + y0[i] + 1);
nCountR += GetRClicked(x + x0[i] + 1, y + y0[i] + 1);
}
if (nCountL != nCountR)
return;
for (i = 0; i < 8; i ++)
{
pt.x = point.x + (x0[i] << 4);
pt.y = point.y + (y0[i] << 4);
OnLButtonUp(MK_LBUTTON, pt);
}
CDialog::OnMButtonUp(nFlags, point);
}
void CMine32Dlg::OnMButtonDown(UINT nFlags, CPoint point)
{
if (bBomb | bWin)
return;
CClientDC dc(this);
dc.BitBlt(m_BeginButton.left, m_BeginButton.top, 24, 24, &FacesDC, 0, 72, SRCCOPY);
CPoint pt;
int i;
int x, y;
x = (point.x - XPos) >> 4;
y = (point.y - YPos) >> 4;
if (!GetLClicked(x + 1, y + 1))
dc.BitBlt(XPos + (x << 4), YPos + (y << 4), 16, 16, &IconsDC, 0, 240, SRCCOPY);
for (i = 0; i < 8; i ++)
{
pt.x = XPos + ((x + x0[i]) << 4);
pt.y = YPos + ((y + y0[i]) << 4);
if (m_Ground.PtInRect(pt) && !GetLClicked(x + x0[i] + 1, y + y0[i] + 1) && !GetRClicked(x + x0[i] + 1, y + y0[i] + 1))
dc.BitBlt(pt.x, pt.y, 16, 16, &IconsDC, 0, 240, SRCCOPY);
}
// TODO: Add your message handler code here and/or call default
CDialog::OnMButtonDown(nFlags, point);
}
void CMine32Dlg::OnAbout()
{
CAboutDlg about;
about.DoModal();
}
/*void CMine32Dlg::OnMouseMove(UINT nFlags, CPoint point)
{
if (bBomb | bWin)
return;
CClientDC dc(this);
int x, y;
x = (point.x - XPos) >> 4;
y = (point.y - YPos) >> 4;
if (x == m_LastPoint.x && y == m_LastPoint.y)
return;
if (m_LastPoint.x == m_LastPoint.y == -1)
return;
if ((nFlags & MK_LBUTTON) && (nFlags & MK_RBUTTON))
{
CPoint pt;
int i;
for (i = 0; i < 8; i ++)
{
pt.x = XPos + ((m_LastPoint.x + x0[i]) << 4);
pt.y = YPos + ((m_LastPoint.y + y0[i]) << 4);
if (m_Ground.PtInRect(pt) && !GetLClicked(x + x0[i] + 1, y + y0[i] + 1) && !GetRClicked(x + x0[i] + 1, y + y0[i] + 1))
dc.BitBlt(pt.x, pt.y, 16, 16, &IconsDC, 0, 240, SRCCOPY);
}
if (!m_Ground.PtInRect(point))
{
m_LastPoint.x = m_LastPoint.y = -1;
return;
}
for (i = 0; i < 8; i ++)
{
pt.x = XPos + ((x + x0[i]) << 4);
pt.y = YPos + ((y + y0[i]) << 4);
if (m_Ground.PtInRect(pt) && !GetLClicked(x + x0[i] + 1, y + y0[i] + 1) && !GetRClicked(x + x0[i] + 1, y + y0[i] + 1))
dc.BitBlt(pt.x, pt.y, 16, 16, &IconsDC, 0, 240, SRCCOPY);
}
}
if (nFlags & MK_LBUTTON)
{
if (GetLClicked(x + 1, y + 1))
return;
dc.BitBlt(XPos + (m_LastPoint.x << 4), YPos + (m_LastPoint.y << 4), 16, 16, &IconsDC, 0, 0, SRCCOPY);
if (!m_Ground.PtInRect(point))
{
m_LastPoint.x = m_LastPoint.y = -1;
return;
}
dc.BitBlt(XPos + (x << 4), YPos + (y << 4), 16, 16, &IconsDC, 0, 240, SRCCOPY);
}
m_LastPoint.x = x;
m_LastPoint.y = y;
CDialog::OnMouseMove(nFlags, point);
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -