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

📄 dicedlg.cpp

📁 用vc++开发的一个经典程序:Dice。自己开发的
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		else if(player1.getScore()<player2.getScore())
		{
			player1.setRank(2);
			player2.setRank(1);
			DisplayTXT();
			info="Game over. Player2 wins.";
		}
		else 
		{
			player1.setRank(0);
			player2.setRank(0);
			DisplayTXT();
			info="Game over. Two players draw.";
		}
		DisplayInfo(info);
	}

}

//##ModelId=4507556B0041
void CDiceDlg::OnBnClickedButton2()     // re_start the game
{
	CString info;
	info="Game restarted";
	DisplayInfo(info);
	player1.setIngame(true);
	player1.setRank(0);
	player1.setRound(0);
	player1.setScore(0);
	player2.setIngame(false);
	player2.setRank(0);
	player2.setRound(0);
	player2.setScore(0);
	DisplayTXT();
		//reset
	dicebox.score=0;
	dicebox.reset();
	DisplayDice();	
}


//##ModelId=4507556B0037
void CDiceDlg::OnBnClickedButton3() 
{
	CString info;
	if((player1.getIngame()==true)&&(player2.getIngame()==false))
	{
		info="Player1 keeped score. Player2's turn.";
		DisplayInfo(info);
		player1.setIngame(false);
		player2.setIngame(true);
		DisplayTXT();
			//reset
		dicebox.score=0;
		dicebox.reset();
	}
	else if((player1.getIngame()==false)&&(player2.getIngame()==true))
	{
		//info="Player2 keeped score. Game over.";
		//DisplayInfo(info);
		player1.setIngame(false);
		player2.setIngame(false);
		DisplayTXT();
			//reset
		dicebox.score=0;
		//dicebox.reset();	
		if(player1.getScore()>player2.getScore())
		{
			player1.setRank(1);
			player2.setRank(2);
			DisplayTXT();
			info="Player2 keeped score. Game over. Player1 wins.";
		}
		else if(player1.getScore()<player2.getScore())
		{
			player1.setRank(2);
			player2.setRank(1);
			DisplayTXT();
			info="Player2 keeped score. Game over. Player2 wins.";
		}
		else 
		{
			player1.setRank(0);
			player2.setRank(0);
			DisplayTXT();
			info="Player2 keeped score. Game over. Two players draw.";
		}
		DisplayInfo(info);		
		
	}
		
}

//##ModelId=4507556B004B
void CDiceDlg::OnBnClickedButton4()    // quit game
{
	OnCancel();	
}

//##ModelId=4507556B0043
void CDiceDlg::OnBnClickedButton5()    // game rules
{
	CDialog dlgAbout(IDD_DIALOG2);
	dlgAbout.DoModal();	
}

//##ModelId=4507556B0057
void CDiceDlg::OnEnChangeEdit1() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

//##ModelId=4507556B0059
void CDiceDlg::OnEnChangeEdit2() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

//##ModelId=4507556B0060
void CDiceDlg::OnEnChangeEdit3() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}


//##ModelId=4507556B0069
void CDiceDlg::OnEnChangeEdit4() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

//##ModelId=4507556B0073
void CDiceDlg::OnEnChangeEdit5() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

//##ModelId=4507556B0075
void CDiceDlg::OnEnChangeEdit6() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

//##ModelId=4507556B007D
void CDiceDlg::OnEnChangeEdit7() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

//##ModelId=4507556B007F
void CDiceDlg::OnEnChangeEdit8() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

//##ModelId=4507556B0088
void CDiceDlg::OnEnChangeEdit9() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

//##ModelId=4507556B008A
void CDiceDlg::OnEnChangeEdit10() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

//##ModelId=4507556B0092
void CDiceDlg::OnEnChangeEdit11() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

//##ModelId=4507556B0094
void CDiceDlg::OnEnChangeEdit12() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

//##ModelId=4507556B00A5
void CDiceDlg::OnEnChangeEdit14() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

//##ModelId=4507556B00A9
void CDiceDlg::OnEnChangeEdit15() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

//##ModelId=4507556B009B
void CDiceDlg::OnEnChangeEdit13() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

//##ModelId=4507556B00B0
void CDiceDlg::OnEnChangeEdit16() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

//##ModelId=4507556B00C5
void CDiceDlg::OnEnChangeEdit17() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

//##ModelId=4507556B009D
void CDiceDlg::DisplayDice(void)
{
	//show num1
	sprintf(m_Display1.GetBuffer(24),"%d",dicebox.num1);
	m_Display1.ReleaseBuffer(-1);
	//UpdateData(FALSE);
	//show num2
	sprintf(m_Display2.GetBuffer(24),"%d",dicebox.num2);
	m_Display2.ReleaseBuffer(-1);
	//UpdateData(FALSE);
	//show num3
	sprintf(m_Display3.GetBuffer(24),"%d",dicebox.num3);
	m_Display3.ReleaseBuffer(-1);
	//UpdateData(FALSE);
	//show num4
	sprintf(m_Display4.GetBuffer(24),"%d",dicebox.num4);
	m_Display4.ReleaseBuffer(-1);
	//UpdateData(FALSE);
	//show num5
	sprintf(m_Display5.GetBuffer(24),"%d",dicebox.num5);
	m_Display5.ReleaseBuffer(-1);
	//UpdateData(FALSE);
	//show num6
	sprintf(m_Display6.GetBuffer(24),"%d",dicebox.num6);
	m_Display6.ReleaseBuffer(-1);
	//UpdateData(FALSE);

	//show avail1
	if(dicebox.avail_1==true) m_Display7=_T("true");
	else if(dicebox.avail_1==false) m_Display7=_T("false");
	//UpdateData(FALSE);
	//show avail2
	if(dicebox.avail_2==true) m_Display8=_T("true");
	else if(dicebox.avail_2==false) m_Display8=_T("false");
	//UpdateData(FALSE);
	//show avail3
	if(dicebox.avail_3==true) m_Display9=_T("true");
	else if(dicebox.avail_3==false) m_Display9=_T("false");
	//UpdateData(FALSE);
	//show avail4
	if(dicebox.avail_4==true) m_Display10=_T("true");
	else if(dicebox.avail_4==false) m_Display10=_T("false");
	//UpdateData(FALSE);
	//show avail5
	if(dicebox.avail_5==true) m_Display11=_T("true");
	else if(dicebox.avail_5==false) m_Display11=_T("false");
	//UpdateData(FALSE);
	//show avail6
	if(dicebox.avail_6==true) m_Display12=_T("true");
	else if(dicebox.avail_6==false) m_Display12=_T("false");
	UpdateData(FALSE);   // member function of class CWnd.
	                     //Update dialog controls from member variables 
}



//##ModelId=4507556B00A7
void CDiceDlg::DisplayPlayer(void)
{	bool c1=false;
	bool c2=false;
	c1=player1.getIngame();
	c2=player2.getIngame();
	if(c1==true){m_Display14="Player1";}
	else if(c2==true){m_Display14="Player2";}
	else {m_Display14="None";}
}



//##ModelId=4507556B00B2
void CDiceDlg::DisplayRound(void)
{
	//bool c1=false;
	//bool c2=false;
	//c1=player1.getIngame();
	//c2=player2.getIngame();
	if((player1.getIngame()==true)&&(player2.getIngame()==false))
	{
		CString temp;
		sprintf(temp.GetBuffer(24),"%d",player1.getRound());
		temp.ReleaseBuffer(-1);
		m_Display15=temp;
	}
	else if((player1.getIngame()==false)&&(player2.getIngame()==true))
	{
		CString temp;
		sprintf(temp.GetBuffer(24),"%d",player2.getRound());
		temp.ReleaseBuffer(-1);
		m_Display15=temp;
	}
	else {m_Display15="over";}
}

//##ModelId=4507556B00BA
void CDiceDlg::DisplayScore(void)
{	CString temp1,temp2;
	sprintf(temp1.GetBuffer(24),"%d",player1.getScore());
	temp1.ReleaseBuffer(-1);
	sprintf(temp2.GetBuffer(24),"%d",player2.getScore());
	temp2.ReleaseBuffer(-1);
	m_Display13=" Player1: "+temp1+"        Player2: "+temp2;
}

//##ModelId=4507556B00BC
void CDiceDlg::DisplayRank(void)
{
	CString temp1,temp2;
	sprintf(temp1.GetBuffer(24),"%d",player1.getRank());
	temp1.ReleaseBuffer(-1);
	sprintf(temp2.GetBuffer(24),"%d",player2.getRank());
	temp2.ReleaseBuffer(-1);
	m_Display16=" Player1: "+temp1+"        Player2: "+temp2;
}

//##ModelId=4507556B00C3
void CDiceDlg::DisplayTXT(void)
{
	DisplayPlayer();
	DisplayRound();
	DisplayScore();
	DisplayRank();
	UpdateData(FALSE);
}

//##ModelId=4507556B00CD
void CDiceDlg::DisplayInfo(CString msg)
{
	m_Display17=msg;
	UpdateData(FALSE);
}

⌨️ 快捷键说明

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