📄 hwrectview.cpp
字号:
}
void CHWRECTView::OnOptionArea1()
{
// TODO: Add your command handler code here
m_iRow = 12;
m_iCol = 10;
m_iLarge = 30;
Invalidate();
}
void CHWRECTView::OnOptionArea2()
{
// TODO: Add your command handler code here
m_iRow = 18;
m_iCol = 15;
m_iLarge = 20;
Invalidate();
}
void CHWRECTView::OnOptionArea3()
{
// TODO: Add your command handler code here
m_iRow = 24;
m_iCol = 20;
m_iLarge = 15;
Invalidate();
}
void CHWRECTView::OnOptionArea4()
{
// TODO: Add your command handler code here
m_iRow = 30;
m_iCol = 25;
m_iLarge = 12;
Invalidate();
}
void CHWRECTView::OnOptionLevel1()
{
// TODO: Add your command handler code here
m_iLevel = 0;
}
void CHWRECTView::OnOptionLevel2()
{
// TODO: Add your command handler code here
m_iLevel = 1;
}
void CHWRECTView::OnOptionLevel3()
{
// TODO: Add your command handler code here
m_iLevel = 2;
}
void CHWRECTView::OnOptionLevel4()
{
// TODO: Add your command handler code here
m_iLevel = 3;
}
void CHWRECTView::OnOptionLevel5()
{
// TODO: Add your command handler code here
m_iLevel = 4;
}
void CHWRECTView::OnOptionLevel6()
{
// TODO: Add your command handler code here
m_iLevel = 5;
}
void CHWRECTView::OnOptionGrid()
{
// TODO: Add your command handler code here
if (m_bDrawGrid)
m_bDrawGrid = FALSE;
else
m_bDrawGrid = TRUE;
Invalidate();
}
void CHWRECTView::OnOptionMusic()
{
// TODO: Add your command handler code here
if (m_bMusic)
{
m_bMusic = FALSE;
StopMid();
}
else
{
m_bMusic = TRUE;
PlayMid();
}
}
void CHWRECTView::OnHelpHelp()
{
// TODO: Add your command handler code here
}
void CHWRECTView::OnHelpAbout()
{
// TODO: Add your command handler code here
MessageBox("重庆大学软件学院\n软件工程2002级3班\n\n靳国荣\n\n本程序大家可以任意复制,可以转载,\n请各位保证程序的完整性。\n由于本人初学VC++,所以有很多不足\n之处,请各位指出。\n谢谢!\n\nEmail:jgr8224@sina.com.cn\n jgr82224@hotmail.com\n\n 2004年4月28日");
}
void CHWRECTView::InvalidateCurrent()
{
int i;
for (i=0;i<4;i++)
{
CRect rect(m_iStartX+ActiveStatus[i][1]*m_iLarge, m_iStartY+ActiveStatus[i][0]*m_iLarge,
m_iStartX+(ActiveStatus[i][1]+1)*m_iLarge+5, m_iStartY+(ActiveStatus[i][0]+1)*m_iLarge);
InvalidateRect(&rect);
}
}
void CHWRECTView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
int i,j,k;
if (m_isBottom)
{
m_icurrentStatus = m_inextStatus;
m_inextStatus = Random(7); //得到下一次的方块样式
if (m_inextStatus==0) m_inextStatus++;
m_currentRect = m_icurrentStatus; //当前落下的方块的形状代码
RectStatusToActiveStatus( m_icurrentStatus );
ActiveStatusToGameStatus();
m_isBottom = FALSE;
ActiveIsBottom();
InvalidateCurrent();
//在屏幕右边显示下一次将会出来的方块的模样
RectStatusToNextStatus( m_inextStatus );
CRect rect(m_iStartY+320, m_iStartX, m_iStartY+440, m_iStartX+160);
InvalidateRect(&rect);
//判断游戏是否已结束: 碰了底,且第1行有小方块
if (m_isBottom)
for (i=0;i<m_iCol;i++)
if (GameStatus[0][i])
{
KillTimer(1);
AfxMessageBox("游戏已结束!");
for (j=0;j<m_iRow;j++)
for (k=0;k<m_iCol;k++)
GameStatus[j][k]=0;
Invalidate();
m_bGameEnd = TRUE;
break;
}
}
else //当前方块下降
{
RectDown();
}
CView::OnTimer(nIDEvent);
}
void CHWRECTView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
switch(nChar)
{
case 'a':
case 'A':
case VK_LEFT:
RectArrow(LEFT);
break;
case 'd':
case 'D':
case VK_RIGHT:
RectArrow(RIGHT);
break;
case 's':
case 'S':
case VK_UP:
RectChange();
break;
case 'x':
case 'X':
case VK_DOWN:
RectArrow(DOWN);
break;
}
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CHWRECTView::OnUpdateGameStart(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_bGameEnd || m_bGamePaush)
pCmdUI->Enable(TRUE);
else
pCmdUI->Enable(FALSE);
}
void CHWRECTView::OnUpdateGameEnd(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (!m_bGameEnd)
pCmdUI->Enable(TRUE);
else
pCmdUI->Enable(FALSE);
}
void CHWRECTView::OnUpdateGameOption(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_bGameEnd)
pCmdUI->Enable(TRUE);
else
pCmdUI->Enable(FALSE);
}
void CHWRECTView::OnUpdateGameExit(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_bGameEnd)
pCmdUI->Enable(TRUE);
else
pCmdUI->Enable(FALSE);
}
void CHWRECTView::OnUpdateGamePaush(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (!m_bGameEnd)
pCmdUI->Enable(TRUE);
else
pCmdUI->Enable(FALSE);
}
void CHWRECTView::OnUpdateOptionArea1(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_bGameEnd)
pCmdUI -> Enable(TRUE);
else
pCmdUI -> Enable(FALSE);
if (m_iRow==12)
pCmdUI -> SetCheck(TRUE);
else
pCmdUI -> SetCheck(FALSE);
}
void CHWRECTView::OnUpdateOptionArea2(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_bGameEnd)
pCmdUI -> Enable(TRUE);
else
pCmdUI -> Enable(FALSE);
if (m_iRow==18)
pCmdUI -> SetCheck(TRUE);
else
pCmdUI -> SetCheck(FALSE);
}
void CHWRECTView::OnUpdateOptionArea3(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_bGameEnd)
pCmdUI -> Enable(TRUE);
else
pCmdUI -> Enable(FALSE);
if (m_iRow==24)
pCmdUI -> SetCheck(TRUE);
else
pCmdUI -> SetCheck(FALSE);
}
void CHWRECTView::OnUpdateOptionArea4(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_bGameEnd)
pCmdUI -> Enable(TRUE);
else
pCmdUI -> Enable(FALSE);
if (m_iRow==30)
pCmdUI -> SetCheck(TRUE);
else
pCmdUI -> SetCheck(FALSE);
}
void CHWRECTView::OnUpdateOptionLevel1(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_bGameEnd)
pCmdUI -> Enable(TRUE);
else
pCmdUI -> Enable(FALSE);
if (m_iLevel == 0)
pCmdUI -> SetCheck(TRUE);
else
pCmdUI -> SetCheck(FALSE);
}
void CHWRECTView::OnUpdateOptionLevel2(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_bGameEnd)
pCmdUI -> Enable(TRUE);
else
pCmdUI -> Enable(FALSE);
if (m_iLevel == 1)
pCmdUI -> SetCheck(TRUE);
else
pCmdUI -> SetCheck(FALSE);
}
void CHWRECTView::OnUpdateOptionLevel3(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_bGameEnd)
pCmdUI -> Enable(TRUE);
else
pCmdUI -> Enable(FALSE);
if (m_iLevel == 2)
pCmdUI -> SetCheck(TRUE);
else
pCmdUI -> SetCheck(FALSE);
}
void CHWRECTView::OnUpdateOptionLevel4(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_bGameEnd)
pCmdUI -> Enable(TRUE);
else
pCmdUI -> Enable(FALSE);
if (m_iLevel == 3)
pCmdUI -> SetCheck(TRUE);
else
pCmdUI -> SetCheck(FALSE);
}
void CHWRECTView::OnUpdateOptionLevel5(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_bGameEnd)
pCmdUI -> Enable(TRUE);
else
pCmdUI -> Enable(FALSE);
if (m_iLevel == 4)
pCmdUI -> SetCheck(TRUE);
else
pCmdUI -> SetCheck(FALSE);
}
void CHWRECTView::OnUpdateOptionLevel6(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_bGameEnd)
pCmdUI -> Enable(TRUE);
else
pCmdUI -> Enable(FALSE);
if (m_iLevel == 5)
pCmdUI -> SetCheck(TRUE);
else
pCmdUI -> SetCheck(FALSE);
}
void CHWRECTView::OnUpdateOptionGrid(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_bGameEnd)
pCmdUI -> Enable(TRUE);
else
pCmdUI -> Enable(FALSE);
if (m_bDrawGrid)
pCmdUI -> SetCheck(TRUE);
else
pCmdUI -> SetCheck(FALSE);
}
void CHWRECTView::OnUpdateOptionMusic(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_bGameEnd)
pCmdUI -> Enable(TRUE);
else
pCmdUI -> Enable(FALSE);
if (m_bMusic)
pCmdUI -> SetCheck(TRUE);
else
pCmdUI -> SetCheck(FALSE);
}
int CHWRECTView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
//白色的黑笔
whitePen = new CPen(PS_SOLID,1,WHITE);
//黑色的黑笔
blackPen = new CPen(PS_SOLID,1,BLACK);
//画刷
grayBrush = new CBrush(RGB(0,255,255));
blueBrush = new CBrush(BLUE);
blackBrush = new CBrush(BLACK);
//决定第一次掉下来的方块的样式
m_inextStatus = Random(7);
if (m_inextStatus==0) m_inextStatus++;
return 0;
}
void CHWRECTView::OnUpdateHelpHelp(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_bGameEnd)
pCmdUI->Enable(FALSE);
else
pCmdUI->Enable(FALSE);
}
void CHWRECTView::OnUpdateHelpAbout(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_bGameEnd)
pCmdUI->Enable(TRUE);
else
pCmdUI->Enable(FALSE);
}
void CHWRECTView::OnHelpTeach()
{
// TODO: Add your command handler code here
}
void CHWRECTView::OnUpdateHelpTeach(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CHWRECTView::OnBackMusic()
{
// TODO: Add your command handler code here
char szFileFilter[]="Mid files(*.mid)|*.mid|";
CFileDialog MyFile(TRUE,//Open对话框
"", //缺省扩展名
"*.mid",
OFN_HIDEREADONLY|OFN_FILEMUSTEXIST, //文件必须存在
szFileFilter,
this);
if (MyFile.DoModal()==IDOK)
{
text.BackMusicFileName=MyFile.GetPathName();
text.mid.Close();
text.mid.Open(text.BackMusicFileName);
text.mid.Play();
//CHWRECTView::SetTimer(IDC_COUNTTIMER,10000,NULL);
}
}
void CHWRECTView::OnCloseMusic()
{
// TODO: Add your command handler code here
text.mid.Close();
// CHWRECTView::KillTimer(IDC_COUNTTIMER);
}
void CHWRECTView::OnMusicCycle()
{
// TODO: Add your command handler code here
CMenu *menu;
menu=AfxGetMainWnd()->GetMenu();
if (text.MusicRecycle==MF_UNCHECKED)
{
menu->CheckMenuItem(IDC_MUSIC_CYCLE,MF_CHECKED);
text.MusicRecycle=MF_CHECKED;
}
else
{
menu->CheckMenuItem(IDC_MUSIC_CYCLE,MF_UNCHECKED);
text.MusicRecycle=MF_UNCHECKED;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -