📄 ms5dlg.cpp
字号:
steps[stepcount].x = x;
steps[stepcount].y = y;
stepcount++;
stop = false;
Sleep(100);
InvalidateRect(thiswnd,CRect(10,10,400,400),FALSE);
/*
if (stepcount>1)
InvalidateRect(thiswnd,getpointRect(steps[stepcount-2].x,steps[stepcount-2].y),FALSE);
if (stepcount>2)
InvalidateRect(thiswnd,getpointRect(steps[stepcount-3].x,steps[stepcount-3].y),FALSE);
*/
}
}
while(is_cvsc)
{
fivestone.setthinkpos(0);
stop = true;
fivestone.setGrade(secondgrade);
fivestone.getpoint(x,y,2,false);//白棋走棋
if (x!=0)
{
if (soundeffect)
sndPlaySound("put",SND_RESOURCE|SND_ASYNC);
fivestone.points[x][y] = 2;
points[x][y] = 4;//用不同颜色表示的棋子
steps[stepcount].x = x;
steps[stepcount].y = y;
stepcount++;
stop = false;
Sleep(100);
InvalidateRect(thiswnd,CRect(10,10,400,400),FALSE);
/*
if (stepcount>1)
InvalidateRect(thiswnd,getpointRect(steps[stepcount-2].x,steps[stepcount-2].y),FALSE);
if (stepcount>2)
InvalidateRect(thiswnd,getpointRect(steps[stepcount-3].x,steps[stepcount-3].y),FALSE);
*/
}
if (!is_cvsc) break;
fivestone.setthinkpos(0);
stop = true;
fivestone.setGrade(firstgrade);
fivestone.getpoint(x,y,1,false);//黑棋走棋
if (x!=0)
{
if (soundeffect)
sndPlaySound("put",SND_RESOURCE|SND_ASYNC);
fivestone.points[x][y] = 1;
points[x][y] = 3;//用不同颜色表示的棋子
steps[stepcount].x = x;
steps[stepcount].y = y;
stepcount++;
stop = false;
Sleep(100);
InvalidateRect(thiswnd,CRect(10,10,400,400),FALSE);
/*
if (stepcount>1)
InvalidateRect(thiswnd,getpointRect(steps[stepcount-2].x,steps[stepcount-2].y),FALSE);
if (stepcount>2)
InvalidateRect(thiswnd,getpointRect(steps[stepcount-3].x,steps[stepcount-3].y),FALSE);
*/
}
}
fivestone.setGrade(grade);
return 1;
}
void CMs5Dlg::OnCvsc()
{
//这里处理电脑宝宝对下的程序
debug = false;
is_cvsc = !is_cvsc;
if (is_cvsc)
this->GetMenu()->ModifyMenu(IDM_CVSC,MF_BYCOMMAND,IDM_CVSC,"停止电脑宝宝对下");
else
{
if (cvscThread!=NULL)
{
TerminateThread(cvscThread,0);
cvscThread = NULL;
}
SetWindowText("五子棋进阶");
this->GetMenu()->ModifyMenu(IDM_CVSC,MF_BYCOMMAND,IDM_CVSC,"电脑宝宝对下");
fivestone.setGrade(grade);
this->GetMenu()->EnableMenuItem(IDM_RENREN,MF_BYCOMMAND|MF_ENABLED);
this->GetMenu()->EnableMenuItem(IDM_REGRET,MF_BYCOMMAND|MF_ENABLED);
this->GetMenu()->EnableMenuItem(IDM_START,MF_BYCOMMAND|MF_ENABLED);
if (!m_renren)
this->GetMenu()->EnableMenuItem(IDM_CHANGE,MF_BYCOMMAND|MF_ENABLED);
this->GetMenu()->EnableMenuItem(IDM_ADVICE,MF_BYCOMMAND|MF_ENABLED);
this->GetMenu()->EnableMenuItem(IDM_LOAD,MF_BYCOMMAND|MF_ENABLED);
this->GetMenu()->EnableMenuItem(IDM_SHOW,MF_BYCOMMAND|MF_ENABLED);
}
if (is_cvsc)
{
CVSCDlg cdlg;
if (cdlg.DoModal()==IDOK)
{
if (!cdlg.m_import)
{
fivestone.clear();
for(int i=1;i<=15;i++)
for(int j=1;j<=15;j++)
points[i][j] = 0;
stepcount = 0;
fivestone.points[8][8] = 1;//计算机先走
points[8][8] = 3;//计算机先走
steps[stepcount].x = 8;
steps[stepcount].y = 8;
stepcount++;
stop = false;
goblack = false;
m_pre.EnableWindow(false);
m_next.EnableWindow(false);
m_first.EnableWindow(false);
m_last.EnableWindow(false);
m_continue.EnableWindow(false);
InvalidateRect(CRect(10,10,400,400));
CWinThread *cwt = AfxBeginThread(&cvsc,NULL);
cvscThread = cwt->m_hThread;
extern int firstgrade;
extern int secondgrade;
CString s;
s.Format("五子棋进阶--现在%d级电脑宝宝黑棋vs%d级电脑宝宝白棋!",firstgrade,secondgrade);
SetWindowText(s);
this->GetMenu()->EnableMenuItem(IDM_RENREN,MF_BYCOMMAND|MF_GRAYED);
this->GetMenu()->EnableMenuItem(IDM_REGRET,MF_BYCOMMAND|MF_GRAYED);
this->GetMenu()->EnableMenuItem(IDM_START,MF_BYCOMMAND|MF_GRAYED);
this->GetMenu()->EnableMenuItem(IDM_CHANGE,MF_BYCOMMAND|MF_GRAYED);
this->GetMenu()->EnableMenuItem(IDM_ADVICE,MF_BYCOMMAND|MF_GRAYED);
this->GetMenu()->EnableMenuItem(IDM_LOAD,MF_BYCOMMAND|MF_GRAYED);
this->GetMenu()->EnableMenuItem(IDM_SHOW,MF_BYCOMMAND|MF_GRAYED);
}
else
{
//需要导入棋局
stop = false;
OnLoad();
if (!stop)
{
//load时被取消
is_cvsc = false;
if (cvscThread!=NULL)
{
TerminateThread(cvscThread,0);
cvscThread = NULL;
}
SetWindowText("五子棋进阶");
this->GetMenu()->ModifyMenu(IDM_CVSC,MF_BYCOMMAND,IDM_CVSC,"电脑宝宝对下");
fivestone.setGrade(grade);
this->GetMenu()->EnableMenuItem(IDM_RENREN,MF_BYCOMMAND|MF_ENABLED);
this->GetMenu()->EnableMenuItem(IDM_REGRET,MF_BYCOMMAND|MF_ENABLED);
this->GetMenu()->EnableMenuItem(IDM_START,MF_BYCOMMAND|MF_ENABLED);
if (!m_renren)
this->GetMenu()->EnableMenuItem(IDM_CHANGE,MF_BYCOMMAND|MF_ENABLED);
this->GetMenu()->EnableMenuItem(IDM_ADVICE,MF_BYCOMMAND|MF_ENABLED);
this->GetMenu()->EnableMenuItem(IDM_LOAD,MF_BYCOMMAND|MF_ENABLED);
this->GetMenu()->EnableMenuItem(IDM_SHOW,MF_BYCOMMAND|MF_ENABLED);
}
else
{
OnLast();
stop = false;
debug = false;
stepcount = showstep+1;
m_pre.EnableWindow(false);
m_next.EnableWindow(false);
m_first.EnableWindow(false);
m_last.EnableWindow(false);
m_continue.EnableWindow(false);
if (fivestone.points[steps[showstep].x][steps[showstep].y]==2)
{
goblack = true;
}
CWinThread *cwt = AfxBeginThread(&cvsc,NULL);
cvscThread = cwt->m_hThread;
extern int firstgrade;
extern int secondgrade;
CString s;
s.Format("五子棋进阶--现在%d级电脑宝宝黑棋vs%d级电脑宝宝白棋!",firstgrade,secondgrade);
SetWindowText(s);
this->GetMenu()->EnableMenuItem(IDM_RENREN,MF_BYCOMMAND|MF_GRAYED);
this->GetMenu()->EnableMenuItem(IDM_REGRET,MF_BYCOMMAND|MF_GRAYED);
this->GetMenu()->EnableMenuItem(IDM_START,MF_BYCOMMAND|MF_GRAYED);
this->GetMenu()->EnableMenuItem(IDM_CHANGE,MF_BYCOMMAND|MF_GRAYED);
this->GetMenu()->EnableMenuItem(IDM_ADVICE,MF_BYCOMMAND|MF_GRAYED);
this->GetMenu()->EnableMenuItem(IDM_LOAD,MF_BYCOMMAND|MF_GRAYED);
this->GetMenu()->EnableMenuItem(IDM_SHOW,MF_BYCOMMAND|MF_GRAYED);
}
}
}
else
{
is_cvsc = false;
if (cvscThread!=NULL)
{
TerminateThread(cvscThread,0);
cvscThread = NULL;
}
SetWindowText("五子棋进阶");
this->GetMenu()->ModifyMenu(IDM_CVSC,MF_BYCOMMAND,IDM_CVSC,"电脑宝宝对下");
fivestone.setGrade(grade);
this->GetMenu()->EnableMenuItem(IDM_RENREN,MF_BYCOMMAND|MF_ENABLED);
this->GetMenu()->EnableMenuItem(IDM_REGRET,MF_BYCOMMAND|MF_ENABLED);
this->GetMenu()->EnableMenuItem(IDM_START,MF_BYCOMMAND|MF_ENABLED);
if (!m_renren)
this->GetMenu()->EnableMenuItem(IDM_CHANGE,MF_BYCOMMAND|MF_ENABLED);
this->GetMenu()->EnableMenuItem(IDM_ADVICE,MF_BYCOMMAND|MF_ENABLED);
this->GetMenu()->EnableMenuItem(IDM_LOAD,MF_BYCOMMAND|MF_ENABLED);
this->GetMenu()->EnableMenuItem(IDM_SHOW,MF_BYCOMMAND|MF_ENABLED);
}
}
}
void CMs5Dlg::OnClearscore()
{
win_num = 0;
loss_num = 0;
tie_num = 0;
m_winnum.SetWindowText("0");
m_lossnum.SetWindowText("0");
m_tienum.SetWindowText("0");
updatescore("win",0);
updatescore("loss",0);
updatescore("tie",0);
SetRatio();
}
void CMs5Dlg::MyMessageBox(CString s)
{
::MessageBox(thiswnd,s,"五子棋进阶",MB_OK);
}
void CMs5Dlg::OnQiangqianmodeladdone()
{
POINT tempresult[225];
int count=0;
if (fivestone.has_qianmodel_addone(debugcolor,count,tempresult,true))
{
for(int i=0;i<count;i++)
{
fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
}
InvalidateRect(NULL,FALSE);
}
else
{
MyMessageBox("no!");
}
}
void CMs5Dlg::OnQiangqianmodel()
{
POINT tempresult[225];
int count=0;
if (fivestone.has_qianmodel(debugcolor,count,tempresult,true))
{
for(int i=0;i<count;i++)
{
fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
}
InvalidateRect(NULL,FALSE);
}
else
{
MyMessageBox("no!");
}
}
void CMs5Dlg::OnQiangtowlevelqianmodel()
{
POINT tempresult[225];
int count=0;
if (fivestone.has_twolevelqianmodel_qiang(debugcolor,count,tempresult))
{
for(int i=0;i<count;i++)
{
fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
}
InvalidateRect(NULL,FALSE);
}
else
{
MyMessageBox("no!");
}
}
void CMs5Dlg::OnShow()
{
showstep = -1;
fivestone.clear();
for(int i=1;i<=15;i++)
for(int j=1;j<=15;j++)
points[i][j] = 0;
debug = true;
stop = true;
m_pre.EnableWindow(true);
m_next.EnableWindow(true);
m_first.EnableWindow(true);
m_last.EnableWindow(true);
m_continue.EnableWindow(true);
InvalidateRect(CRect(10,10,400,400));
}
void CMs5Dlg::OnHascanfour()
{
POINT tempresult[225];
int count=0;
if (fivestone.has_canfour(debugcolor,count,tempresult))
{
for(int i=0;i<count;i++)
{
fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
}
InvalidateRect(NULL,FALSE);
}
else
{
MyMessageBox("no!");
}
}
void CMs5Dlg::OnQiangtwolevel()
{
POINT tempresult[225];
int count=0;
if (fivestone.has_twolevel_four(debugcolor,count,tempresult))
{
for(int i=0;i<count;i++)
{
fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
}
InvalidateRect(NULL,FALSE);
}
else
{
MyMessageBox("no!");
}
}
void CMs5Dlg::OnMakeqian()
{
POINT tempresult[225];
int count=0;
if (fivestone.make_qianmodel(debugcolor,count,tempresult))
{
for(int i=0;i<count;i++)
{
fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
}
InvalidateRect(NULL,FALSE);
}
else
{
MyMessageBox("no!");
}
}
void CMs5Dlg::OnSmallsubqian()
{
POINT tempresult[225];
int count=0;
fivestone.getclose_small_subqian(debugcolor,count,tempresult);
for(int i=0;i<count;i++)
{
fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
}
InvalidateRect(NULL,FALSE);
}
void CMs5Dlg::OnBeat()
{
int x=11;
int y=8;
if (fivestone.is_beatpoint(debugcolor,x,y))
{
AfxMessageBox("yes!");
}
else
{
AfxMessageBox("no!");
}
}
void CMs5Dlg::OnMakebeat()
{
POINT tempresult[225];
int count=0;
if (fivestone.make_beatpoints(debugcolor,count,tempresult))
{
for(int i=0;i<count;i++)
{
fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
}
InvalidateRect(NULL,FALSE);
}
else
{
MyMessageBox("no!");
}
}
void CMs5Dlg::OnValue()
{
fivestone.design(9,8,2);
int x1 = fivestone.value[9][8];
fivestone.design(10,8,2);
int x2 = fivestone.value[10][8];
CString s;
s.Format("%d,%d",x1,x2);
AfxMessageBox(s);
}
void CMs5Dlg::OnDefentpoint()
{
POINT tempresult[225];
int count=0;
if (fivestone.has_defent_point(debugcolor,count,tempresult))
{
for(int i=0;i<count;i++)
{
fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
}
InvalidateRect(NULL,FALSE);
}
else
{
MyMessageBox("no!");
}
}
void CMs5Dlg::OnChongtwo()
{
POINT tempresult[225];
int count=0;
if (fivestone.has_chongtwo(debugcolor,count,tempresult))
{
for(int i=0;i<count;i++)
{
fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
}
InvalidateRect(NULL,FALSE);
}
else
{
MyMessageBox("no!");
}
}
void CMs5Dlg::OnGetclosetwolevel()
{
POINT tempresult[225];
int count=0;
fivestone.getclose_twolevel(debugcolor,count,tempresult);
for(int i=0;i<count;i++)
{
fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
}
InvalidateRect(NULL,FALSE);
}
void CMs5Dlg::OnTwoleveldefent()
{
POINT tempresult[225];
int count=0;
if (fivestone.has_twolevel_defent(debugcolor,count,tempresult))
{
for(int i=0;i<count;i++)
{
fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
}
InvalidateRect(NULL,FALSE);
}
else
{
MyMessageBox("no!");
}
}
void CMs5Dlg::OnTimer(UINT nIDEvent)
{
int pos = fivestone.getthinkpos();
if (pos>100) pos = 100;
m_thinkprocess.SetPos(pos);
CDialog::OnTimer(nIDEvent);
}
void CMs5Dlg::updatescore(CString column_name, int score)
{
char str[256];
sprintf(str,"%d",score);
CDaoRecordset rs(&conn);
rs.Open(dbOpenDynaset,"select win,loss,tie from score");
if(!rs.IsEOF()){
rs.Edit();
rs.SetFieldValue(column_name,str);
rs.Update();
}
rs.Close();
}
void CMs5Dlg::OnRenren()
{
m_renren = !m_renren;
if (m_renren)
{
OnStart();
this->GetMenu()->ModifyMenu(IDM_RENREN,MF_BYCOMMAND,IDM_RENREN,"人和电脑宝宝对下");
this->GetMenu()->EnableMenuItem(IDM_CHANGE,MF_BYCOMMAND|MF_GRAYED);
}
else
{
this->GetMenu()->ModifyMenu(IDM_RENREN,MF_BYCOMMAND,IDM_RENREN,"人人对下");
this->GetMenu()->EnableMenuItem(IDM_CHANGE,MF_BYCOMMAND|MF_ENABLED);
SetWindowText("五子棋进阶");
}
}
void CMs5Dlg::OnMouseMove(UINT nFlags, CPoint point)
{
if (!stop)
{
CRect boardrect(10,10,372,365);
if (boardrect.PtInRect(point))
{
CWinApp *pApp=AfxGetApp();
HICON hIconBang=pApp->LoadCursor (IDC_CURSOR1);
SetCursor(hIconBang);
}
}
CDialog::OnMouseMove(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -