?? mychessview.cpp
字號:
{
m_bMessFrom=false;
return;
}
if (0==GetDocument()->m_nSelected)//表示A準備選擇了這個棋子了
{
if (pCurrentChess)
{
if (pCurrentChess->m_uRoleID<=16)//剛好選中的子就是A方的
{
GetDocument()->m_nSelected=1;//表示A方已經選擇了棋子了
pCurrentChess->ShowIAmHere(&dc);
::PlaySound("res\\select.wav",NULL,SND_FILENAME|SND_ASYNC);
GetDocument()->m_pOldRole=pCurrentChess;//保存這個棋子以決定下一次有效單擊該怎么做
}
else
{
//do nothing//
}
}
}
else if(1==GetDocument()->m_nSelected)//表示A已經選中了一個棋子了
{
if (pCurrentChess&&pCurrentChess->m_uRoleID<=16)//表示下一步點的是自己家的子,這個時候只進行選中切換
{
CChessMan::m_stcChosenID=pCurrentChess->m_uRoleID;
GetDocument()->m_pOldRole->InvalidateMyRect(&dc);
GetDocument()->m_cpPaper.Draw(&dc);
GetDocument()->m_chessMap.Draw(&dc);
GetDocument()->m_pOldRole=pCurrentChess;
::PlaySound("res\\select.wav",NULL,SND_FILENAME|SND_ASYNC);
//InvalidateRect(NULL,true);
}
else
{
if (GetDocument()->m_chessMap.IfManInMidOfHead(GetDocument()->m_pOldRole->uRow,GetDocument()->m_pOldRole->uCol))
{
if (nPosX!=GetDocument()->m_pOldRole->uCol)////這里是用來判斷兩個將之間只有一個子的情況
{
AfxMessageBox(_T("對不起只能上下移動"));
return;
}
}
/*
if (GetDocument()->m_pOldRole->m_uRoleID==16)////判斷將的下一步是不是可以走,如果不可以走的話就提示不可以走的
{
bool bLegal=GetDocument()->m_chessMap.IfHeadCanGo(GetDocument()->m_pOldRole,point,1);
if (!bLegal)
{
AfxMessageBox(_T("這個地方太危險,不能走的"));
return ;
}
}*/
bool bIfLegal=GetDocument()->m_pOldRole->IfNextPosLegal(point);//返回true表示下一步是合法的
UINT uOldRow,uOldCol;
uOldRow=GetDocument()->m_pOldRole->uRow;
uOldCol=GetDocument()->m_pOldRole->uCol;///保存即將移動的棋子的原來的位置
if(bIfLegal)
{
/*
if (!GetDocument()->m_chessMap.IfHeadSafe(GetDocument()->m_pOldRole,nPosY,nPosX))
{
AfxMessageBox(_T("你走了你的將就不安全了,不能走的"));
return ;
}*/
if (GetDocument()->m_pOldRole->m_uRoleID==16)////判斷將的下一步是不是可以走,如果不可以走的話就提示不可以走的
{
bool bLegal=GetDocument()->m_chessMap.IfHeadCanGo(GetDocument()->m_pOldRole,point,1);
if (!bLegal)
{
AfxMessageBox(_T("將和將是不可以直接面對面的"));
return ;
}
}
//GetDocument()->m_pOldRole->GetRect(rect);
bool bResult= GetDocument()->m_pOldRole->NextStep(pCurrentChess,nPosY,nPosX);
if (true==bResult)//表示A方已經下了
{
StSaveInfo HelpSaveInfo;
if (GetDocument()->m_chessMap.TheStateOfAllChess[nPosY][nPosX]!=NULL)
{
HelpSaveInfo.uTargetId=GetDocument()->m_chessMap.TheStateOfAllChess[nPosY][nPosX]->m_uRoleID;
}
else
{
HelpSaveInfo.uTargetId=0;
}
// GetDocument()->m_chessMap.ResetStatePos(GetDocument()->m_pOldRole->uRow,GetDocument()->m_pOldRole->uCol,NULL);
GetDocument()->m_chessMap.ResetStatePos(uOldRow,uOldCol,NULL);
GetDocument()->m_chessMap.m_nSteps++;
HelpSaveInfo.uRoleId=GetDocument()->m_pOldRole->m_uRoleID;
HelpSaveInfo.uOldRow=uOldRow;
HelpSaveInfo.uOldCol=uOldCol;
HelpSaveInfo.uNewRow=nPosY;
HelpSaveInfo.uNewCol=nPosX;
GetDocument()->m_CSave.push(HelpSaveInfo);//更新CSave
GetDocument()->m_CSave.SaveChess();
if(pCurrentChess&&pCurrentChess->m_uRoleID==32)
{
::PlaySound("res\\gamewin.wav",NULL,SND_FILENAME|SND_ASYNC);
AfxMessageBox(_T("A wins the game"));
CMainFrame *pMainFrame=(CMainFrame*)AfxGetMainWnd();
CClientDC dc=CClientDC(this);
pMainFrame->Timer1->SetToZero(&dc,0);
pMainFrame->Timer2->SetToZero(&dc,300);
setJISHIToZero=true;
::AfxGetMainWnd()->KillTimer(1);
::AfxGetMainWnd()->KillTimer(2);
m_bIfLButtonDownMe=true;//默認表示是自己的單擊
m_bIfACanGo=true;
m_TalkDlg=false;
m_bIfStart=false;
m_bHeStart=false;
GetDocument()->m_chessMap.Clear();
UINT ifSave;
ifSave=MessageBox("Do you want to save? Yes/No?","Save the File",MB_YESNO);
if (ifSave==IDYES)
{
OnFileSaveas();
GetDocument()->OnNewDocument();
InvalidateRect(NULL,true);
}
else
{
GetDocument()->OnNewDocument();
InvalidateRect(NULL,true);
}
return ;
}
if (!pCurrentChess)
{
::PlaySound("res\\go.wav",NULL,SND_FILENAME|SND_ASYNC);
}
else
{
::PlaySound("res\\eat.wav",NULL,SND_FILENAME|SND_ASYNC);
}
//AfxMessageBox(_T("A wins the game"));
GetDocument()->m_chessMap.ResetStatePos(nPosY,nPosX,GetDocument()->m_pOldRole);
theArr.Set(uOldRow,uOldCol,0);
theArr.Set(nPosY,nPosX,1);
//theArr.Show();
// InvalidateRect(NULL,true);
// GetDocument()->m_chessMap.Show();
// GetDocument()->m_cpPaper.Draw(&dc);
//GetDocument()->m_chessMap.Draw(&dc);
//GetDocument()->m_pOldRole->Draw(&dc);
GetDocument()->m_nWhoPlayNow=2;//輪到B下了
CChessMan::m_stcChosenID=-1;
GetDocument()->m_nSelected=0;
// m_bIfAFinished=true;
GetDocument()->m_pOldRole->InvalidateMyRect(&dc,uOldRow,uOldCol);///局部重繪
GetDocument()->m_cpPaper.Draw(&dc);
GetDocument()->m_chessMap.Draw(&dc);
m_bIfACanGo=false;
::AfxGetMainWnd()->KillTimer(1);
::AfxGetMainWnd()->SetTimer(2,1000,NULL);
CString myStr;
myStr.Format("已走步數: %d",GetDocument()->m_chessMap.m_nSteps);
pDC->TextOut(0,0,myStr);
//str.Format(_T("nPosX: %d,nPosY %d,ID %d"),GetDocument()->m_pOldRole->uRow,GetDocument()->m_pOldRole->uCol,GetDocument()->m_pOldRole->m_uRoleID);
//AfxMessageBox(str);
}
}
}
}
}
else if(2==GetDocument()->m_nWhoPlayNow)//表示是B方下了
{
if (!m_bMessFrom)
{
return;
}
m_bMessFrom=false;
if (0==GetDocument()->m_nSelected)//表示B準備選擇了這個棋子了
{
if (pCurrentChess)
{
if (pCurrentChess->m_uRoleID>=17)//剛好選中的子就是B方的
{
GetDocument()->m_nSelected=2;//表示B方已經選擇了棋子了
pCurrentChess->ShowIAmHere(&dc);
::PlaySound("res\\select.wav",NULL,SND_FILENAME|SND_ASYNC);
GetDocument()->m_pOldRole=pCurrentChess;//保存這個棋子以決定下一次有效單擊該怎么做
}
else
{
//do nothing//
}
}
}
else if(2==GetDocument()->m_nSelected)//表示B已經選中了一個棋子了
{
if (pCurrentChess&&pCurrentChess->m_uRoleID>=17)//表示下一步點的是自己家的子,這個時候只進行選中切換
{
CChessMan::m_stcChosenID=pCurrentChess->m_uRoleID;
GetDocument()->m_pOldRole->InvalidateMyRect(&dc);
GetDocument()->m_cpPaper.Draw(&dc);
GetDocument()->m_chessMap.Draw(&dc);
GetDocument()->m_pOldRole=pCurrentChess;
//InvalidateRect(NULL,true);
::PlaySound("res\\select.wav",NULL,SND_FILENAME|SND_ASYNC);
}
else
{
if (GetDocument()->m_chessMap.IfManInMidOfHead(GetDocument()->m_pOldRole->uRow,GetDocument()->m_pOldRole->uCol))
{
if (nPosX!=GetDocument()->m_pOldRole->uCol)////這里是用來判斷兩個將之間只有一個子的情況
{
AfxMessageBox(_T("對不起只能上下移動"));
return;
}
}
/*
if (GetDocument()->m_pOldRole->m_uRoleID==32)////判斷將的下一步是不是可以走,如果不可以走的話就提示不可以走的
{
bool bLegal=GetDocument()->m_chessMap.IfHeadCanGo(GetDocument()->m_pOldRole,point,2);
if (!bLegal)
{
AfxMessageBox(_T("這個地方太危險,不能走的"));
return ;
}
}*/
UINT uOldRow,uOldCol;
uOldRow=GetDocument()->m_pOldRole->uRow;
uOldCol=GetDocument()->m_pOldRole->uCol;
bool bIfLegal=GetDocument()->m_pOldRole->IfNextPosLegal(point);//返回true表示下一步是合法的
if(bIfLegal)
{
/*
if (!GetDocument()->m_chessMap.IfHeadSafe(GetDocument()->m_pOldRole,nPosY,nPosX))
{
AfxMessageBox(_T("你走了你的將就不安全了,不能走的"));
return ;
}*/
if (GetDocument()->m_pOldRole->m_uRoleID==32)////判斷將的下一步是不是可以走,如果不可以走的話就提示不可以走的
{
bool bLegal=GetDocument()->m_chessMap.IfHeadCanGo(GetDocument()->m_pOldRole,point,2);
if (!bLegal)
{
AfxMessageBox(_T("將和將是不可以直接面對面的"));
return ;
}
}
//GetDocument()->m_pOldRole->GetRect(rect);
bool bResult= GetDocument()->m_pOldRole->NextStep(pCurrentChess,nPosY,nPosX);
if (true==bResult)//表示B方已經下了
{
StSaveInfo HelpSaveInfo;
if (GetDocument()->m_chessMap.TheStateOfAllChess[nPosY][nPosX]!=NULL)
{
HelpSaveInfo.uTargetId=GetDocument()->m_chessMap.TheStateOfAllChess[nPosY][nPosX]->m_uRoleID;
}
else
{
HelpSaveInfo.uTargetId=0;
}
//GetDocument()->m_chessMap.ResetStatePos(GetDocument()->m_pOldRole->uRow,GetDocument()->m_pOldRole->uCol,NULL);
GetDocument()->m_chessMap.ResetStatePos(uOldRow,uOldCol,NULL);
GetDocument()->m_chessMap.m_nSteps++;
HelpSaveInfo.uRoleId=GetDocument()->m_pOldRole->m_uRoleID;
HelpSaveInfo.uOldRow=uOldRow;
HelpSaveInfo.uOldCol=uOldCol;
HelpSaveInfo.uNewRow=nPosY;
HelpSaveInfo.uNewCol=nPosX;
GetDocument()->m_CSave.push(HelpSaveInfo);
GetDocument()->m_CSave.SaveChess();
if(pCurrentChess&&pCurrentChess->m_uRoleID==16)
{
::PlaySound("res\\gamewin.wav",NULL,SND_FILENAME|SND_ASYNC);
AfxMessageBox(_T("B wins the game"));
CMainFrame *pMainFrame=(CMainFrame*)AfxGetMainWnd();
CClientDC dc=CClientDC(this);
pMainFrame->Timer1->SetToZero(&dc,0);
pMainFrame->Timer2->SetToZero(&dc,300);
setJISHIToZero=true;
::AfxGetMainWnd()->KillTimer(1);
::AfxGetMainWnd()->KillTimer(2);
m_bIfLButtonDownMe=true;//默認表示是自己的單擊
m_bIfACanGo=true;
m_TalkDlg=false;
m_bIfStart=false;
m_bHeStart=false;
GetDocument()->m_chessMap.Clear();
UINT ifSave;
ifSave=MessageBox("Do you want to save? Yes/No?","Save the File",MB_YESNO);
if (ifSave==IDYES)
{
OnFileSaveas();
GetDocument()->OnNewDocument();
InvalidateRect(NULL,true);
}
else
{
GetDocument()->OnNewDocument();
InvalidateRect(NULL,true);
}
return;
}
if (!pCurrentChess)
{
::PlaySound("res\\go.wav",NULL,SND_FILENAME|SND_ASYNC);
}
else
{
::PlaySound("res\\eat.wav",NULL,SND_FILENAME|SND_ASYNC);
}
GetDocument()->m_chessMap.ResetStatePos(nPosY,nPosX,GetDocument()->m_pOldRole);
//InvalidateRect(NULL,true);
theArr.Set(uOldRow,uOldCol,0);
theArr.Set(nPosY,nPosX,2);
// GetDocument()->m_cpPaper.Draw(&dc);
//GetDocument()->m_chessMap.Draw(&dc);
//GetDocument()->m_pOldRole->Draw(&dc);
GetDocument()->m_nWhoPlayNow=1;//輪到A下了
CChessMan::m_stcChosenID=-1;
GetDocument()->m_nSelected=0;
GetDocument()->m_pOldRole->InvalidateMyRect(&dc,uOldRow,uOldCol);///局部重繪
GetDocument()->m_cpPaper.Draw(&dc);
GetDocument()->m_chessMap.Draw( &dc);
::AfxGetMainWnd()->SetTimer(1,1000,NULL);
::AfxGetMainWnd()->KillTimer(2);
CString myStr;
myStr.Format("已走步數: %d",GetDocument()->m_chessMap.m_nSteps);
pDC->TextOut(0,0,myStr);
//str.Format(_T("nPosX: %d,nPosY %d"),GetDocument()->m_pOldRole->uRow,GetDocument()->m_pOldRole->uCol);
//AfxMessageBox(str);
}
}
}
}
}
//}
m_bIfLButtonDownMe=true;
}
CView::OnLButtonDown(nFlags, point);
delete pDC;
}
void CMyChessView::OnHelpConect()
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -