-
Notifications
You must be signed in to change notification settings - Fork 1
/
card.hpp
95 lines (73 loc) · 1.68 KB
/
card.hpp
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
#include <iostream>
#include <string>
using namespace std;
/*
Equivalent to:
struct Card {
int numero;
char seme;
int fun() {
}
}
*/
class Card {
// Const Instruction
// Variable:
// x: | 0x01 | 10 (const)|
// const int x = 10; Eq to: int const x = 10;
// px: | 0x02 | 0x01 |
// const int* px = &x; <- the pointer object cannot change
// Eq to: int const * px = &x;
// *px = 42 <- ILLIGAL: ERROR COMPILE
// px = &y
// y = 20;
// int* const py = &y; <- the pointer cannot change
// *py = 42
// py = &z <- ERROR
public:
static Card getEmptyCard() {
Card empty;
empty.numero = -1;
empty.seme = '-';
return empty;
}
// implicitly implemented C++ if you want
Card() {
// cout << "DEBUG: Card: constructor" << endl;
} // default constructor
Card(int number, char seed) {
numero = number;
seme = seed;
}
Card(const Card & val) {
// cout << "DEBUG: Card: copy constructor" << endl;
numero = val.numero;
seme = val.seme;
} // copy constructor
// Methods
int getPoint() const {
if (numero == 1) {
return 11;
} else if (numero == 3) {
return 10;
} else if (numero == 10) {
return 4;
} else if (numero == 9) {
return 3;
} else if (numero == 8) {
return 2;
} else {
return 0;
}
}
std::string print() const {
return std::to_string(numero) + '-' + seme;
}
bool isValid() const {
return numero != -1 || seme != '-';
}
public:
// Fields
int numero;
char seme;
};