-
Notifications
You must be signed in to change notification settings - Fork 4
/
Contract.cpp
57 lines (47 loc) · 1.4 KB
/
Contract.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
#include "Contract.h"
Contract* Contract::_pass = new Contract();
int Contract::getTricksAmount() const {
return _tricksAmount;
}
Color::Type Contract::getColor() const {
return _color;
}
bool operator>(const Contract& lhs, const Contract& rhs) {
if (lhs.getTricksAmount() > rhs.getTricksAmount()) {
return true;
} else if (lhs.getTricksAmount() == rhs.getTricksAmount()) {
return lhs.getColor() > rhs.getColor();
}
return false;
}
bool operator<(const Contract& lhs, const Contract& rhs) {
if (lhs.getTricksAmount() < rhs.getTricksAmount()) {
return true;
} else if (lhs.getTricksAmount() == rhs.getTricksAmount()) {
return lhs.getColor() < rhs.getColor();
}
return false;
}
bool operator==(const Contract& lhs, const Contract& rhs) {
return lhs.getColor() == rhs.getColor() && lhs.getTricksAmount() == rhs.getTricksAmount();
}
Contract::Contract(int amountOfTricks, Color::Type color) {
if (amountOfTricks < 1) {
_tricksAmount = 1;
} else if (amountOfTricks > 6) {
_tricksAmount = 6;
} else {
_tricksAmount = amountOfTricks;
}
_color = color;
}
Contract::Contract() {
_tricksAmount = 0;
_color = Color::NOTRUMP;
}
Contract *Contract::Pass() {
return _pass;
}
std::ostream &operator<<(std::ostream &os, const Contract &c) {
return os << c._tricksAmount << " " << Color::Values[c._color];
}