⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ms5dlg.cpp

📁 该工程是一个非常完整的,优化的五子棋源代码(VC),可以帮你学习路径选择算法和vc编程.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
				if (stepcount%2==1)//黑子
				{
					fivestone.points[tempx][tempy] = 1;
					points[tempx][tempy] = 1;
				}
				else
				{
					fivestone.points[tempx][tempy] = 2;
					points[tempx][tempy] = 2;
				}
				*/
			}				
		}		
		fs.close();		
		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);
	} 		
}

void CMs5Dlg::OnRegret() 
{
	//悔棋
	if (!m_renren)
	{
		if (stepcount>=2)
		{
			if (soundeffect)
				sndPlaySound("regret",SND_RESOURCE|SND_ASYNC);
			fivestone.points[steps[stepcount-1].x][steps[stepcount-1].y] = 0;
			fivestone.points[steps[stepcount-2].x][steps[stepcount-2].y] = 0;
			points[steps[stepcount-1].x][steps[stepcount-1].y] = 0;
			points[steps[stepcount-2].x][steps[stepcount-2].y] = 0;
			InvalidateRect(getpointRect(steps[stepcount-1].x,steps[stepcount-1].y));
			InvalidateRect(getpointRect(steps[stepcount-2].x,steps[stepcount-2].y));
			stepcount = stepcount-2;
		}	
	}
	else
	{
		//在人人对下模式下,一次只要悔一步棋
		if (stepcount>=1)
		{
			if (soundeffect)
				sndPlaySound("regret",SND_RESOURCE|SND_ASYNC);
			fivestone.points[steps[stepcount-1].x][steps[stepcount-1].y] = 0;			
			points[steps[stepcount-1].x][steps[stepcount-1].y] = 0;			
			InvalidateRect(getpointRect(steps[stepcount-1].x,steps[stepcount-1].y));			
			stepcount = stepcount-1;
			if (stepcount%2==0) SetWindowText("五子棋进阶--现在该黑棋走棋!");
			else SetWindowText("五子棋进阶--现在该白棋走棋!");
		}	
		
	}
	
}

void CMs5Dlg::OnQianmodel() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_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::OnQianaddone() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_qianmodel_addone(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::OnPre() 
{
	//stop = true;		
	//不允许再放子了,进入观赏模式
	if (showstep<0) return;	
	fivestone.points[steps[showstep].x][steps[showstep].y] = 0;
	points[steps[showstep].x][steps[showstep].y] = 0;		
	InvalidateRect(getpointRect(steps[showstep].x,steps[showstep].y));
	showstep--;//演示到的步数
}

void CMs5Dlg::OnNext() 
{
	//stop = true;		
	//不允许再放子了,进入观赏模式
	if ((showstep+1)>=stepcount) {
		if (first)//计算机先走
		{
			if (fivestone.points[steps[stepcount-1].x][steps[stepcount-1].y]==1)
			{
				//最后一个子是黑子,说明计算机赢了
				if (fivestone.has_five(1))
					MyMessageBox("计算机获胜!");
			}
			else if (fivestone.has_five(2)) MyMessageBox("人获胜!");
		}
		else
		{
			if (fivestone.points[steps[stepcount-1].x][steps[stepcount-1].y]==1)
			{
				//最后一个子是黑子,说明人赢了
				if (fivestone.has_five(1))
					MyMessageBox("人获胜!");
			}
			else if (fivestone.has_five(2)) MyMessageBox("计算机获胜!");
		}
		return;
	}
	showstep++;//演示到的步数
	if (showstep%2==0)//黑子
	{
		fivestone.points[steps[showstep].x][steps[showstep].y] = 1;
		points[steps[showstep].x][steps[showstep].y] = 1;
	}
	else
	{
		fivestone.points[steps[showstep].x][steps[showstep].y] = 2;
		points[steps[showstep].x][steps[showstep].y] = 2;
	}
	InvalidateRect(getpointRect(steps[showstep].x,steps[showstep].y),FALSE);
}

void CMs5Dlg::OnFirst() 
{
	//stop = true;		
	//不允许再放子了,进入观赏模式
	fivestone.clear();
	for(int i=1;i<=15;i++)
		for(int j=1;j<=15;j++)
			points[i][j] = 0;
	showstep = 0;
	fivestone.points[steps[showstep].x][steps[showstep].y] = 1;
	points[steps[showstep].x][steps[showstep].y] = 1;	
	InvalidateRect(CRect(10,10,400,400));	
}

void CMs5Dlg::OnLast() 
{
	//stop = true;
	for (showstep=0;showstep<stepcount;showstep++)
	{
		if (showstep%2==0)//黑子
		{
			fivestone.points[steps[showstep].x][steps[showstep].y] = 1;
			points[steps[showstep].x][steps[showstep].y] = 1;
		}
		else
		{
			fivestone.points[steps[showstep].x][steps[showstep].y] = 2;
			points[steps[showstep].x][steps[showstep].y] = 2;
		}	
	}
	showstep--;
	InvalidateRect(CRect(10,10,400,400),FALSE);
}

void CMs5Dlg::OnContinue() 
{
	if (fivestone.has_five(1)||fivestone.has_five(2))
	{
		MyMessageBox("已经分出胜负,请点击上一步!");
	}
	else
	{
		if (first)
		{
			//计算机先走,执黑
			if ((m_renren)||(fivestone.points[steps[showstep].x][steps[showstep].y] == 1))
			{
				//当前显示的是黑子,那么应该人走棋,这时可以断点续玩
				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);
			}
			else 
			{
				MyMessageBox("下一步应该计算机走,不能断点续玩,请点击上一步或下一步!");
			}
		}
		else
		{
			//计算机后走,执白
			if ((m_renren)||(fivestone.points[steps[showstep].x][steps[showstep].y] == 2))
			{
				//当前显示的是白子,那么应该人走棋,这时可以断点续玩
				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);
			}
			else
			{
				MyMessageBox("下一步应该计算机走,不能断点续玩,请点击上一步或下一步!");
			}
		}
	}	
}

void CMs5Dlg::OnTwolevelqianmodel() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_twolevel_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::OnDebugqian() 
{
	extern BOOL debugqian;
	debugqian = !debugqian;
	
}

void CMs5Dlg::OnHasfive() 
{
	if (fivestone.has_five(debugcolor))
	{
		MyMessageBox("yes!");
	}
	else
	{
		MyMessageBox("no!");
	}
	
}

void CMs5Dlg::OnDefent() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_qianmodel_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::OnDebugchange() 
{
	if (debugcolor==1)
	{
		debugcolor = 2;
		this->GetMenu()->ModifyMenu(IDM_DEBUGCHANGE,MF_BYCOMMAND,IDM_DEBUGCHANGE,"现在调试白棋");
	}
	else 
	{
		debugcolor = 1;
		this->GetMenu()->ModifyMenu(IDM_DEBUGCHANGE,MF_BYCOMMAND,IDM_DEBUGCHANGE,"现在调试黑棋");
	}
}

void CMs5Dlg::OnSub() 
{
	POINT tempresult[225];
	int count;
	fivestone.getclose_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::OnTwomodel() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_twoqianmodel(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::OnThreeqianmodel() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_threelevel_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::SetRatio()
{
	int total = win_num+loss_num+tie_num;
	if (total==0)
	{
		m_winratio.SetWindowText("0%");
		m_lossratio.SetWindowText("0%");
		m_tieratio.SetWindowText("0%");
	}
	else
	{
		CString s;
		s.Format("%.1f%%",(double)(win_num*100)/(double)total);
		m_winratio.SetWindowText(s);
		s.Format("%.1f%%",(double)(loss_num*100)/(double)total);
		m_lossratio.SetWindowText(s);
		s.Format("%.1f%%",(double)(tie_num*100)/(double)total);
		m_tieratio.SetWindowText(s);
	}
}

HBRUSH CMs5Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	if (nCtlColor==CTLCOLOR_DLG)
		return m_brush;	
	if (nCtlColor==CTLCOLOR_STATIC) 
	{	
		if (!pWnd->IsKindOf( RUNTIME_CLASS( CEdit )))
		{
			pDC->SetBkMode(TRANSPARENT);
			return m_brush;
		}
	}
	return hbr;
}

void CMs5Dlg::OnGrade1() 
{
	grade = 1;	
	fivestone.setGrade(grade);
	this->GetMenu()->CheckMenuItem(IDM_GRADE1,MF_BYCOMMAND|MF_CHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE2,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE3,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE4,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE5,MF_BYCOMMAND|MF_UNCHECKED);
	InvalidateRect(CRect(406,49,600,240));
}

void CMs5Dlg::OnGrade2() 
{
	grade = 2;
	fivestone.setGrade(grade);
	this->GetMenu()->CheckMenuItem(IDM_GRADE1,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE2,MF_BYCOMMAND|MF_CHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE3,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE4,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE5,MF_BYCOMMAND|MF_UNCHECKED);
	InvalidateRect(CRect(406,49,600,240));
}

void CMs5Dlg::OnGrade3() 
{
	grade = 3;	
	fivestone.setGrade(grade);
	this->GetMenu()->CheckMenuItem(IDM_GRADE1,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE2,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE3,MF_BYCOMMAND|MF_CHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE4,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE5,MF_BYCOMMAND|MF_UNCHECKED);
	InvalidateRect(CRect(406,49,600,240));
}

void CMs5Dlg::OnGrade4() 
{
	grade = 4;	
	fivestone.setGrade(grade);
	this->GetMenu()->CheckMenuItem(IDM_GRADE1,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE2,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE3,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE4,MF_BYCOMMAND|MF_CHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE5,MF_BYCOMMAND|MF_UNCHECKED);
	InvalidateRect(CRect(406,49,600,240));
}

void CMs5Dlg::OnGrade5() 
{
	grade = 5;	
	fivestone.setGrade(grade);
	this->GetMenu()->CheckMenuItem(IDM_GRADE1,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE2,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE3,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE4,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE5,MF_BYCOMMAND|MF_CHECKED);
	InvalidateRect(CRect(406,49,600,240));
}

void CMs5Dlg::OnAbout() 
{
	CAbout cad;
	cad.DoModal();
}

void CMs5Dlg::OnSound() 
{
	soundeffect = !soundeffect;	
	if (soundeffect)
	{
		this->GetMenu()->ModifyMenu(IDM_SOUND,MF_BYCOMMAND,IDM_SOUND,"去掉音效");
	}	
	else
	{
		this->GetMenu()->ModifyMenu(IDM_SOUND,MF_BYCOMMAND,IDM_SOUND,"使用音效");
	}
}

void CMs5Dlg::OnBeatpoint() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_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::OnMaketwoalive() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.make_twoalive(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::OnTwolevelbeat() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_twolevel_beat(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!");
	}				
}

UINT cvsc(LPVOID pParam)
{
	extern int firstgrade;
	extern int secondgrade;
	int x,y;//计算机走的子
	if (goblack)
	{
		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;//用不同颜色表示的棋子

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -