-
Notifications
You must be signed in to change notification settings - Fork 0
/
QwintoPlayer.cpp
187 lines (181 loc) · 3.56 KB
/
QwintoPlayer.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
* University Of Ottawa
* CSI 2372 Final Project
* Professor : Jochen Lang
* Group Number : 11
* Name : Zekun Li 8520399 Hanyang Yu 8524153
*
*/
#include "QwintoPlayer.h"
#include "RollOfDice.h"
#include "Colour.h"
#include "Dice.h"
using namespace std;
QwintoPlayer::QwintoPlayer(QwintoScoreSheet qs)
{
qtss = qs;
}
void QwintoPlayer::inputBeforeRoll(RollOfDice &rod)
{
cout << "Please enter the number of dice(s) to roll for player "
<< this->qtss.getName() << ": " << endl;
int num;
cin >> num;
while (cin.fail())
{
cout << "Please enter a number value" << endl;
cin.clear();
cin.ignore(256, '\n');
cout << "Please enter the number of dice(s) to roll for player "
<< this->qtss.getName() << ": " << endl;
cin >> num;
}
if (num == 3)
{ // if number of dice is 3, roll all dices directly
Colour red = Colour::RED;
Dice *r = new Dice(red);
rod.add(*r);
Colour yellow = Colour::YELLOW;
Dice *y = new Dice(yellow);
rod.add(*y);
Colour blue = Colour::BLUE;
Dice *b = new Dice(blue);
rod.add(*b);
}
else if (num > 0 && num <= 2)
{
int i = 0;
int rcount = 0;
int ycount = 0;
int bcount = 0;
while (i < num)
{ // if number of dice is less than 3, ask player which dice they want to roll
cout << "Please select the color of dice(s) " << i + 1 << ":(r/y/b)"
<< endl;
Colour c;
string ibcolour;
cin >> ibcolour;
if (ibcolour == "r")
{
c = Colour::RED;
++rcount;
}
else if (ibcolour == "b")
{
c = Colour::BLUE;
++bcount;
}
else
{
c = Colour::YELLOW;
++ycount;
}
if (rcount > 1 || ycount > 1 || bcount > 1)
{ // check if the color is unique
cout << "You can't roll 2 dices with the same color! Try again."
<< endl;
rcount--;
ycount--;
bcount--;
}
else
{
Dice *d = new Dice(c);
rod.add(*d);
++i;
}
}
}
else
{
cout << "invalid number of dices" << endl;
}
}
void QwintoPlayer::inputAfterRoll(RollOfDice &rod)
{
bool done = false;
while (!done)
{
cout << "Please select which row color to score for player "
<< this->qtss.getName() << "," << endl
<< "to skip scoring this number, enter 'fail':(r/y/b/fail) "
<< endl;
string iacolour;
cin >> iacolour;
if (iacolour == "fail")
{
this->qtss.failed++;
break;
}
cout << "Please select the position to score: " << endl;
int iscore;
cin >> iscore;
while (cin.fail())
{ // check if input is a number
cout << "Please enter a number value" << endl;
cin.clear();
cin.ignore(256, '\n');
cout << "Please select the position to score: " << endl;
cin >> iscore;
}
if (iacolour == "r")
{
if (!qtss.score(rod, Colour::RED, iscore))
{
cout << "Try again?(y/n)" << endl;
string selection;
cin >> selection;
if (selection == "n")
{
done = true;
this->qtss.failed++;
}
}
else
{
done = true;
}
}
else if (iacolour == "b")
{
if (!qtss.score(rod, Colour::BLUE, iscore))
{
cout << "Try again?(y/n)" << endl;
string selection;
cin >> selection;
if (selection == "n")
{
done = true;
this->qtss.failed++;
}
}
else
{
done = true;
}
}
else if (iacolour == "y")
{
if (!qtss.score(rod, Colour::YELLOW, iscore))
{
cout << "Try again?(y/n)" << endl;
string selection;
cin >> selection;
if (selection == "n")
{
done = true;
this->qtss.failed++;
}
}
else
{
done = true;
}
// if input is not a vaild color, loop again
}
else
{
cout << "Incorrect input.(r/y/b) :(" << endl;
}
}
}