📄 catcatchratview.cpp
字号:
}
void CCatCatchRatView::OnUpdateNormal(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_nDifficulty==1);
pCmdUI->Enable(StartFlag==-1);
}
void CCatCatchRatView::OnUpdateRestart(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(StartFlag==2);
}
void CCatCatchRatView::OnUpdateStop(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(StartFlag==1);
}
void CCatCatchRatView::OnUpdateHard(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_nDifficulty==2);
pCmdUI->Enable(StartFlag==-1);
}
void CCatCatchRatView::OnUpdateStart(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(StartFlag<1);
}
void CCatCatchRatView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(StartFlag)
{
InvalidateRect(m_rectCat,TRUE);
switch(nChar)
{
case VK_UP:
if(m_rectCat.top-m_nCatSpeed>m_rectClient.top)
{
m_rectCat.top-=m_nCatSpeed;
m_rectCat.bottom-=m_nCatSpeed;
m_nCaty-=m_nCatSpeed;
m_nCatDirection=0;
}
break;
case VK_DOWN:
if(m_rectCat.bottom+m_nCatSpeed<m_rectClient.bottom)
{
m_rectCat.top+=m_nCatSpeed;
m_rectCat.bottom+=m_nCatSpeed;
m_nCaty+=m_nCatSpeed;
m_nCatDirection=1;
}
break;
case VK_LEFT:
if(m_rectCat.left-m_nCatSpeed>m_rectClient.left)
{
m_rectCat.left-=m_nCatSpeed;
m_rectCat.right-=m_nCatSpeed;
m_nCatx-=m_nCatSpeed;
m_nCatDirection=2;
}
break;
case VK_RIGHT:
if(m_rectCat.right+m_nCatSpeed<m_rectClient.right)
{
m_rectCat.left+=m_nCatSpeed;
m_rectCat.right+=m_nCatSpeed;
m_nCatx+=m_nCatSpeed;
m_nCatDirection=3;
}
}
InvalidateRect(m_rectCat,FALSE);
for(int i=0;i<RATMAX;i++)
{
if(m_bRatLive[i]&&(abs(m_nRatx[i]-m_nCatx)<m_nRatw)&&(abs(m_nRaty[i]-m_nCaty)<m_nRath))
{
m_bRatLive[i]=FALSE;
m_nRat--;
InvalidateRect(m_rectRat[i]);
InvalidateRect(CRect(590,100,750,230));
}
}
}
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CCatCatchRatView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(m_nRat>0)
{
srand((unsigned)time(NULL));
for(int i=0;i<RATMAX;i++)
{
if(m_bRatLive[i])
{
switch(nIDEvent)
{
case 2:
m_nRatDirection[i]=rand()%4;
break;
case 1:
InvalidateRect(m_rectRat[i]);
int nRatMoveStep=m_nRatSpeed+rand()%5;
if((abs(m_nRatx[i]-m_nCatx)<3*m_nRatw)
|| (abs(m_nRaty[i]-m_nCaty)<3*m_nRath))
{ //如果老鼠靠近了猫就改变方向
//m_nRatDirection[i]=rand()%4;
m_nRatDirection[i]=(m_nCatDirection+rand())%4;
}/*if*/
switch(m_nRatDirection[i])
{
case 0:
if(m_rectRat[i].top-nRatMoveStep>m_rectClient.top)
{
m_rectRat[i].top-=nRatMoveStep;
m_rectRat[i].bottom-=nRatMoveStep;
m_nRaty[i]-=nRatMoveStep;
}
else m_nRatDirection[i]=rand()%4;
break;
case 1:
if(m_rectRat[i].bottom+nRatMoveStep<m_rectClient.bottom)
{
m_rectRat[i].top+=nRatMoveStep;
m_rectRat[i].bottom+=nRatMoveStep;
m_nRaty[i]+=nRatMoveStep;
}
else m_nRatDirection[i]=rand()%4;
break;
case 2:
if(m_rectRat[i].left-nRatMoveStep>m_rectClient.bottom)
{
m_rectRat[i].left-=nRatMoveStep;
m_rectRat[i].right-=nRatMoveStep;
m_nRatx[i]-=nRatMoveStep;
}
else m_nRatDirection[i]=rand()%4;
break;
case 3:
if(m_rectRat[i].right+nRatMoveStep<m_rectClient.bottom)
{
m_rectRat[i].left+=nRatMoveStep;
m_rectRat[i].right+=nRatMoveStep;
m_nRatx[i]+=nRatMoveStep;
}
else m_nRatDirection[i]=rand()%4;
}
}
/*if((abs(m_nRatx[i]-m_nCatx)<m_nRatw)&&(abs(m_nRaty[i]-m_nCaty)<m_nRath))
{
m_nRat--;
m_bRatLive[i]=FALSE;
}*/
if((abs(m_nRatx[i]-m_nCatx)<m_nRatw)&&(abs(m_nRaty[i]-m_nCaty)<m_nRath)
&&((m_nRatx[i]<m_nCatx)&&m_nCatDirection==2))
{
m_nRat--;
m_bRatLive[i]=FALSE;
}
else
if((abs(m_nRatx[i]-m_nCatx)<m_nRatw)&&(abs(m_nRaty[i]-m_nCaty)<m_nRath)
&&((m_nRatx[i]>m_nCatx)&&m_nCatDirection==3))
{
m_nRat--;
m_bRatLive[i]=FALSE;
}
else
if((abs(m_nRatx[i]-m_nCatx)<m_nRatw)&&(abs(m_nRaty[i]-m_nCaty)<m_nRath)
&&((m_nRaty[i]<m_nCaty)&&m_nCatDirection==0))
{
m_nRat--;
m_bRatLive[i]=FALSE;
}
else
if((abs(m_nRatx[i]-m_nCatx)<m_nRatw)&&(abs(m_nRaty[i]-m_nCaty)<m_nRath)
&&((m_nRaty[i]>m_nCaty)&&m_nCatDirection==1))
{
m_nRat--;
m_bRatLive[i]=FALSE;
}
InvalidateRect(m_rectRat[i]);
}
}
m_timeEnd=m_timeEnd.GetCurrentTime();
m_timeWork=m_timeSet-(m_timeEnd-m_timeStart);
InvalidateRect(CRect(590,100,750,230));
if(!(m_timeWork.GetTotalSeconds()))
if(m_nRat)
{
KillTimer(1);
KillTimer(2);
StartFlag=2;
MessageBox("失败,要不要再试一次");
CCatCatchRatView::OnRestart();
CCatCatchRatView::OnStart();
}
}
else
{
KillTimer(1);
KillTimer(2);
StartFlag=2;
MessageBox("胜利,进入下一关");
CCatCatchRatView::OnRestart();
CCatCatchRatView::LevelIncrease();
//CCatCatchRatView::SetGameLevel();
CCatCatchRatView::OnStart();
}
CView::OnTimer(nIDEvent);
}
void CCatCatchRatView::SetGameLevel()
{
GameSlectDlg dlg2;
if(dlg2.DoModal()==IDOK)
{
RATMAX=dlg2.m_RatMount;
m_nDifficulty=dlg2.m_GameLevel;
m_nCatSpeed+=m_nDifficulty;
m_nRatSpeed+=(m_nDifficulty*4);
}
}
void CCatCatchRatView::LevelIncrease()
{
GameSlectDlg dlg3;
dlg3.m_GameLevel++;
m_nDifficulty++;
m_nCatSpeed++;
m_nRatSpeed+=4;
}
void CCatCatchRatView::OnOpiontMusic()
{
HWND hWnd;
hWnd = GetSafeHwnd();
//分配命令缓冲符,错误信息储存缓冲,播放的文件名
char inBuf[300],outBuf[60],fileName[255];
//错落误码
MCIERROR mciError;
//初始化设备元素
strcpy(fileName,"bg.mid");
//初始化命令字符串
wsprintf( inBuf,"open %s type sequencer alias myseq",fileName);
//打开设备
mciError = mciSendString( inBuf, outBuf, sizeof(outBuf), NULL);
if (mciError == 0)
{
//如果打开成功则播放
mciError = mciSendString("play myseq notify",NULL,0, hWnd);
//根据播放操作是否成功决定是否关闭设备
if (mciError != 0)
mciSendString("close myseq",NULL,0,NULL);
}
}
void CCatCatchRatView::OnGaSel()
{
// TODO: Add your command handler code here
CCatCatchRatView::OnStop();
CCatCatchRatView::SetGameLevel();
CCatCatchRatView::OnRestart();
CCatCatchRatView::OnStart();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -