-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.cpp
More file actions
102 lines (96 loc) · 1.72 KB
/
Copy pathCard.cpp
File metadata and controls
102 lines (96 loc) · 1.72 KB
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
102
#include "Card.h"
//#define RANDOM
// #define WINDOWS
#ifdef WINDOWS
#include <windows.h>
#endif
Card generate_card() {
#ifdef RANDOM
return Card(color(rand() % 4 + 1), sign(rand() % 13 + 1));
#else
static int counter = 0;
counter++;
return Card(color(counter % 2 + 1), sign(counter % 5 + 8));
#endif
}
bool Card::is_leggal(const Card& other) const {
bool ret = false;
ret |= (get_color() == other.get_color());
ret |= (get_sign() == other.get_sign());
return ret;
}
ostream& operator << (ostream &os, const Card &c) {
#ifdef WINDOWS
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
// Remember how things were when we started
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hstdout, &csbi);
switch (c.clr) {
case R:
SetConsoleTextAttribute(hstdout, 0x7C);
break;
case G:
SetConsoleTextAttribute(hstdout, 0x7A);
break;
case B:
SetConsoleTextAttribute(hstdout, 0x79);
break;
case Y:
SetConsoleTextAttribute(hstdout, 0x7E);
break;
default:
os << c.clr << " error";
}
switch (c.s) {
case PLUS:
os << "+";
break;
case STOP:
os << "STP";
break;
case CD:
os << "-><-";
break;
case TAKI:
os << "TAKI";
break;
default:
os << c.s;
}
SetConsoleTextAttribute(hstdout, csbi.wAttributes);
#else
switch (c.clr) {
case R:
os << "R-";
break;
case G:
os << "G-";
break;
case B:
os << "B-";
break;
case Y:
os << "Y-";
break;
default:
os << c.clr << " error";
}
switch (c.s) {
case PLUS:
os << "+";
break;
case STOP:
os << "STP";
break;
case CD:
os << "-><-";
break;
case TAKI:
os << "TAKI";
break;
default:
os << c.s;
}
#endif
return os;
}