📄 mychessview.cpp
字号:
{
return;
}
m_bMessFrom=false;
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;
}
}
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方已经下了
{
// GetDocument()->m_chessMap.ResetStatePos(GetDocument()->m_pOldRole->uRow,GetDocument()->m_pOldRole->uCol,NULL);
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(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_bIfBCanGo=false;
m_TalkDlg=false;
m_bMessFrom=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;
GetDocument()->m_pOldRole->InvalidateMyRect(&dc,uOldRow,uOldCol);///局部重绘
GetDocument()->m_cpPaper.Draw(&dc);
GetDocument()->m_chessMap.Draw(&dc);
::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)
{
m_bMessFrom=false;
return;
}
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_bIfBCanGo=false;
m_TalkDlg=false;
m_bMessFrom=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);
m_bIfBCanGo=false;
::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::OnHelpConnect()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -