#include
using namespace std;
class Game
{
private:
int die1;
int die2;
int tzs;
public:
int RollDice(); //函数原型 //抛骰子函数
void PlayGame(); //进行一次游戏
void GetHelp();//游戏帮助
};
enum GameStatus{WIN,LOSE,PLAYING}; //枚举游戏状态;
int RollDice() //抛骰子函数
{
int die1 = 1 + rand() % 6;
int die2 = 1 + rand() % 6;
int tzs = die1 + die2;
cout << "Player rooled " << die1 << "+" << die2 << "=" << tzs << endl;
return tzs;
}
void Game::PlayGame()
{
int a;
cout<<"输入任何数字开始游戏"< cin>>a;
int tzs,first;
int GameStatus;
tzs=RollDice();
switch(tzs){
case 7:
case 11:
GameStatus = WIN;
break;
case 2:
case 3:
case 12:
GameStatus = LOSE;
break;
default:
GameStatus = PLAYING;
first=tzs;
break;
}
while(GameStatus==PLAYING)
{
tzs=RollDice();
if (tzs=first)
GameStatus=WIN;
else if (tzs=7)
GameStatus=LOSE;
}
if (GameStatus==WIN)
cout<<"你赢啦"<<endl;
else if(GameStatus==LOSE)
cout<<"很遗憾你输了"<<endl;
char j;
char y;
cout<<"想继续玩此游戏吗? 输入'y'或'Y'则继续,输入其他字符则退出游戏。"<<endl;
cin>>y;
while(y=='y'||'Y')
{
if(y=='y')
{
cout<<"输入任意字符游戏开始"<<endl;
cin>>j;
cout<<"游戏开始\n\n\n\n";
Game::PlayGame();
}
break;
}
}
void Game::GetHelp(){
cout<<endl
<<" 比赛规则:每人初始积分为100分,从1号开始掷骰子,骰子出现后,"
<<"根据点数减去掷骰人的相应积分, 如 减去 10*(6-点数),然后"
<<"根据点数多少,就依次向后数掷骰的点数同等数量的人,被数到的"
<<"被数到的最后一个人继续掷骰子,计算积分,依此类推。"
<<"如果某人掷骰子后,其积分小于等于0则出列,余下的人继续按照此法进行游戏,直到剩下最后一个人,为胜利者。"
<<endl<<endl<<endl;
}
int main()
{
cout<<endl
<<" **************************************************\n\n"
<<" 欢迎进入掷骰子游戏\n\n"
<<" **************************************************\n\n"
<<endl<<endl<<endl;
int o;
cout<<" ------------------------"<<endl;
cout<<" |亲输入你要选择的项目 |"<<endl;
cout<<" |1.玩一手游戏 |"<<endl;
cout<<" |2.查看帮助 |"<<endl;
cout<<" |3.退出游戏 |"<<endl;
cout<<" ------------------------"<<endl;
cin>>o;
switch(o)
{
case 1:
char j;
cout<<" 输入任意字符游戏开始"<<endl;
cin>>j;
cout<<" 游戏开始\n\n\n\n";
Game obj;
obj.PlayGame();
break;
case 2:
obj.GetHelp();
break;
case 3:
break;
default:
cout<<" 对不起你输入的不在范围内"<<endl;
break;
}
return 0;
}
错误是这样的:
1>zzh.obj : error LNK2019: 无法解析的外部符号 "public: int __thiscall Game::RollDice(void)" (?RollDice@Game@@QAEHXZ),该符号在函数 "public: void __thiscall Game::PlayGame(void)" (?PlayGame@Game@@QAEXXZ) 中被引用
1>C:\Users\11350\documents\visual studio 2010\Projects\111\Debug\111.exe : fatal error LNK1120: 1 个无法解析的外部命令