/
MorrisonDiceRoll.cpp
67 lines (61 loc) · 1.72 KB
/
MorrisonDiceRoll.cpp
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
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<windows.h>
using namespace std;
int main()
{
HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
string player1;
string player2;
int p1roll;
int p2roll;
int p1color = 7;
int p2color = 7;
string p1crit;
string p2crit;
string winner;
cout << "Enter Player 1 name:";
cin >> player1;
cout << "Enter Player 2 name:";
cin >> player2;
srand(time(0));
p1roll = rand() % (20 - 1 + 1) + 1;
p2roll = rand() % (20 - 1 + 1) + 1;
if (p1roll == 1) {
p1color = 12;
p1crit = "Critical Failure";
} else if (p1roll == 20) {
p1color = 10;
p1crit = "Critical Success";
};
if (p2roll == 1) {
p2color = 12;
p2crit = "Critical Failure";
} else if (p2roll == 20) {
p2color = 10;
p2crit = "Critical Success";
};
if (p1roll > p2roll) {
winner = player1;
} else if (p1roll < p2roll) {
winner = player2;
} else {
winner = "No one your Evenly Matched play again.";
};
cout << "The two Players play the game, here are the results."<< endl;
cout << "Player 1 rolls:" << p1roll << endl;
cout << "Player 2 rolls:" << p2roll << endl;
cout << "-------------------------------" << endl;
cout << "Player 1 critical status: ";
SetConsoleTextAttribute ( screen, p1color);
cout << p1crit << endl;
SetConsoleTextAttribute ( screen, 7);
cout << "Player 2 critical status: ";
SetConsoleTextAttribute ( screen, p2color);
cout << p2crit << endl;
SetConsoleTextAttribute ( screen, 7);
cout << "-------------------------------" << endl;
cout << "Winner is " << winner << endl;
return 0;
}