所以我写了一个模拟骰子游戏的程序,几乎就像掷骰子的游戏。我想把这个普通的控制台应用程序变成一个基于对话的 MFC。所以我会创建一个标记为“滚动”的按钮,窗口会显示两个骰子正在滚动。这是我为 condole 应用程序提供的代码。它工作得很好,但我很困惑如何将代码分配给按钮以及如何将模具面分配给其各自的位图。感谢您的帮助!
//Game of chance "Craps"
#include "stdafx.h"
using namespace std;
void dice(void)
{
//variables
string input;
int i,roll,gamePoint,val,val_1,val_2,roll_1,roll_2,sumRoll;
long winnings,losses,wager,odds,oddsNumer,oddsDenom;
bool A=false;
//declarations
roll=0;gamePoint=0;val=0;val_1=0;val_2=0;roll_1=0;roll_2=0;sumRoll=0;
//user input
cout<<"Enter your odds ratio:\nNumerator: ";
cin>>oddsNumer;
cout<<setw(8)<<"Denominator: ";
cin>>oddsDenom;
cout<<"Enter your wager for the game: ";
cin>>wager;
odds=abs((oddsNumer/oddsDenom)+1);
winnings=abs(odds*wager-wager);
cout<<winnings;
//dice output
do
{
srand (unsigned(time(NULL)));
sumRoll=0;
for(i=0;i<2;i++)
{
val_1=rollDice();
//cout<<"***test1***";
switch (val_1)
{//start switch
case 1:
dieFace(val_1);
break;
case 2:
dieFace(val_1);
break;
case 3:
dieFace(val_1);
break;
case 4:
dieFace(val_1);
break;
case 5:
dieFace(val_1);
break;
case 6:
dieFace(val_1);
break;
}//end switch
sumRoll=val_1+sumRoll;
}//end for loop dice roll
cout<<endl<<endl<<"\tYou rolled a: "<<sumRoll<<endl;
system("pause");
if (sumRoll==7 ||sumRoll==11)
{
cout<<"Hurray! You win!\n"<<
"Your total winnings: $"<<winnings<<endl;
A=true;
system("pause");
}//and if winner statement
else if(sumRoll==2 ||sumRoll==3||sumRoll==12)
{
losses=abs(odds*wager);
cout<<"Sorry, you lose. The house wins. Total lost is $"<<
losses<<endl;
A=true;
system("pause");
}
else
{
gamePoint=sumRoll;
roll=0;
do
{
srand (unsigned(time(NULL)));
sumRoll=0;
roll++;
for(i=0;i<2;i++)
{
val_1=rollDice();
switch (val_1)
{//start switch
case 1:
dieFace(val_1);
break;
case 2:
dieFace(val_1);
break;
case 3:
dieFace(val_1);
break;
case 4:
dieFace(val_1);
break;
case 5:
dieFace(val_1);
break;
case 6:
dieFace(val_1);
break;
}//end switch
sumRoll=val_1+sumRoll;
}//end for loop dice roll
cout<<endl<<endl<<"\tYou rolled a: "<<sumRoll<<endl;
system("pause");
if (sumRoll==7)
{
losses=abs(wager*roll*odds);
cout<<"Sorry, you lose. The house wins."<<
"Total lost is $"<<losses<<endl;
A=true;
system("pause");
}
else if(sumRoll==gamePoint)
{
winnings=abs(wager*roll*odds-wager);
cout<<"Hurray! You win!\n"<<
"Your total winnings are $"<<winnings<<endl;
A=true;
system("pause");
}
}while(A==false);
}
}while(A==false);
system("pause");
system("cls");
return ;
}
int rollDice(void)
{
//srand (unsigned(time(0)));
return((rand()%6)+1);
}
void dieFace(int val)
{
switch (val)
{//start switch
case 1:
cout<<endl<<endl<<endl;
cout<<" *************"<<endl;
cout<<" * *"<<endl;
cout<<" * *"<<endl;
cout<<" * O *"<<endl;
cout<<" * *"<<endl;
cout<<" * *"<<endl;
cout<<" *************"<<endl<<endl;
break;
case 2:
cout<<endl<<endl<<endl;
cout<<" *************"<<endl;
cout<<" * O *"<<endl;
cout<<" * *"<<endl;
cout<<" * *"<<endl;
cout<<" * *"<<endl;
cout<<" * O *"<<endl;
cout<<" *************"<<endl<<endl;
break;
case 3:
cout<<endl<<endl<<endl;
cout<<" *************"<<endl;
cout<<" * O *"<<endl;
cout<<" * *"<<endl;
cout<<" * O *"<<endl;
cout<<" * *"<<endl;
cout<<" * O *"<<endl;
cout<<" *************"<<endl<<endl;
break;
case 4:
cout<<endl<<endl<<endl;
cout<<" *************"<<endl;
cout<<" * O O *"<<endl;
cout<<" * *"<<endl;
cout<<" * *"<<endl;
cout<<" * *"<<endl;
cout<<" * O O *"<<endl;
cout<<" *************"<<endl<<endl;
break;
case 5:
cout<<endl<<endl<<endl;
cout<<" *************"<<endl;
cout<<" * O O *"<<endl;
cout<<" * *"<<endl;
cout<<" * O *"<<endl;
cout<<" * *"<<endl;
cout<<" * O O *"<<endl;
cout<<" *************"<<endl<<endl;
break;
case 6:
cout<<endl<<endl<<endl;
cout<<" *************"<<endl;
cout<<" * O O *"<<endl;
cout<<" * *"<<endl;
cout<<" * O O *"<<endl;
cout<<" * *"<<endl;
cout<<" * O O *"<<endl;
cout<<" *************"<<endl<<endl;
break;
}
return ;
}