-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQwixxRow.h
63 lines (60 loc) · 1.19 KB
/
QwixxRow.h
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
/*
* University Of Ottawa
* CSI 2372 Final Project
* Professor : Jochen Lang
* Group Number : 11
* Name : Zekun Li 8520399 Hanyang Yu 8524153
*
*/
#ifndef QWIXXROW_H
#define QWIXXROW_H
#include "RollOfDice.h"
#include "Colour.h"
#include <iostream>
using namespace std;
//row of qwixx score sheet
template <class T, Colour C>
class QwixxRow
{
friend ostream &operator<<(ostream &os, QwixxRow<T, C> row);
public:
QwixxRow();
QwixxRow<T, C> operator+=(RollOfDice rod);
bool validate(RollOfDice rod, int &position);
T scoreArray;
};
template <class T, Colour C>
//Check whether we can put the rod at the position
bool QwixxRow<T, C>::validate(RollOfDice rod, int &position)
{
int counter = 0;
if (C == Colour::RED || C == Colour::YELLOW)
position = rod - 2;
else
position = 12 - rod;
for (auto a : scoreArray)
{
if (position > counter)
++counter;
else if (a > 0)
return false;
}
return true;
};
template <class T, Colour C>
QwixxRow<T, C> QwixxRow<T, C>::operator+=(RollOfDice rd)
{
int position, counter = 0;
validate(rd, position);
for (auto &a : scoreArray)
{
if (position == counter)
{
a = rd;
break;
}
++counter;
}
return *this;
};
#endif /* QWIXXROW_H */