-
Notifications
You must be signed in to change notification settings - Fork 4
/
Card.cpp
56 lines (47 loc) · 1.17 KB
/
Card.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
#include "Card.h"
bool Card::_deckSet = false;
array<Card *, 52> Card::_deck = {};
Card::Card(CardValue::Type value, Color::Type color) {
_value = value;
_color = color;
}
CardValue::Type Card::getValue() const {
return _value;
}
Color::Type Card::getColor() const {
return _color;
}
bool Card::isBigger(Card *rhs, Contract *c) {
if (rhs->getColor() == getColor()) {
return getValue() > rhs->getValue();
}
return getColor() == c->getColor() && rhs->getColor() != c->getColor();
}
std::ostream &operator<<(std::ostream &os, const Card &c) {
return os << Color::Values[c.getColor()] << " " << CardValue::Values[c.getValue()];
}
json Card::serialize() {
return json(getValue() * 4 + getColor());
}
void Card::setDeck() {
int i = 0;
for (const auto cardValue : CardValue::All) {
for (const auto color : Color::All) {
_deck[i] = new Card(cardValue, color);
i++;
}
}
_deckSet = true;
}
array<Card *, 52> Card::getDeck() {
if (!_deckSet) {
setDeck();
}
return Card::_deck;
}
Card* Card::get(const int id){
if (!_deckSet) {
setDeck();
}
return Card::_deck[id];
}