Skip to content

Commit acdca48

Browse files
committed
documentation
1 parent fe78c43 commit acdca48

File tree

6 files changed

+125
-13
lines changed

6 files changed

+125
-13
lines changed

card.cpp

Lines changed: 102 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
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+
*/
2834
Card::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+
*/
5257
QString 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+
*/
6267
void 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+
*/
7584
int 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+
*/
8397
bool 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+
*/
88106
bool 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+
*/
93115
bool 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+
*/
104131
bool 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+
*/
115148
void Card::setOnAceSpot(bool on)
116149
{
117150
mIsOnAceSpot = on;
118151
}
119152

153+
/*!
154+
* \brief Getter for the "ace spot" flag
155+
* \return boolean
156+
*/
120157
bool Card::isOnAceSpot()
121158
{
122159
return mIsOnAceSpot;
123160
}
124161

162+
/*!
163+
* \brief Get the value of this card as a string
164+
* \return QString
165+
*/
125166
QString 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+
*/
152197
QString 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+
*/
184233
char 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+
*/
204257
QPoint 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+
*/
227284
void 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+
*/
236297
void 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+
*/
246311
int 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+
*/
254323
int 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+
*/
259333
void 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+
*/
272349
void Card::show()
273350
{
274351
mWidget->show();
275352
}
276353

354+
/*!
355+
* \brief Hide the card
356+
*/
277357
void 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+
*/
287371
void 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+
*/
297385
bool Card::isSelected()
298386
{
299387
return mSelected;
300388
}
301389

390+
/*!
391+
* \brief Attempt automatic move with this card
392+
* \see Board::automaticMove()
393+
*/
302394
void Card::automaticMove()
303395
{
304396
mBoard->automaticMove(this);

card.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ class CardProxy;
3030
class Board;
3131
class QPixmap;
3232

33+
/*!
34+
* \brief A Card
35+
*/
3336
class Card : public AbstractCardHolder
3437
{
3538
Q_OBJECT
3639
public:
37-
Card();
3840
Card(cardcolor color, cardvalue value, Board* board);
3941

4042
void setParent(AbstractCardHolder*, bool = false);
@@ -49,9 +51,7 @@ class Card : public AbstractCardHolder
4951

5052
QString getValueName();
5153
QString getColorName();
52-
void presents();
5354
QString getLabel();
54-
QPixmap getWidgetPixmap();
5555

5656
cardvalue getValue();
5757
cardcolor getColor();

freecell.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222

2323
#include <QFrame>
2424

25+
/*!
26+
* \brief Constructor
27+
* \param board
28+
*/
2529
Freecell::Freecell(Board* board) : CardSpot(board)
2630
{
2731
mProxy = new CardSpotProxy(this);

freecell.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
class Board;
2424

25+
/*!
26+
* \brief A Freecell for holding cards
27+
*/
2528
class Freecell : public CardSpot
2629
{
2730
public:

mainwindow.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
#include <QMenuBar>
2121
#include <QApplication>
2222

23+
/*!
24+
* \brief Constructor
25+
* \param parent The parent widget
26+
*/
2327
MainWindow::MainWindow(QWidget *parent) :
2428
QMainWindow(parent)
2529
{
@@ -38,12 +42,18 @@ MainWindow::MainWindow(QWidget *parent) :
3842
newGame();
3943
}
4044

45+
/*!
46+
* \brief Start a new game
47+
*/
4148
void MainWindow::newGame()
4249
{
4350
endGame();
4451
mBoard->dealCards();
4552
}
4653

54+
/*!
55+
* \brief Triggers the end of a game
56+
*/
4757
void MainWindow::endGame()
4858
{
4959
mBoard->collectCards();

mainwindow.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
class Board;
2424

25+
/*!
26+
* \brief The MainWindow of the application
27+
*/
2528
class MainWindow : public QMainWindow
2629
{
2730
Q_OBJECT

0 commit comments

Comments
 (0)