1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int counter = 0;
int rollChoice = 0;
int mainMenuChoice = 1;
class Die;
void rollDice(Die die1, Die die2, Die die3, Die die4, Die die5);
void rollTest(Die die1, Die die2, Die die3, Die die4, Die die5);
class Die
{
public:
int dieNumber;
bool held;
int pips;
bool Holding();
int DieReport();
int Roll();
}
int Die::DieReport()
{
cout<< "Die #" << dieNumber << " is now showing " << pips << " pips." << endl << endl;
return pips;
}
bool Die::Holding()
{
if(held == false)
{
held = true;
cout<< "Die #" << dieNumber << " is now held." << endl << endl;
}
else
{
held = false;
cout<< "Die #" << dieNumber << " is now released." << endl << endl;
}
return held;
}
int Die::Roll()
{
srand(static_cast<unsigned int>(time(0)));
int randNum = rand();
pips = (randNum % 6) + 1;
return pips;
}
void main()
{
Die die1;
die1.dieNumber = 1;
die1.held = false;
die1.pips = 1;
Die die2;
die2.dieNumber = 2;
die2.held = false;
die2.pips = 1;
Die die3;
die3.dieNumber = 3;
die3.held = false;
die3.pips = 1;
Die die4;
die4.dieNumber = 4;
die4.held = false;
die4.pips = 1;
Die die5;
die5.dieNumber = 5;
die5.held = false;
die5.pips = 1;
cout<< "Die Test"<< endl<<endl;
cout<< "1. Launch"<< endl<<endl;
cout<< "2. End"<< endl<<endl;
cin >> mainMenuChoice;
while(mainMenuChoice == 1)
{
cout<< "Die Test"<< endl<<endl;
cout<< "1. Launch"<<endl;
cout<< "2. End"<< endl<<endl;
cin >> mainMenuChoice;
rollTest(die1, die2, die3, die4, die5);
}
cout<< "Bye" << endl;
system("pause");
}
void rollDice(Die die1, Die die2, Die die3, Die die4, Die die5)
{ // rolls dice
die1.Roll();
die2.Roll();
die3.Roll();
die4.Roll();
die5.Roll();
}
void rollTest(Die die1, Die die2, Die die3, Die die4, Die die5)
{
rollDice(die1, die2, die3, die4, die5);
//more to be added later
}
|