-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQwixxRow.h
More file actions
99 lines (77 loc) · 1.96 KB
/
QwixxRow.h
File metadata and controls
99 lines (77 loc) · 1.96 KB
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
#ifndef QWIXX_ROW
#define QWIXX_ROW
#include <iomanip>
#include "Row.h"
#include "Dice.h"
template <class rowType, const Color d_c>
class QwixxRow : public Row
{
rowType d_row;
protected:
virtual void print(std::ostream& _out) const;
public:
QwixxRow();
bool validate(const int _index, const RollOfDice roll);
virtual Color getColor() { return d_c; }
virtual int & operator[](const int _index);
virtual const int & operator[](const int _index) const;
};
template<class rowType, const Color d_c>
QwixxRow<rowType, d_c>::QwixxRow()
{
_locked = false;
if ((d_c == Color::RED) || (d_c == Color::YELLOW))
for (int i = 2; i < 13; i++) {
d_row.push_back(i);
}
if ((d_c == Color::GREEN) || (d_c == Color::BLUE))
for (int i = 12; i > 1; i--) {
d_row.push_back(i);
}
}
template <typename rowType, const Color d_c>
bool QwixxRow<rowType, d_c>::validate(const int _index, const RollOfDice _roll)
{
if (_index < 0 || _index > 10)
return false;
if ((*this)[_index] == -1)
return false;
//checking if _roll has a dice of the selected color
bool found = false;
for (auto die : _roll)
{
if (die.d_color == d_c)
found = true;
}
if (!found)
return false;
//checking if value is open for use
int playedBoxCount = 0;
for (int i = 0; i < d_row.size(); i++) {
if ((*this)[i] == -1) {
playedBoxCount++;
if (i > _index)
return false;
}
}
if (playedBoxCount > 5){
this->_locked = true;
return false;
}
return true;
}
template<typename rowType, Color d_c>
int & QwixxRow<rowType, d_c>::operator[](int _index)
{
auto iter = d_row.begin();
std::advance(iter, _index);
return *iter;
}
template<typename rowType, Color d_c>
const int & QwixxRow<rowType, d_c>::operator[](int _index) const
{
auto iter = d_row.begin();
std::advance(iter, _index);
return *iter;
}
#endif