最后我似乎无法比较球员和骰子得分。我需要它来帮助决定谁赢。我需要调用变量吗?还是需要调整我已经拥有的东西?
我试图将最终得分保存在另一个变量下,但是如果不给得分本身添加大量数字,它就不会让我失望。
#include <iostream>
#include <string>
#include <time.h>
#include <cctype>
#include <stdlib.h>
#include <iomanip>
using namespace std;
/********************************************************************
* Class: Dice Game
* Purpose: Generate the numbers for the dice and save the score along
* with allowing both the user and AI to roll..
* Then at the end displays the winner and score.
********************************************************************/
class Dice
{
private:
int totalRolls;
int FinalScore;
//int FinalScoreai;
int ScoreAddD;
//int ScoreAddDai;
//int FinalScoreAi;
int die;
int die2;
public:
Dice();
void FirstDiceFaces();
void SecndDiceFaces();
int NumberGen() { return rand() % 6 + 1; }
int NumberGen2() { return rand() % 6 + 1; }
void Rolls();
void Display();
void DisplayAi();
};
Dice::Dice() : die(0), die2(0), totalRolls(0), FinalScore(0)
{}
void Dice::Rolls()
{
die = 0;
die2 = 0;
totalRolls++;
die = NumberGen();
die2 = NumberGen2();
ScoreAddD = (die + die2);
//ScoreAddDai = (die + die2);
//ScoreAddD += (die);
FinalScore += (ScoreAddD); //adds to the final score
//FinalScoreai += (ScoreAddDai);
}
void Dice::Display()
{
cout << "You rolled a " << die << " and a " << die2 << endl;
cout << "You rolled a total of: " << totalRolls << " times. " << endl;
cout << "Final score: " << FinalScore << endl;
}
void Dice::DisplayAi()
{
cout << "The last dice the computer rolled was a " << die << " and a " << die2 << endl;
cout << "The computer rolled: " << totalRolls << " times. " << endl;
cout << "Final score: " << FinalScore << endl;
}
void Dice::FirstDiceFaces()
{
switch (die)
{
case 1:
cout << "- - - - -" << endl;
cout << "| |" << endl;
cout << "| O |" << endl;
cout << "| |" << endl;
cout << " - - - - -" << endl;
break;
case 2:
cout << "- - - - -" << endl;
cout << "| O |" << endl;
cout << "| |" << endl;
cout << "| O |" << endl;
cout << " - - - - -" << endl;
break;
case 3:
cout << "- - - - -" << endl;
cout << "| O |" << endl;
cout << "| O |" << endl;
cout << "| O |" << endl;
cout << " - - - - -" << endl;
break;
case 4:
cout << "- - - - -" << endl;
cout << "| O O |" << endl;
cout << "| |" << endl;
cout << "| O O |" << endl;
cout << " - - - - -" << endl;
break;
case 5:
cout << "- - - - -" << endl;
cout << "| O O |" << endl;
cout << "| O |" << endl;
cout << "| O O |" << endl;
cout << " - - - - -" << endl;
break;
case 6:
cout << "- - - - -" << endl;
cout << "| O O |" << endl;
cout << "| O O |" << endl;
cout << "| O O |" << endl;
cout << " - - - - -" << endl;
break;
}
}
void Dice::SecndDiceFaces() //doesn't display anything
{
switch (die2)
{
case 1:
cout << "- - - - -" << endl;
cout << "| |" << endl;
cout << "| O |" << endl;
cout << "| |" << endl;
cout << " - - - - -" << endl;
break;
case 2:
cout << "- - - - -" << endl;
cout << "| O |" << endl;
cout << "| |" << endl;
cout << "| O |" << endl;
cout << " - - - - -" << endl;
break;
case 3:
cout << "- - - - -" << endl;
cout << "| O |" << endl;
cout << "| O |" << endl;
cout << "| O |" << endl;
cout << " - - - - -" << endl;
break;
case 4:
cout << "- - - - -" << endl;
cout << "| O O |" << endl;
cout << "| |" << endl;
cout << "| O O |" << endl;
cout << " - - - - -" << endl;
break;
case 5:
cout << "- - - - -" << endl;
cout << "| O O |" << endl;
cout << "| O |" << endl;
cout << "| O O |" << endl;
cout << " - - - - -" << endl;
break;
case 6:
cout << "- - - - -" << endl;
cout << "| O O |" << endl;
cout << "| O O |" << endl;
cout << "| O O |" << endl;
cout << " - - - - -" << endl;
break;
}
}
/*******************************************************************************
* Function Name: main()
* Parameters: None
* Return Value: int
* Purpose:
*******************************************************************************/
//class Dice
int main()
{
//char YesOrNo;
cout << "Welcome to the Dice Off game!" << endl;
cout << "" << endl;
cout << "You get to roll two dice, a total of six times " << endl;
cout << "" << endl;
cout << "before the score are calculated to determin the winner." << endl;
cout << "" << endl;
cout << "Your goal is to get lucky and beat the computer." << endl;
cout << "" << endl;
cout << "-<[Ready to roll? Press enter!]>-" << endl;
cout << "" << endl;
//cout << "Type y to start rolling." << endl;
//cin >> YesOrNo;
//if (YesOrNo = 'y')
//{
srand(time(0));
Dice player, ai;
for (int i = 0; i < 6; i++)
{
cin.get();
player.Rolls();
player.Display();
player.FirstDiceFaces();
player.SecndDiceFaces();
cout << "" << endl;
ai.Rolls();
ai.DisplayAi();
ai.FirstDiceFaces();
ai.SecndDiceFaces();
//ai.Rolls();
//ai.Display();
//ai.DisplayAi();
cin.get();
}
system("pause"); //pauses the program
return 0; //ends the program
};