-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQwintoRow.h
More file actions
85 lines (61 loc) · 1.5 KB
/
QwintoRow.h
File metadata and controls
85 lines (61 loc) · 1.5 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
#ifndef QWINTO_ROW
#define QWINTO_ROW
#include <iomanip>
#include "Row.h"
#include "Dice.h"
template <const Color d_c>
class QwintoRow : public Row
{
int d_row[10] = {0};
protected:
virtual void print(std::ostream& _out) const;
public:
QwintoRow();
virtual int &operator[](int _index);
virtual bool validate(const int _index, const RollOfDice roll);
virtual Color getColor() { return d_c; }
};
//defining functions from QwintoRow template
template<const Color d_c>
QwintoRow<d_c>::QwintoRow()
{
if(d_c == Color::RED)
d_row[3] = -1;
else if(d_c == Color::YELLOW)
d_row[5] = -1;
else if(d_c == Color::BLUE)
d_row[4] = -1;
}
template <const Color d_c>
bool QwintoRow<d_c>::validate(const int _index, const RollOfDice _roll)
{
if (_index < 0 || _index > 9)
return false;
if(d_row[_index] != 0)
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 a lower index has a higer value
int i;
for(i = _index; i>-1 && d_row[i] <= 0; --i);
if (i>-1 && d_row[i] >= _roll)
return false;
//checking if a higer index has a lower value
for(i = _index; i<10 && d_row[i] <= 0; ++i);
if (i<10 && d_row[i] <= _roll)
return false;
return true;
}
template <const Color d_c>
int& QwintoRow<d_c>::operator[](const int _index)
{
return d_row[_index];
}
#endif