?? russiaview.cpp
字號:
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
RegisterHotKey(CRussiaView::m_hWnd,1001,MOD_CONTROL|MOD_ALT,'Z');
RegisterHotKey(m_hWnd,1002,MOD_CONTROL|MOD_ALT,'z');
CDC* pDC=GetDC();
Game.GameInit(pDC);
Game2.GameInit(pDC);
Initial();
Game2.SetPosition(320,0);
Game.SetPosition(0,0);
ReleaseDC(pDC);
// Game.SetPosition(20,10);
return 0;
}
void CRussiaView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
int i=nChar;
if(nChar==VK_SPACE)
{
OnMenuPause();
return;
}
if(m_bPause==TRUE) return;
switch(nChar)
{
case VK_LEFT:
Game.MoveLeft();
break;
case VK_RIGHT:
Game.MoveRight();
break;
case VK_UP:
Game.MoveRotate();
break;
case VK_DOWN:
Game.MoveNext();
break;
case 65:
Game2.MoveLeft();
break;
case 68:
Game2.MoveRight();
break;
case 87:
Game2.MoveRotate();
break;
case 83:
Game2.MoveNext();
break;
}
CDC* pDC=GetDC();
Game.Draw(pDC);
if(CurrentGameFlag==2)
Game2.Draw(pDC);
ReleaseDC(pDC);
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CRussiaView::OnUpdateMenuPause(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_bPause);
}
void CRussiaView::OnMenuSetup()
{
// TODO: Add your command handler code here
m_bPause=TRUE;
Game.PlayMusic(FALSE);
CDialogSetup dlg;
dlg.m_Difficult=Game.GetLevel();
dlg.m_Speed=Game.GetSpeed();
dlg.m_Music=m_bMusic;
if(dlg.DoModal()==IDOK)
{
Game.SetLevel(dlg.m_Difficult);
Game.SetSpeed(dlg.m_Speed);
Game.SetLevel(dlg.m_Difficult);
Game2.SetLevel(dlg.m_Difficult);
Game2.SetSpeed(dlg.m_Speed);
Game2.SetLevel(dlg.m_Difficult);
m_bMusic=dlg.m_Music;
}
Invalidate(false);
}
void CRussiaView::OnMenuSave()
{
m_bPause=true;
if(CurrentGameFlag!=1) return;
CFileDialog dlg(FALSE,"fly",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"(*.FLY)|*.fly|All Files|*.*||",this);
if(dlg.DoModal()==IDOK)
Game.SaveGame(dlg.GetFileName());
}
void CRussiaView::OnMenuRead()
{
m_bPause=true;
if(CurrentGameFlag!=1) return;
CFileDialog dlg(TRUE,"fly",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"(*.FLY)|*.fly|All Files|*.*||",this);
if(dlg.DoModal()==IDOK)
{
Game.ReadGame(dlg.GetFileName());
m_bStart=TRUE;
}
Invalidate(false);
}
void CRussiaView::OnMenuNetstart()
{
// TODO: Add your command handler code here
MessageBox("請您購買注冊版(E_Mail:kiler@cmmail.com)","俄羅斯方塊",MB_ICONINFORMATION);
}
void CRussiaView::OnMenuDoublestart()
{
MessageBox("請您購買注冊版(E_Mail:kiler@cmmail.com)","俄羅斯方塊",MB_ICONINFORMATION);
return;
CWinApp* pApp = AfxGetApp();
int dx=pApp->GetProfileInt("Settings","方塊大小",20);
int m1=111+dx*10;
int m2=85+dx*24;
if(CurrentGameFlag!=2)
{
//調整窗口大小
AfxGetMainWnd() ->SetWindowPos(NULL,0,0,2*m1,m2,SWP_NOMOVE|SWP_NOZORDER|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_SYSMENU );
AfxGetMainWnd()->CenterWindow();
}
CurrentGameFlag=2;
//1為單人游戲,2為雙人游戲,3為網絡游戲
Game.SetPosition(m1,0);
Game2.SetPosition(0,0);
m_bPause=false;
m_bStart=true;
SetTimer(9999,50*(11-Game.GetSpeed()),NULL);
Game.Start();
Game.Draw(GetDC());
Game2.Start();
Game2.Draw(GetDC());
//播放聲音
Game2.PlayMusic(m_bMusic);
Game.PlayMusic(m_bMusic);
}
void CRussiaView::OnMenuHelp()
{
CDialogHelp dlg;
dlg.DoModal();
}
void CRussiaView::OnMenuColor()
{
m_bPause=TRUE;
Game.PlayMusic(FALSE);
CDialogColorSetup dlg;
dlg.m_clrCube=Game.m_clrCube;//方塊顏色
dlg.m_clrDeclareCube=Game.m_clrDeclareCube;//聲明區域的方塊顏色
dlg.m_clrMaxRect=Game.m_clrMaxRect;//最大區域顏色
dlg.m_clrDeclareRect=Game.m_clrDeclareRect;//聲明區域顏色
dlg.m_clrDiamondsRect=Game.m_clrDiamondsRect;//運行區域顏色
dlg.m_clrLine=Game.m_clrLine;//方格線顏色
dlg.m_clrDeclareFont=Game.m_clrDeclareFont; //聲明區域的字體顏色
dlg.m_clrGameOverFont=Game.m_clrGameOverFont; //游戲結束字體的顏色
dlg.m_bRandomCubeColor=Game.m_bRandomCubeColor; //隨機產生運動方塊顏色
if(dlg.DoModal()==IDOK)
{
//顏色設置
Game.m_clrCube=dlg.m_clrCube;//方塊顏色
Game.m_clrDeclareCube=dlg.m_clrDeclareCube;//聲明區域的方塊顏色
Game.m_clrMaxRect=dlg.m_clrMaxRect;//最大區域顏色
Game.m_clrDeclareRect=dlg.m_clrDeclareRect;//聲明區域顏色
Game.m_clrDiamondsRect=dlg.m_clrDiamondsRect;//運行區域顏色
Game.m_clrLine=dlg.m_clrLine;//方格線顏色
Game.m_clrDeclareFont=dlg.m_clrDeclareFont; //聲明區域的字體顏色
Game.m_clrGameOverFont=dlg.m_clrGameOverFont; //游戲結束字體的顏色
Game.m_bRandomCubeColor=dlg.m_bRandomCubeColor;//隨機產生運動方塊顏色
Game2.m_clrCube=dlg.m_clrCube;//方塊顏色
Game2.m_clrDeclareCube=dlg.m_clrDeclareCube;//聲明區域的方塊顏色
Game2.m_clrMaxRect=dlg.m_clrMaxRect;//最大區域顏色
Game2.m_clrDeclareRect=dlg.m_clrDeclareRect;//聲明區域顏色
Game2.m_clrDiamondsRect=dlg.m_clrDiamondsRect;//運行區域顏色
Game2.m_clrLine=dlg.m_clrLine;//方格線顏色
Game2.m_clrDeclareFont=dlg.m_clrDeclareFont; //聲明區域的字體顏色
Game2.m_clrGameOverFont=dlg.m_clrGameOverFont; //游戲結束字體的顏色
Game2.m_bRandomCubeColor=dlg.m_bRandomCubeColor;//隨機產生運動方塊顏色
if(CurrentGameFlag==2)
{//1為單人游戲,2為雙人游戲,3為網絡游戲
Game.SetPosition(302,0);
Game2.SetPosition(0,0);
}
else if(CurrentGameFlag==1)
{
Game.SetPosition(0,0);
Game2.SetPosition(302,0);
}
Invalidate(FALSE);
}
}
void CRussiaView::OnMenuPlayer()
{
CDialogPlayer dlg;
dlg.DoModal();
}
int CRussiaView::GetMinScore()
{
TCHAR szDir [MAX_PATH];
:: GetWindowsDirectory (szDir, MAX_PATH);
CString str,s[5];
int i,m[5];
CStdioFile file;
for(i=0;i<5;i++)
{
s[i]="swallow";
m[i]=50;
} //初始值置為50
//先從文件中把成績和姓名讀出存入m[i]和s[i]中
str.Format("%s\\kiler.ini",szDir);
if(file.Open(str,CFile::modeRead)!=0)
{
CArchive ar(&file,CArchive::load);
for(i=0;i<5;i++)
{
ar.ReadString(str);
sscanf(str,"%d",&m[i]);
}
ar.Close();
file.Close();
}
return(m[4]);
}
void CRussiaView::Initial()
{
CWinApp* pApp = AfxGetApp();
Game.m_clrCube=pApp->GetProfileInt(szSection, clrCube, Game.m_clrCube);
Game.m_clrDeclareCube=pApp->GetProfileInt(szSection, clrDeclareCube, Game.m_clrDeclareCube);
Game.m_clrMaxRect =pApp->GetProfileInt(szSection,clrMaxRect ,Game.m_clrMaxRect );
Game.m_clrDeclareRect=pApp->GetProfileInt(szSection,clrDeclareRect , Game.m_clrDeclareRect);
Game.m_clrDiamondsRect=pApp->GetProfileInt(szSection,clrDiamondsRect , Game.m_clrDiamondsRect);
Game.m_clrLine=pApp->GetProfileInt(szSection, clrLine, Game.m_clrLine);
Game.m_clrDeclareFont =pApp->GetProfileInt(szSection, clrDeclareFont,Game.m_clrDeclareFont );
Game.m_clrGameOverFont=pApp->GetProfileInt(szSection,clrGameOverFont , Game.m_clrGameOverFont);
Game.m_bRandomCubeColor=pApp->GetProfileInt(szSection, bRandomCubeColor,Game.m_bRandomCubeColor );
Game2.m_clrCube=pApp->GetProfileInt(szSection, clrCube, Game.m_clrCube);
Game2.m_clrDeclareCube=pApp->GetProfileInt(szSection, clrDeclareCube, Game.m_clrDeclareCube);
Game2.m_clrMaxRect =pApp->GetProfileInt(szSection,clrMaxRect ,Game.m_clrMaxRect );
Game2.m_clrDeclareRect=pApp->GetProfileInt(szSection,clrDeclareRect , Game.m_clrDeclareRect);
Game2.m_clrDiamondsRect=pApp->GetProfileInt(szSection,clrDiamondsRect , Game.m_clrDiamondsRect);
Game2.m_clrLine=pApp->GetProfileInt(szSection, clrLine, Game.m_clrLine);
Game2.m_clrDeclareFont =pApp->GetProfileInt(szSection, clrDeclareFont,Game.m_clrDeclareFont );
Game2.m_clrGameOverFont=pApp->GetProfileInt(szSection,clrGameOverFont , Game.m_clrGameOverFont);
Game2.m_bRandomCubeColor=pApp->GetProfileInt(szSection, bRandomCubeColor,Game.m_bRandomCubeColor );
m_bMusic=pApp->GetProfileInt(szSection, Music, FALSE);
Game.SetSpeed(pApp->GetProfileInt(szSection, Speed, 5));
Game.SetLevel(pApp->GetProfileInt(szSection,Difficult ,2));
Game2.SetSpeed(pApp->GetProfileInt(szSection, Speed, 5));
Game2.SetLevel(pApp->GetProfileInt(szSection,Difficult ,2));
}
void CRussiaView::OnDestroy()
{
CView::OnDestroy();
// TODO: Add your message handler code here
UnregisterHotKey(m_hWnd,1001);
UnregisterHotKey(m_hWnd,1002);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -