📄 cchessuidlg.cpp
字号:
{
nCur = RED_B4;
Other[0]= RED_B1;
Other[1]= RED_B2;
Other[2]= RED_B3;
Other[3]= RED_B5;
}
if( RED_B5 == nSourceID )
{
nCur = RED_B5;
Other[0]= RED_B1;
Other[1]= RED_B2;
Other[2]= RED_B3;
Other[3]= RED_B4;
}
for(i=0;i<4;i++)
{
if(ptChess[nCur].x == ptChess[Other[i]].x)
count_X++;
if(ptChess[nCur].y < ptChess[Other[i]].y)
count_Y++;
if( 2 == count_X) //只有两个兵在相同纵坐标
{
if(ptChess[nCur].y < ptChess[Other[i]].y)
{
if(nToY > nFromY)
{
Str="红:前兵进"+ConvertDigit(0);
}
if(nToY == nFromY)
{
Str="红:前兵平"+ConvertDigit(8-nToX);
}
}
else
{
if(nToY > nFromY)
{
Str="红:后兵进"+ConvertDigit(0);
}
if(nToY == nFromY)
{
Str="红:后兵平"+ConvertDigit(8-nToX);
}
}
break;
}
}
if( count_X > 2 ) //有三个或三个以上的兵在相同纵坐标
{
if(nToY > nFromY)
Str="红:"+ConvertDigit(count_Y-1)+"兵进"+ConvertDigit(0);
if(nFromY==nToY)
Str="红:"+ConvertDigit(count_Y-1)+"兵平"+ConvertDigit(8-nToX);
}
if( 1 == count_X ) //所有的兵都在不同的纵坐标
{
if(nFromY==nToY)
Str="红:兵"+ConvertDigit(8-nFromX)+"平"+ConvertDigit(8-nToX);
else
Str="红:兵"+ConvertDigit(8-nFromX)+"进"+ConvertDigit(0);
}
break;
//黑卒
case BLACK_B1:
case BLACK_B2:
case BLACK_B3:
case BLACK_B4:
case BLACK_B5:
count_X = 1;
count_Y = 0;
if( BLACK_B1 == nSourceID )
{
nCur = BLACK_B1;
Other[0]= BLACK_B2;
Other[1]= BLACK_B3;
Other[2]= BLACK_B4;
Other[3]= BLACK_B5;
}
if( BLACK_B2 == nSourceID )
{
nCur = BLACK_B2;
Other[0]= BLACK_B1;
Other[1]= BLACK_B3;
Other[2]= BLACK_B4;
Other[3]= BLACK_B5;
}
if( BLACK_B3 == nSourceID )
{
nCur = BLACK_B3;
Other[0]= BLACK_B1;
Other[1]= BLACK_B2;
Other[2]= BLACK_B4;
Other[3]= BLACK_B5;
}
if( BLACK_B4 == nSourceID )
{
nCur = BLACK_B4;
Other[0]= BLACK_B1;
Other[1]= BLACK_B2;
Other[2]= BLACK_B3;
Other[3]= BLACK_B5;
}
if( BLACK_B5 == nSourceID )
{
nCur = BLACK_B5;
Other[0]= BLACK_B1;
Other[1]= BLACK_B2;
Other[2]= BLACK_B3;
Other[3]= BLACK_B4;
}
for(i=0;i<4;i++)
{
if(ptChess[nCur].x == ptChess[Other[i]].x)
count_X++;
if(ptChess[nCur].y < ptChess[Other[i]].y)
count_Y++;
if( 2 == count_X) //只有两个兵在相同纵坐标
{
if(ptChess[nCur].y < ptChess[Other[i]].y)
{
if(nToY > nFromY)
{
Str.Format("黑:前卒进1");
}
if(nToY == nFromY)
{
Str.Format("黑:前卒平%d",nToX+1);
}
}
else
{
if(nToY > nFromY)
{
Str.Format("黑:后卒进1");
}
if(nToY == nFromY)
{
Str.Format("黑:后卒平%d",nToX+1);
}
}
break;
}
}
if( count_X > 2 ) //有三个或三个以上的兵在相同纵坐标
{
if(nToY > nFromY)
Str.Format("黑:%d卒进1",count_Y-1);
if(nFromY==nToY)
Str.Format("黑:%d卒平%d",count_Y-1,nToX+1);
}
if( 1 == count_X ) //所有的兵都在不同的纵坐标
{
if(nFromY==nToY)
Str.Format("黑:卒%d平%d",nFromX+1,nToX+1);
else
Str.Format("黑:卒%d进1",nFromX+1);
}
break;
default:
break;
}
return Str;
}
/*
inline void PushMoveStack(POINT ptFrom, POINT ptTo, int nChessID)
{
MOVESTACK[nMoveStackCount].nChessID =nChessID;
MOVESTACK[nMoveStackCount].ptFrom =ptFrom;
MOVESTACK[nMoveStackCount].ptTo =ptTo;
nMoveStackCount++;
}
*/
void CCChessUIDlg::OnMenuNewGame()
{
// TODO: 在此添加命令处理程序代码
Restart();
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CCChessUIDlg::OnMenuQuit()
{
// TODO: 在此添加命令处理程序代码
if(MessageBox("你确定要退出吗?","确认",MB_OKCANCEL)==IDOK)
{
EndDialog(IDCANCEL);
}
}
void CCChessUIDlg::OnAbout()
{
// TODO: 在此添加命令处理程序代码
CAboutDlg dlg;
dlg.DoModal();
}
void CCChessUIDlg::OnSetEngine()
{
// TODO: 在此添加命令处理程序代码
m_SetDlg.DoModal();
}
void CCChessUIDlg::OnTimer(UINT nIDEvent)
{
if(nIDEvent == 1)
{
Second_a2++;
Second_a= (int)Second_a2/10;
if (Second_a>=60)
{
Minute_a = Second_a/60;
Second_a = Second_a%60;
if(Minute_a>=60)
Hour_a = Minute_a/60;
Minute_a= Minute_a%60;
}
CString SSecond_a;
CString MMinute_a;
CString HHour_a;
SSecond_a.Format("%02d",Second_a);
MMinute_a.Format("%02d",Minute_a);
HHour_a.Format("%02d",Hour_a);
GetDlgItem(IDC_STATIC3)->SetWindowText(HHour_a+":"+MMinute_a+":"+SSecond_a);
}
if(nIDEvent ==2)
{
if( !fSearchOver )
{
Second_b2++;
Second_b= (int)Second_b2/10;
if (Second_b>=60)
{
Minute_b = Second_b/60;
Second_b = Second_b%60;
if(Minute_b>=60)
Hour_b = Minute_b/60;
Minute_b=Minute_b%60;
}
CString SSecond_b;
CString MMinute_b;
CString HHour_b;
SSecond_b.Format("%02d",Second_b);
MMinute_b.Format("%02d",Minute_b);
HHour_b.Format("%02d",Hour_b);
GetDlgItem(IDC_STATIC4)->SetWindowText(HHour_b+":"+MMinute_b+":"+SSecond_b);
}
if( bThreadOver == true )
{
bThreadOver = false;
//刷新屏幕
InvalidateRect(&rctPreR,FALSE);
InvalidateRect(&rctCurR,FALSE);
InvalidateRect(&rctPreB,FALSE);
InvalidateRect(&rctCurB,FALSE);
if( nObject != NOCHESS )
{
if(IsGameOverUI() == REDWIN)
{
MessageBox("大侠果真厉害,小弟甘拜下风!","游戏结束",MB_OK);
GameOver();
}
if(IsGameOverUI() == BLACKWIN)
{
MessageBox("老兄,看来你不行嘛。","游戏结束",MB_OK);
GameOver();
}
}
}
}
CDialog::OnTimer(nIDEvent);
}
void CCChessUIDlg::OnBnClickedButton1()//悔棋
{
if( WhoseTurn != RED )
{
return;
}
CString strTemp;
pLB->GetText( pLB->GetCount()-1, strTemp );
vNameQueue.push_back( strTemp );
pLB->DeleteString(pLB->GetCount()-1);
pLB->PostMessage(WM_VSCROLL,SB_BOTTOM,0);
pLB->GetText( pLB->GetCount()-1, strTemp );
vNameQueue.push_back( strTemp );
pLB->DeleteString(pLB->GetCount()-1);
pLB->PostMessage(WM_VSCROLL,SB_BOTTOM,0);
nNumOfStep--;
//////////////////////////////////////////
for (int i = 0; i<9; i++)
{
for (int j = 0; j<10;j++)
{
temp.CChessBoard[i][j] = CChessBoard[i][j];
}
}
for (int i=0; i<32;i++)
{
temp.ptChess[i] = ptChess[i];
}
//temp.ptCurKuang = ptCurKuang;
//temp.ptPreKuang = ptPreKuang;
/*
temp.ptCurKuang.x = -100;
temp.ptCurKuang.y = -100;
temp.ptPreKuang.x = -100;
temp.ptPreKuang.y = -100;
*/
vForwardQueue.push_back(temp);
///////////////////////////////////////
temp = vBackQueue.back();
for (int i = 0; i<9; i++)
{
for (int j = 0; j<10;j++)
{
CChessBoard[i][j] = temp.CChessBoard[i][j];
}
}
for (int i=0; i<32;i++)
{
ptChess[i] = temp.ptChess[i];
}
//ptPreKuang = temp.ptPreKuang;
//ptCurKuang = temp.ptCurKuang;
ptPreKuang.x = -100;
ptPreKuang.y = -100;
ptCurKuang.x = -100;
ptCurKuang.y = -100;
vBackQueue.pop_back();
cb1.EnableWindow(!vBackQueue.empty());
cb2.EnableWindow(!vForwardQueue.empty());
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
//BackMove();
//BackMove();
}
void CCChessUIDlg::OnBnClickedButton2()//还原
{
// TODO: 在此添加控件通知处理程序代码
if( WhoseTurn != RED )
{
return;
}
nNumOfStep++;
//////////////////////////////////////////
for (int i = 0; i<9; i++)
{
for (int j = 0; j<10;j++)
{
temp.CChessBoard[i][j] = CChessBoard[i][j];
}
}
for (int i=0; i<32;i++)
{
temp.ptChess[i] = ptChess[i];
}
//temp.ptCurKuang = ptCurKuang;
//temp.ptPreKuang = ptPreKuang;
vBackQueue.push_back(temp);
///////////////////////////////
temp = vForwardQueue.back();
for (int i = 0; i<9; i++)
{
for (int j = 0; j<10;j++)
{
CChessBoard[i][j] = temp.CChessBoard[i][j];
}
}
for (int i=0; i<32;i++)
{
ptChess[i] = temp.ptChess[i];
}
//ptPreKuang = temp.ptPreKuang;
//ptCurKuang = temp.ptCurKuang;
ptPreKuang.x = -100;
ptPreKuang.y = -100;
ptCurKuang.x = -100;
ptCurKuang.y = -100;
vForwardQueue.pop_back();
cb1.EnableWindow(!vBackQueue.empty());
cb2.EnableWindow(!vForwardQueue.empty());
pLB->AddString(vNameQueue.back());
pLB->PostMessage(WM_VSCROLL,SB_BOTTOM,0);
vNameQueue.pop_back();
pLB->AddString(vNameQueue.back());
pLB->PostMessage(WM_VSCROLL,SB_BOTTOM,0);
vNameQueue.pop_back();
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CCChessUIDlg::OnNormal()
{
// TODO: Add your command handler code here
m_Mode = NORMAL;
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CCChessUIDlg::OnUpdateNormal(CCmdUI *pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_Mode==NORMAL);
}
void CCChessUIDlg::OnBlind()
{
// TODO: Add your command handler code here
m_Mode =BLIND;
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
MessageBox("您选择了盲棋模式!\n在盲棋模式下走棋方法与在普通模式下相同,\n只需用鼠标点击棋盘上的相应位置即可。"
,"盲棋模式", MB_ICONASTERISK );
}
void CCChessUIDlg::OnUpdateBlind(CCmdUI *pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_Mode==BLIND);
}
void CCChessUIDlg::OnstQipan()
{
// TODO: Add your command handler code here
m_Qipan =STQP;
qipan= IDB_STQP;
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CCChessUIDlg::OnUpdatestQipan(CCmdUI *pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_Qipan==STQP);
}
void CCChessUIDlg::OnsjQipan()
{
// TODO: Add your command handler code here
m_Qipan =SJQP;
qipan= IDB_SJQP;
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CCChessUIDlg::OnUpdatesjQipan(CCmdUI *pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_Qipan==SJQP);
}
void CCChessUIDlg::OnmtQipan()
{
// TODO: Add your command handler code here
m_Qipan =MTQP;
qipan= IDB_MTQP;
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CCChessUIDlg::OnUpdatemtQipan(CCmdUI *pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_Qipan==MTQP);
}
void CCChessUIDlg::OnstQizi()
{
// TODO: Add your command handler code here
m_Qizi =STQZ;
qzidir ="Pic/qizi/shitou/";
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CCChessUIDlg::OnUpdatestQizi(CCmdUI *pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_Qizi==STQZ);
}
void CCChessUIDlg::OnsjQizi()
{
// TODO: Add your command handler code here
m_Qizi =SJQZ;
qzidir ="Pic/qizi/shuijing/";
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CCChessUIDlg::OnUpdatesjQizi(CCmdUI *pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_Qizi==SJQZ);
}
void CCChessUIDlg::OnmtQizi()
{
// TODO: Add your command handler code here
m_Qizi =MTQZ;
qzidir ="Pic/qizi/mutou/";
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CCChessUIDlg::OnUpdatemtQizi(CCmdUI *pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_Qizi==MTQZ);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -