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
|
#include <iostream>
#include <string>
#include <random>
#include <array>
using namespace std;
class Dice
{
public:
void RollTwoDice(bool human=true)
{
int one = rd_() % 6 + 1;
int two = rd_() % 6 + 1;
int i = one-1;
int j = two-1;
cout << LINES << SPACE << LINES << endl;
cout << FACES[i][0] << SPACE << FACES[j][0] << endl;
cout << FACES[i][1] << SPACE << FACES[j][1] << endl;
cout << FACES[i][2] << SPACE << FACES[j][2] << endl;
cout << LINES << SPACE << LINES << endl;
cout << (human ? "You have " : "The computer has ") <<
"rolled a " << one+two << endl << endl;
}
private:
random_device rd_;
const string LINES = " ------- "; // Top and bottom bars
const string S_S_S = "| |";
const string D_S_S = "| 0 |";
const string D_S_D = "| 0 0 |";
const string S_D_S = "| 0 |";
const string S_S_D = "| 0 |";
const string SPACE = " "; // Whitespace between dice
const array<array<string,3>, 6> FACES =
{{
{S_S_S, S_D_S, S_S_S}, // 1
{S_D_S, S_S_S, S_D_S}, // 2
{D_S_S, S_D_S, S_S_D}, // 3
{D_S_D, S_S_S, D_S_D}, // 4
{D_S_D, S_D_S, D_S_D}, // 5
{D_S_D, D_S_D, D_S_D} // 6
}};
};
int main()
{
Dice d;
int total_rolls = 6;
int roll = 1;
cout << "Ready to roll some dice?" << endl << endl;
do
{
cout << "-----------------------------------------\n";
cout << "Roll #" << roll << endl << endl;
d.RollTwoDice();
d.RollTwoDice(false);
} while (roll++ < total_rolls);
return 0;
}
|