-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScoreSheet.cpp
101 lines (94 loc) · 1.78 KB
/
ScoreSheet.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
/*
* University Of Ottawa
* CSI 2372 Final Project
* Professor : Jochen Lang
* Group Number : 11
* Name : Zekun Li 8520399 Hanyang Yu 8524153
*
*/
#include "ScoreSheet.h"
#include <iostream>
#include <stdio.h>
#include "QwintoScoreSheet.h"
#include "QwixxScoreSheet.h"
#include <typeinfo>
using namespace std;
ostream &operator<<(ostream &out, const ScoreSheet &sheet)
{
return out;
}
ScoreSheet::ScoreSheet()
{
}
ScoreSheet::ScoreSheet(string pname)
{
name = pname;
}
// first validate if the score is valid, then score the dice accoring to input
bool ScoreSheet::score(RollOfDice rod, Colour color, int position)
{
if (!validate(rod, color, position))
{
return false;
}
else
{
//check this type, cast to corresponding and add score to score sheet
if (typeid(*this) == typeid(QwintoScoreSheet))
{
QwintoScoreSheet *qts = dynamic_cast<QwintoScoreSheet *>(this);
switch (color)
{
case Colour::RED:
qts->red[position] = rod;
return true;
break;
case Colour::BLUE:
qts->blue[position] = rod;
return true;
break;
case Colour::YELLOW:
qts->yellow[position] = rod;
return true;
break;
}
}
else
{
QwixxScoreSheet *qxs = dynamic_cast<QwixxScoreSheet *>(this);
for (Dice &a : rod)
{
if (a.getColour() != Colour::WHITE)
{
color = a.getColour();
}
switch (color)
{
case Colour::RED:
qxs->red += rod;
return true;
break;
case Colour::YELLOW:
qxs->yellow += rod;
return true;
break;
case Colour::GREEN:
qxs->green += rod;
return true;
break;
case Colour::BLUE:
qxs->blue += rod;
return true;
break;
case Colour::WHITE:
return true;
break;
}
}
}
}
}
void ScoreSheet::setTotal()
{
overallScore = calcTotal();
}