2525#include < iostream>
2626#include < sstream>
2727
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+ */
2834Card::Card (cardcolor color, cardvalue value, Board* board) : AbstractCardHolder()
2935{
3036 mChild = 0 ;
@@ -44,21 +50,20 @@ Card::Card(cardcolor color, cardvalue value, Board* board) : AbstractCardHolder(
4450 mBoard ->addItem (mProxy );
4551}
4652
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+ */
5257QString Card::getLabel ()
5358{
5459 return getValueName () + " of " + getColorName ();
5560}
5661
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+ */
6267void Card::setParent (AbstractCardHolder* parent, bool animate)
6368{
6469 if (mParent ) {
@@ -72,6 +77,10 @@ void Card::setParent(AbstractCardHolder* parent, bool animate)
7277 }
7378}
7479
80+ /* !
81+ * \brief Get the number of cards stacked over this one
82+ * \return int
83+ */
7584int Card::countChildren ()
7685{
7786 if (mChild == 0 ) {
@@ -80,16 +89,29 @@ int Card::countChildren()
8089 return mChild ->countChildren () + 1 ;
8190}
8291
92+ /* !
93+ * \brief Check if a card can be stacked over this one
94+ * \param card The card to check
95+ * \return boolean
96+ */
8397bool Card::canStackCard (Card* card)
8498{
8599 return isStackable () && getChild () == 0 && card->isMovable () && isValidParentOf (card);
86100}
87101
102+ /* !
103+ * \brief Check if the card can receive other cards over itself
104+ * \return boolean
105+ */
88106bool Card::isStackable ()
89107{
90108 return mParent ->isStackable ();
91109}
92110
111+ /* !
112+ * \brief Check if the card can be moved from its current spot
113+ * \return boolean
114+ */
93115bool Card::isMovable ()
94116{
95117 if (mIsOnAceSpot ) {
@@ -101,6 +123,11 @@ bool Card::isMovable()
101123 return isValidParentOf (mChild ) && mChild ->isMovable () && mBoard ->hasEnoughFreecells (countChildren () + 1 );
102124}
103125
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+ */
104131bool Card::isValidParentOf (Card* card)
105132{
106133 if (card == 0 ) {
@@ -112,16 +139,30 @@ bool Card::isValidParentOf(Card* card)
112139 return getValue () - card->getValue () == 1 && card->getBlackRedColor () != getBlackRedColor ();
113140}
114141
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+ */
115148void Card::setOnAceSpot (bool on)
116149{
117150 mIsOnAceSpot = on;
118151}
119152
153+ /* !
154+ * \brief Getter for the "ace spot" flag
155+ * \return boolean
156+ */
120157bool Card::isOnAceSpot ()
121158{
122159 return mIsOnAceSpot ;
123160}
124161
162+ /* !
163+ * \brief Get the value of this card as a string
164+ * \return QString
165+ */
125166QString Card::getValueName ()
126167{
127168 QString cardValue = " " ;
@@ -149,6 +190,10 @@ QString Card::getValueName()
149190 return cardValue;
150191}
151192
193+ /* !
194+ * \brief Get the color of this card as a string
195+ * \return QString
196+ */
152197QString Card::getColorName ()
153198{
154199 QString colorName = " " ;
@@ -181,6 +226,10 @@ cardcolor Card::getColor()
181226 return mColor ;
182227}
183228
229+ /* !
230+ * \brief Convert the color of the card to the "real" (red or black) color
231+ * \return 1 or 2
232+ */
184233char Card::getBlackRedColor ()
185234{
186235 if (mColor == HEARTS || mColor == DIAMONDS) {
@@ -201,6 +250,10 @@ QPoint Card::getChildPosition()
201250 return QPoint (x, y);
202251}
203252
253+ /* !
254+ * \brief Get the position of the card in board coordinates
255+ * \return QPoint
256+ */
204257QPoint Card::getPosition ()
205258{
206259 return mPosition ;
@@ -224,6 +277,10 @@ void Card::animatePosition(QPoint pos)
224277 }
225278}
226279
280+ /* !
281+ * \brief Change the position of the card and its children to pos
282+ * \param pos The new position
283+ */
227284void Card::setPosition (QPoint pos)
228285{
229286 mPosition = pos;
@@ -233,6 +290,10 @@ void Card::setPosition(QPoint pos)
233290 }
234291}
235292
293+ /* !
294+ * \brief Replace the card to its expected position
295+ * \param animate Flag for animating the position update
296+ */
236297void Card::updatePosition (bool animate)
237298{
238299 if (animate) {
@@ -243,6 +304,10 @@ void Card::updatePosition(bool animate)
243304 }
244305}
245306
307+ /* !
308+ * \brief Get the minimum zindex for the card to be visible over all its children
309+ * \return int
310+ */
246311int Card::getTopZIndex ()
247312{
248313 if (mChild ) {
@@ -251,11 +316,20 @@ int Card::getTopZIndex()
251316 return getZIndex () + 1 ;
252317}
253318
319+ /* !
320+ * \brief Getter for the zindex of the card
321+ * \return int
322+ */
254323int Card::getZIndex ()
255324{
256325 return mProxy ->zValue ();
257326}
258327
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+ */
259333void Card::setZIndex (int index, bool cascade)
260334{
261335 mProxy ->setZValue (index);
@@ -269,11 +343,17 @@ void Card::resetZIndex()
269343 setZIndex (mParent ->getZIndex () + 1 );
270344}
271345
346+ /* !
347+ * \brief Display the card
348+ */
272349void Card::show ()
273350{
274351 mWidget ->show ();
275352}
276353
354+ /* !
355+ * \brief Hide the card
356+ */
277357void Card::hide ()
278358{
279359 mWidget ->hide ();
@@ -284,6 +364,10 @@ void Card::select()
284364 mBoard ->selectCard (this );
285365}
286366
367+ /* !
368+ * \brief Update the card design so it is selected or not
369+ * \param selected The new sselected status
370+ */
287371void Card::setSelected (bool selected)
288372{
289373 mSelected = selected;
@@ -294,11 +378,19 @@ void Card::setSelected(bool selected)
294378 }
295379}
296380
381+ /* !
382+ * \brief Check if the card is selected
383+ * \return boolean
384+ */
297385bool Card::isSelected ()
298386{
299387 return mSelected ;
300388}
301389
390+ /* !
391+ * \brief Attempt automatic move with this card
392+ * \see Board::automaticMove()
393+ */
302394void Card::automaticMove ()
303395{
304396 mBoard ->automaticMove (this );
0 commit comments