25
25
#include < iostream>
26
26
#include < sstream>
27
27
28
+ /* !
29
+ * \brief Constructor
30
+ * \param color The color of the card
31
+ * \param value The value of the card
32
+ * \param board The board of the game
33
+ */
28
34
Card::Card (cardcolor color, cardvalue value, Board* board) : AbstractCardHolder()
29
35
{
30
36
mChild = 0 ;
@@ -44,21 +50,20 @@ Card::Card(cardcolor color, cardvalue value, Board* board) : AbstractCardHolder(
44
50
mBoard ->addItem (mProxy );
45
51
}
46
52
47
- void Card::presents ()
48
- {
49
- std::cout << getLabel ().toStdString () << std::endl;
50
- }
51
-
53
+ /* !
54
+ * \brief Get a string for displaying the card's identity
55
+ * \return QString
56
+ */
52
57
QString Card::getLabel ()
53
58
{
54
59
return getValueName () + " of " + getColorName ();
55
60
}
56
61
57
- QPixmap Card::getWidgetPixmap ()
58
- {
59
- return mWidget -> grab ();
60
- }
61
-
62
+ /* !
63
+ * \brief Change the parent of the card and update the position accordingly
64
+ * \param parent The new parent
65
+ * \param animate If set to true, the position will change through an animation
66
+ */
62
67
void Card::setParent (AbstractCardHolder* parent, bool animate)
63
68
{
64
69
if (mParent ) {
@@ -72,6 +77,10 @@ void Card::setParent(AbstractCardHolder* parent, bool animate)
72
77
}
73
78
}
74
79
80
+ /* !
81
+ * \brief Get the number of cards stacked over this one
82
+ * \return int
83
+ */
75
84
int Card::countChildren ()
76
85
{
77
86
if (mChild == 0 ) {
@@ -80,16 +89,29 @@ int Card::countChildren()
80
89
return mChild ->countChildren () + 1 ;
81
90
}
82
91
92
+ /* !
93
+ * \brief Check if a card can be stacked over this one
94
+ * \param card The card to check
95
+ * \return boolean
96
+ */
83
97
bool Card::canStackCard (Card* card)
84
98
{
85
99
return isStackable () && getChild () == 0 && card->isMovable () && isValidParentOf (card);
86
100
}
87
101
102
+ /* !
103
+ * \brief Check if the card can receive other cards over itself
104
+ * \return boolean
105
+ */
88
106
bool Card::isStackable ()
89
107
{
90
108
return mParent ->isStackable ();
91
109
}
92
110
111
+ /* !
112
+ * \brief Check if the card can be moved from its current spot
113
+ * \return boolean
114
+ */
93
115
bool Card::isMovable ()
94
116
{
95
117
if (mIsOnAceSpot ) {
@@ -101,6 +123,11 @@ bool Card::isMovable()
101
123
return isValidParentOf (mChild ) && mChild ->isMovable () && mBoard ->hasEnoughFreecells (countChildren () + 1 );
102
124
}
103
125
126
+ /* !
127
+ * \brief Check if a given card's color and value allows it to be stacked over this one
128
+ * \param card The card to check
129
+ * \return
130
+ */
104
131
bool Card::isValidParentOf (Card* card)
105
132
{
106
133
if (card == 0 ) {
@@ -112,16 +139,30 @@ bool Card::isValidParentOf(Card* card)
112
139
return getValue () - card->getValue () == 1 && card->getBlackRedColor () != getBlackRedColor ();
113
140
}
114
141
142
+ /* !
143
+ * \brief The the "ace spot" flag of the card
144
+ * The flag is used for the stacking behaviour, as ace spot only receive card of the same colour
145
+ * in ascendant order
146
+ * \param on The new value
147
+ */
115
148
void Card::setOnAceSpot (bool on)
116
149
{
117
150
mIsOnAceSpot = on;
118
151
}
119
152
153
+ /* !
154
+ * \brief Getter for the "ace spot" flag
155
+ * \return boolean
156
+ */
120
157
bool Card::isOnAceSpot ()
121
158
{
122
159
return mIsOnAceSpot ;
123
160
}
124
161
162
+ /* !
163
+ * \brief Get the value of this card as a string
164
+ * \return QString
165
+ */
125
166
QString Card::getValueName ()
126
167
{
127
168
QString cardValue = " " ;
@@ -149,6 +190,10 @@ QString Card::getValueName()
149
190
return cardValue;
150
191
}
151
192
193
+ /* !
194
+ * \brief Get the color of this card as a string
195
+ * \return QString
196
+ */
152
197
QString Card::getColorName ()
153
198
{
154
199
QString colorName = " " ;
@@ -181,6 +226,10 @@ cardcolor Card::getColor()
181
226
return mColor ;
182
227
}
183
228
229
+ /* !
230
+ * \brief Convert the color of the card to the "real" (red or black) color
231
+ * \return 1 or 2
232
+ */
184
233
char Card::getBlackRedColor ()
185
234
{
186
235
if (mColor == HEARTS || mColor == DIAMONDS) {
@@ -201,6 +250,10 @@ QPoint Card::getChildPosition()
201
250
return QPoint (x, y);
202
251
}
203
252
253
+ /* !
254
+ * \brief Get the position of the card in board coordinates
255
+ * \return QPoint
256
+ */
204
257
QPoint Card::getPosition ()
205
258
{
206
259
return mPosition ;
@@ -224,6 +277,10 @@ void Card::animatePosition(QPoint pos)
224
277
}
225
278
}
226
279
280
+ /* !
281
+ * \brief Change the position of the card and its children to pos
282
+ * \param pos The new position
283
+ */
227
284
void Card::setPosition (QPoint pos)
228
285
{
229
286
mPosition = pos;
@@ -233,6 +290,10 @@ void Card::setPosition(QPoint pos)
233
290
}
234
291
}
235
292
293
+ /* !
294
+ * \brief Replace the card to its expected position
295
+ * \param animate Flag for animating the position update
296
+ */
236
297
void Card::updatePosition (bool animate)
237
298
{
238
299
if (animate) {
@@ -243,6 +304,10 @@ void Card::updatePosition(bool animate)
243
304
}
244
305
}
245
306
307
+ /* !
308
+ * \brief Get the minimum zindex for the card to be visible over all its children
309
+ * \return int
310
+ */
246
311
int Card::getTopZIndex ()
247
312
{
248
313
if (mChild ) {
@@ -251,11 +316,20 @@ int Card::getTopZIndex()
251
316
return getZIndex () + 1 ;
252
317
}
253
318
319
+ /* !
320
+ * \brief Getter for the zindex of the card
321
+ * \return int
322
+ */
254
323
int Card::getZIndex ()
255
324
{
256
325
return mProxy ->zValue ();
257
326
}
258
327
328
+ /* !
329
+ * \brief Set the zindex of the card
330
+ * \param index The new value
331
+ * \param cascade If set to true, the children are also updated
332
+ */
259
333
void Card::setZIndex (int index, bool cascade)
260
334
{
261
335
mProxy ->setZValue (index );
@@ -269,11 +343,17 @@ void Card::resetZIndex()
269
343
setZIndex (mParent ->getZIndex () + 1 );
270
344
}
271
345
346
+ /* !
347
+ * \brief Display the card
348
+ */
272
349
void Card::show ()
273
350
{
274
351
mWidget ->show ();
275
352
}
276
353
354
+ /* !
355
+ * \brief Hide the card
356
+ */
277
357
void Card::hide ()
278
358
{
279
359
mWidget ->hide ();
@@ -284,6 +364,10 @@ void Card::select()
284
364
mBoard ->selectCard (this );
285
365
}
286
366
367
+ /* !
368
+ * \brief Update the card design so it is selected or not
369
+ * \param selected The new sselected status
370
+ */
287
371
void Card::setSelected (bool selected)
288
372
{
289
373
mSelected = selected;
@@ -294,11 +378,19 @@ void Card::setSelected(bool selected)
294
378
}
295
379
}
296
380
381
+ /* !
382
+ * \brief Check if the card is selected
383
+ * \return boolean
384
+ */
297
385
bool Card::isSelected ()
298
386
{
299
387
return mSelected ;
300
388
}
301
389
390
+ /* !
391
+ * \brief Attempt automatic move with this card
392
+ * \see Board::automaticMove()
393
+ */
302
394
void Card::automaticMove ()
303
395
{
304
396
mBoard ->automaticMove (this );
0 commit comments