📄 minewnd.cpp
字号:
MyCheckMenuItem();
SetWindowSize();
ReAssign();
GameInit();
Invalidate();
}
void CMineWnd::OnMenuCustom()
{
theApp.uGameLevel = LEVEL_CUSTOM;
CCustomDlg customDlg;
if(customDlg.DoModal() == IDOK)
{
SetWindowSize();
}
MyCheckMenuItem();
ReAssign();
GameInit();
Invalidate();
}
void CMineWnd::OnMenuMark()
{
theApp.bMarked = !theApp.bMarked;
MyCheckMarkItem();
}
void CMineWnd::OnMenuSound()
{
theApp.bSound = !theApp.bSound;
MyCheckSoundItem();
if( !bLoadWavRes && theApp.bSound)
{
LoadWavRes();
}
else if( bLoadWavRes && !theApp.bSound )
{
FreeWavRes();
}
}
void CMineWnd::OnMenuColor()
{
theApp.bColor = !theApp.bColor;
SetBitmap();
MyCheckColorItem();
if(theApp.bColor)
darkColor = COLOR_DARK_GRAY;
else
darkColor = COLOR_BLACK;
Invalidate();
}
void CMineWnd::MyCheckColorItem()
{
if(theApp.bColor)
{
pSubMenu->CheckMenuItem(ID_MENU_COLOR, MF_CHECKED | MF_BYCOMMAND);
}
else
{
pSubMenu->CheckMenuItem(ID_MENU_COLOR, MF_UNCHECKED | MF_BYCOMMAND);
}
}
void CMineWnd::MyCheckSoundItem()
{
if(theApp.bSound)
{
pSubMenu->CheckMenuItem(ID_MENU_SOUND, MF_CHECKED | MF_BYCOMMAND);
}
else
{
pSubMenu->CheckMenuItem(ID_MENU_SOUND, MF_UNCHECKED | MF_BYCOMMAND);
}
}
void CMineWnd::MyCheckMarkItem()
{
if(theApp.bMarked)
{
pSubMenu->CheckMenuItem(ID_MENU_MARK, MF_CHECKED | MF_BYCOMMAND);
}
else
{
pSubMenu->CheckMenuItem(ID_MENU_MARK, MF_UNCHECKED | MF_BYCOMMAND);
}
}
void CMineWnd::OnMenuHeroList()
{
CHeroDlg heroDlg;
heroDlg.DoModal();
}
void CMineWnd::OnInitMenu(CMenu* pMenu)
{
CWnd::OnInitMenu(pMenu);
if( (pSubMenu = pMenu->GetSubMenu(0)) == NULL )
{
AfxMessageBox(theApp.sResource[7]);
PostQuitMessage(0);
}
else
{
MyCheckMenuItem();
MyCheckColorItem();
MyCheckMarkItem();
MyCheckSoundItem();
}
}
void CMineWnd::OnPaint()
{
CDC cdc;
CPaintDC dc(this); // device context for painting
CBitmap bitmap;
CBitmap* pOldBitmap;
if( !dc.IsPrinting() )
{
if( cdc.CreateCompatibleDC( &dc ) )
{
if(bitmap.CreateCompatibleBitmap(&dc,rect.right,rect.bottom))
{
pOldBitmap = cdc.SelectObject(&bitmap);
cdc.FillRect(&rect,&backGroundBrush);
MyDrawRectangle( (CPaintDC &)cdc );
MyDrawMineArea( (CPaintDC &)cdc );
MyDrawButton( (CPaintDC &)cdc );
MyDrawNumber( (CPaintDC &)cdc );
dc.BitBlt(rect.left, rect.top, rect.right, rect.bottom,
&cdc, 0, 0, SRCCOPY);
cdc.SelectObject( pOldBitmap );
bitmap.DeleteObject();
}
}
}
}
void CMineWnd::OnTimer(UINT nIDEvent)
{
if( nIDEvent == ID_TIMER_EVENT )
{
if(theApp.bSound)
{
sndPlaySound((LPCSTR)LockResource(pCountWavMem),
SND_MEMORY | SND_ASYNC | SND_NODEFAULT);
}
theApp.uSecends++;
CRect rect(uNumPos[0],15,uNumPos[1],39);
InvalidateRect(rect);
if(theApp.uSecends >= DEFAULT_RECORD)
{
KillTimer( ID_TIMER_EVENT );
m_nTimer = 0;
}
}
CWnd::OnTimer(nIDEvent);
}
void CMineWnd::OnClose()
{
KillTimer( ID_TIMER_EVENT );
CWnd::OnClose();
}
void CMineWnd::OnMenuExit()
{
PostQuitMessage(0);
}
void CMineWnd::OnMouseMove(UINT nFlags, CPoint point)
{
bInMineArea = FALSE;
if((nFlags == MK_LBUTTON)||(nFlags == (MK_LBUTTON|MK_RBUTTON)))
{
SetCapture(); // Capture mouse
CRect rectButton(uButtonPos[1],15,uButtonPos[2],42);
CRect rectMineArea(MINE_AREA_X, MINE_AREA_Y,
MINE_AREA_X+uWidth*MINE_WIDTH, MINE_AREA_Y+uHeight*MINE_HEIGHT);
if (rectButton.PtInRect(point))
{
// get into the button area, button down
if( bHitButton && !bInButtonRect )
{
bInButtonRect = TRUE;
uButtonState = BUTTON_DOWN;
InvalidateRect(rectButton);
}
}
else if(rectMineArea.PtInRect(point))
{
bInMineArea = TRUE;
if( uGameState == WAIT || uGameState == RUN )
{
nNewPos = GetStation(point.x,point.y);
if( nNewPos != nOldPos)
{
if( nFlags == (MK_LBUTTON|MK_RBUTTON))
{
int around[10];
int num;
if(nOldPos > -1)
{
GetAroundPos( nOldPos, around );
num = around[8];
around[num] = nOldPos;
SetMineUpEx(around,num); // up
}
GetAroundPos( nNewPos, around );
num = around[8];
around[num] = nNewPos;
SetMineDownEx(around,num); // down
}
else if( nFlags == MK_LBUTTON && !bRBUPOutMineArea )
{
SetMineDown( nNewPos);// down
if(nOldPos > -1)
{
SetMineUp( nOldPos );//up
}
}
}
nOldPos = nNewPos;
}
}
else // at orther area
{
if( bInButtonRect ) // leave the button area, button up
{
bInButtonRect = FALSE;
if( uGameState == WAIT || uGameState == RUN )
{
uButtonState = BUTTON_NORMAL;
}
else if( uGameState == DEAD )
{
uButtonState = BUTTON_DEAD;
}
else
{
uButtonState = BUTTON_VICTORY;
}
InvalidateRect(rectButton);
}
if( uGameState == WAIT || uGameState == RUN )
{
// the mine area is up when mouse is leave
if( nOldPos > -1 )
{
if( nFlags == MK_LBUTTON )// up
{
SetMineUp( nOldPos );
}
else if( nFlags == (MK_LBUTTON|MK_RBUTTON))
{
int around[10];
int num;
if(nOldPos > -1) // up
{
GetAroundPos( nOldPos, around );
num = around[8];
around[num] = nOldPos;
SetMineUpEx(around,num);
}
}
nNewPos = -1;
nOldPos = -1;
}
}
}
}
else
{
ReleaseCapture();
}
CWnd::OnMouseMove(nFlags, point);
}
void CMineWnd::OnLButtonDown(UINT nFlags, CPoint point)
{
bRBUPOutMineArea = FALSE;
CRect rectButton(uButtonPos[1],15,uButtonPos[2],42);
CRect rectMineArea(MINE_AREA_X, MINE_AREA_Y,
MINE_AREA_X+uWidth*MINE_WIDTH, MINE_AREA_Y+uHeight*MINE_HEIGHT);
if (rectButton.PtInRect(point)) // clicked button
{
bHitButton = TRUE;
bInButtonRect = TRUE;
uButtonState = BUTTON_DOWN;
InvalidateRect(rectButton);
}
else if(rectMineArea.PtInRect(point)) // clicked mine area
{
if( uGameState == WAIT || uGameState == RUN )
{
nNewPos = GetStation(point.x,point.y);
SetMineDown( nNewPos ); // down
nOldPos = nNewPos;
uButtonState = BUTTON_CLICK;
InvalidateRect( rectButton );
if( nFlags == (MK_LBUTTON|MK_RBUTTON) )
{
int around[9];
GetAroundPos( nNewPos, around );
SetMineDownEx(around,around[8]-1); // down
bDoubleClick = TRUE;
}
}
}
else // clicked other area
{
if( uGameState == WAIT || uGameState == RUN )
{
uButtonState = BUTTON_CLICK;
InvalidateRect(rectButton);
}
}
CWnd::OnLButtonDown(nFlags, point);
}
void CMineWnd::OnLButtonUp(UINT nFlags, CPoint point)
{
CRect rectButton(uButtonPos[1],15,uButtonPos[2],42);
CRect rectMineArea(MINE_AREA_X, MINE_AREA_Y,
MINE_AREA_X+uWidth*MINE_WIDTH, MINE_AREA_Y+uHeight*MINE_HEIGHT);
if( bHitButton && rectButton.PtInRect(point) )
{
GameInit(); // reset
Invalidate();
return;
}
else if( rectMineArea.PtInRect(point) )
{
if( (uGameState == WAIT || uGameState == RUN) )
{
if( uGameState == WAIT && !bRBUPOutMineArea )
{
if( (bDoubleClick && nFlags == MK_RBUTTON) ||
!bDoubleClick )
{
if(m_nTimer)
{
KillTimer( ID_TIMER_EVENT );
m_nTimer = 0;
}
m_nTimer = SetTimer(ID_TIMER_EVENT,1000,0);
uGameState = RUN;
}
}
if( bDoubleClick )
{
ProcessLeftRightButtonUp( nNewPos );
bDoubleClick = FALSE;
}
else if( !bRBUPOutMineArea )
{
ProcessLeftButtonUp( nNewPos );
}
}
}
bHitButton = FALSE;
bInButtonRect = FALSE;
if( (uGameState == WAIT || uGameState == RUN) &&
uButtonState == BUTTON_CLICK )
{
uButtonState = BUTTON_NORMAL;
InvalidateRect(rectButton);
}
CWnd::OnLButtonUp(nFlags, point);
}
void CMineWnd::OnRButtonDown(UINT nFlags, CPoint point)
{
bRBUPOutMineArea = FALSE;
CRect rectMineArea(MINE_AREA_X, MINE_AREA_Y,
MINE_AREA_X+uWidth*MINE_WIDTH, MINE_AREA_Y+uHeight*MINE_HEIGHT);
if( rectMineArea.PtInRect(point) )
{
if( uGameState == WAIT || uGameState == RUN )
{
if( nFlags == (MK_LBUTTON|MK_RBUTTON) ) // down
{
int around[10];
GetAroundPos( nNewPos, around );
int num = around[8];
around[num] = nNewPos;
SetMineDownEx(around,num);
bDoubleClick = TRUE;
}
else // chang flag
{
int pos = GetStation(point.x,point.y);
ChangeFlag( pos );
}
}
}
CWnd::OnRButtonDown(nFlags, point);
}
void CMineWnd::OnRButtonUp(UINT nFlags, CPoint point)
{
if( (uGameState == WAIT || uGameState == RUN) &&
uButtonState == BUTTON_CLICK )
{
uButtonState = BUTTON_NORMAL;
CRect rectButton(uButtonPos[1],15,uButtonPos[2],42);
InvalidateRect(rectButton);
}
if( !bInMineArea )
{
bDoubleClick = FALSE;
bRBUPOutMineArea = TRUE;
}
else if( nFlags != MK_LBUTTON )
{
bRBUPOutMineArea = FALSE;
}
if( uGameState == RUN || uGameState == WAIT )
{
CRect rectMineArea(MINE_AREA_X, MINE_AREA_Y,
MINE_AREA_X+uWidth*MINE_WIDTH, MINE_AREA_Y+uHeight*MINE_HEIGHT);
if( rectMineArea.PtInRect(point) )
{
if( nFlags == MK_LBUTTON )
{
if( uGameState == WAIT )
{
if(m_nTimer)
{
KillTimer( ID_TIMER_EVENT );
m_nTimer = 0;
}
m_nTimer = SetTimer(ID_TIMER_EVENT,1000,0);
uGameState = RUN; // start game
}
ProcessLeftRightButtonUp( nNewPos );//
}
}
}
CWnd::OnRButtonUp(nFlags, point);
}
BOOL CMineWnd::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -