-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcard.cpp
executable file
·179 lines (127 loc) · 2.15 KB
/
pcard.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// The pyrimid helper class
// We use a Cards class object for code simplicity
#include "stdafx.h"
#include "pcard.h"
#include "cards.h"
#include "cardtools.h"
PCard::PCard() {
card = NULL;
n1 = NULL;
n2 = NULL;
p1 = NULL;
p2 = NULL;
selected = false;
return;
}
PCard::PCard(short cardnum) {
card = NULL;
n1 = NULL;
n2 = NULL;
p1 = NULL;
p2 = NULL;
selected = false;
setVal(cardnum);
return;
}
PCard::PCard(short cardnum, PCard *prev1, PCard *prev2, PCard *next1, PCard *next2) {
card = NULL;
n1 = NULL;
n2 = NULL;
p1 = NULL;
p2 = NULL;
selected = false;
setVal(cardnum);
setNext1(next1);
setNext2(next2);
setPrev1(prev1);
setPrev2(prev2);
return;
}
PCard* PCard::next1() {
return n1;
}
PCard* PCard::next2() {
return n2;
}
PCard* PCard::prev1() {
return p1;
}
PCard* PCard::prev2() {
return p2;
}
PCard* PCard::get() {
return this;
}
void PCard::setNext1(PCard *item) {
n1 = item;
if (n1 != NULL)
n1->setPrev1(this);
return;
}
void PCard::setNext2(PCard *item) {
n2 = item;
if (n2 != NULL)
n2->setPrev2(this);
return;
}
void PCard::setPrev1(PCard *item) {
p1 = item;
return;
}
void PCard::setPrev2(PCard *item) {
p2 = item;
return;
}
void PCard::setVal(short val) {
if (card != NULL)
delete card;
card = new Cards(NULL, val, false);
return;
}
void PCard::select() {
selected = !selected;
return;
}
void PCard::unselect() {
selected = false;
return;
}
short PCard::getVal() {
return card->getVal();
}
short PCard::getSuit() {
return card->getSuit();
}
short PCard::getNum() {
return card->getNum();
}
short PCard::getCol() {
return card->getCol();
}
bool PCard::isSelected() {
return selected;
}
void PCard::draw(KXY xy, HWND hWnd, KXY ca) {
drawCard(hWnd, xy.x, xy.y, card->getNum(), 0, selected);
xy.y += ca.y / 2;
xy.x -= ca.x * 11 / 20;
if (n1 != NULL)
n1->draw(xy, hWnd, ca);
xy.x += ca.x * 11 / 10;
if (n2 != NULL)
n2->draw(xy, hWnd, ca);
return;
}
PCard::~PCard() {
if (card != NULL)
delete card;
if (p1 != NULL)
p1->setNext1(NULL);
if (p2 != NULL)
p2->setNext2(NULL);
if (n1 != NULL)
n1->setPrev1(NULL);
if (n2 != NULL)
n2->setPrev2(NULL);
return;
}