Skip to content

Commit 603db6c

Browse files
committed
A lot of code beautifications
1 parent 7661940 commit 603db6c

10 files changed

+40
-47
lines changed

CardStack.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ CCardStack::CCardStack(QWidget *parent)
1414

1515
void CCardStack::addCard(CCard *cardToAdd)
1616
{
17-
// qDebug() << "CCardStack::addCard";
18-
1917
// Make sure the card is valid
2018
if (cardToAdd)
2119
{
@@ -99,8 +97,6 @@ bool CCardStack::canDropCard(CCard* cardToDrop)
9997
{
10098
Q_UNUSED(cardToDrop);
10199

102-
qDebug() << "CanDropCard not overwritten!";
103-
104100
// By default, allow dropping
105101
return true;
106102
}
@@ -113,5 +109,5 @@ int CCardStack::getIndexOfCard(CCard* card)
113109

114110
void CCardStack::handleCardsChanged()
115111
{
116-
//qDebug() << "handleCardsChanged!";
112+
117113
}

DrawStack.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
CDrawStack::CDrawStack(QWidget* parent)
88
: CCardStack(parent)
99
{
10-
//TODO: why do we need setGeometry? -> does not change anything when commented out
11-
// This widget has always the size of a card
12-
//this->setGeometry(0, 0, CCard::cardTileSize.width(), CCard::cardTileSize.height());
13-
1410
// Create the dummy vbox layout with zero spacing, so they get overlayed
1511
hbox = new CCardHBoxLayout(20, this);
1612

@@ -36,19 +32,16 @@ CDrawStack::CDrawStack(QWidget* parent)
3632
boxLayout->addWidget(drawStackPlaceholder);
3733
boxLayout->addWidget(this);
3834

35+
// Connect the clicked event with the showNextCard function
3936
QObject::connect(drawStackPlaceholder, &CClickableLabel::clicked, this, &CDrawStack::showNextCard);
4037
}
4138

42-
void CDrawStack::addCard(CCard* cardToAdd)
43-
{
44-
CCardStack::addCard(cardToAdd);
45-
}
46-
4739
void CDrawStack::removeCard(CCard* cardToRemove)
4840
{
49-
5041
// Call the superclasses' removeCard
5142
CCardStack::removeCard(cardToRemove);
43+
44+
// Remove the card from the UI
5245
removeCardFromUi();
5346
}
5447

@@ -59,11 +52,12 @@ bool CDrawStack::canDropCard(CCard *cardToDrop)
5952
// Adding a card to the drawStack is not possible, due to that, this method is not necessary
6053
qDebug() << "nothing happens";
6154

62-
return true;
55+
return false;
6356
}
6457

6558
CCard* CDrawStack::getTopCard()
6659
{
60+
// Return the current top card
6761
return getCards()[currentCard];
6862
}
6963

@@ -103,12 +97,11 @@ void CDrawStack::removeCardFromUi()
10397
// The next card should be interactable, if there is one
10498
if(currentCard <= getNumCards()-1)
10599
{
106-
qDebug() << "next card is set to interact";
107100
getCards()[currentCard]->setCanInteract(true);
101+
108102
// When a card is removed, the last third card in the stack will be displayed, if existent
109103
if(currentCard + 2 <= getNumCards()-1)
110104
{
111-
qDebug() << "next card should be displayed";
112105
hbox->push_back(getCards()[currentCard+2]);
113106
getCards()[currentCard+2]->setVisible(true);
114107
}
@@ -117,7 +110,6 @@ void CDrawStack::removeCardFromUi()
117110

118111
void CDrawStack::showNextCard()
119112
{
120-
qDebug() << "current card" << currentCard;
121113
// The cards that shouldn't be displayed have to be invisible, even if the card is removed from
122114
// the layout (the card is still in the background of the layout)
123115
// If there are cards left on the stack, the variable "currentCard" is decremented
@@ -128,8 +120,6 @@ void CDrawStack::showNextCard()
128120
}
129121
else if(currentCard == 0)
130122
{
131-
qDebug() << "set to last card";
132-
133123
// CurrentCard = 0 means, that the stack is empty, so the drawStack gets recycled
134124
drawStackPlaceholder->setPixmap(cardBackPixmap);
135125

DrawStack.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class CDrawStack : public CCardStack
1818

1919
public:
2020
//~ Begin CCardStack interface
21-
virtual void addCard(CCard *cardToAdd) override;
2221
virtual void removeCard(CCard *cardToRemove) override;
2322
virtual bool canDropCard(CCard* cardToDrop) override;
2423
virtual CCard* getTopCard() override;

FinalStack.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#include "Main.h"
55
#include <QDebug>
66

7+
// Set the static variables
8+
int CFinalStack::NumCardsToRender = 5;
9+
710
CFinalStack::CFinalStack(QWidget* parent, ECardSymbol symbol)
811
: CCardStack(parent)
912
, stackSymbol(symbol)
@@ -28,15 +31,10 @@ CFinalStack::CFinalStack(QWidget* parent, ECardSymbol symbol)
2831

2932
void CFinalStack::addCard(CCard* cardToAdd)
3033
{
31-
// Hide the current top card, if any
32-
/*if (this->getNumCards() > 0)
33-
{
34-
this->getTopCard()->hide();
35-
}*/
36-
3734
// Call the superclasses' addCard
3835
CCardStack::addCard(cardToAdd);
3936

37+
// Add it to the vbox
4038
vbox->addWidget(cardToAdd);
4139
}
4240

@@ -48,13 +46,8 @@ void CFinalStack::removeCard(CCard* cardToRemove)
4846
// Call the superclasses' removeCard
4947
CCardStack::removeCard(cardToRemove);
5048

49+
// Remove it from the vbox
5150
vbox->removeWidget(cardToRemove);
52-
53-
// Show the next top card, if any
54-
/*if (this->getNumCards() > 0)
55-
{
56-
this->getTopCard()->show();
57-
}*/
5851
}
5952

6053
bool CFinalStack::canDropCard(CCard *cardToDrop)
@@ -86,10 +79,10 @@ bool CFinalStack::canDropCard(CCard *cardToDrop)
8679

8780
void CFinalStack::handleCardsChanged()
8881
{
89-
// Only show the last five cards to avoid weird overlapping shadows
82+
// Only show the last NumCardsToRender cards to avoid weird overlapping shadows
9083
for (int i = 0; i < getCards().length(); i++)
9184
{
92-
if (i >= getCards().length() - 5)
85+
if (i >= getCards().length() - CFinalStack::NumCardsToRender)
9386
{
9487
getCards()[i]->show();
9588
}

FinalStack.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ class CFinalStack : public CCardStack
1111
{
1212
Q_OBJECT
1313

14+
public:
15+
// How many cards to render on a final stack to avoid glitches with the shadows
16+
static int NumCardsToRender;
17+
1418
public:
1519
// Constructor
1620
CFinalStack(QWidget* parent = nullptr, ECardSymbol symbol = ECardSymbol::Heart);

Game.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,10 @@ void CGame::undoLastMove()
346346

347347
void CGame::restartGame()
348348
{
349+
// Set up the new game board
349350
setUp();
351+
352+
// Reset the score
350353
score = 0;
351354
emit onScoreChanged();
352355
}

GameWindow.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ CGameWindow::CGameWindow(QWidget* parent)
6666
ui->time_label->setStyleSheet("QLabel {color: white}");
6767
ui->statusbar->hide();
6868

69-
QWidget *layout = new QWidget();
69+
// Create the main layout
70+
QWidget* layout = new QWidget();
7071
mainGrid = new QGridLayout();
7172
mainGrid->setSpacing(12);
7273
layout->setLayout(mainGrid);
@@ -75,7 +76,7 @@ CGameWindow::CGameWindow(QWidget* parent)
7576

7677
void CGameWindow::displayHoldingStack(CHoldingStack* stack, int column)
7778
{
78-
// stack->resize(CCard::getCardScreenSize().width(), this->size().height() - stack->pos().y());
79+
// Set a minimum height to avoid layout glitches
7980
stack->setMinimumHeight(CCard::getCardScreenSize().height());
8081
mainGrid->addWidget(stack, 1, column, 1, 1, Qt::AlignTop);
8182

@@ -90,37 +91,43 @@ void CGameWindow::displayHoldingStack(CHoldingStack* stack, int column)
9091

9192
void CGameWindow::displayFinalStack(CFinalStack* final, int column)
9293
{
93-
//final->resize(CCard::getCardScreenSize().width(), this->size().height() - final->pos().y());
94+
// Add the final stack to the widget
9495
mainGrid->addWidget(final, 0, column + 3, 1, 1);
95-
// SetRowMinimumHeight is needed, so that the layout is not changing, when cards are added to the holdingstacks
96+
97+
// setRowMinimumHeight is needed, so that the layout is not changing, when cards are added to the holdingstacks
9698
mainGrid->setRowMinimumHeight(0, 200);
9799
}
98100

99-
void CGameWindow::displayDrawStack(CDrawStack *draw)
101+
void CGameWindow::displayDrawStack(CDrawStack* draw)
100102
{
103+
// Add the stack to the layout
101104
mainGrid->addLayout(draw->getHBoxLayout(), 0, 0, 1, 2);
102105
}
103106

104107
void CGameWindow::incrementMove()
105108
{
109+
// Increment the moves and update the text
106110
++moves;
107111
ui->move_label->setText("Moves: " + QString::number(moves));
108112
}
109113

110114
void CGameWindow::decrementMove()
111115
{
116+
// Decrement the moves and update the text
112117
--moves;
113118
ui->move_label->setText("Moves: " + QString::number(moves));
114119
}
115120

116-
void CGameWindow::incrementScore(int gameScore)
121+
void CGameWindow::incrementScore(int scoreToAdd)
117122
{
118-
score += gameScore;
123+
// Increment the score by the given value and update the text
124+
score += scoreToAdd;
119125
ui->score_label->setText("Score: " + QString::number(score));
120126
}
121127

122128
void CGameWindow::updateTimer()
123129
{
130+
// Add a second to the timer and update the text
124131
*time = time->addSecs(1);
125132
ui->time_label->setText("Timer: " + time->toString("mm:ss"));
126133
}
@@ -137,12 +144,14 @@ Created by Annie Berend (5033782) and Jonathan Verbeek (5058288)");
137144

138145
void CGameWindow::updateScore()
139146
{
147+
// Get the score off the game instance and update the text
140148
score = CMain::get()->getGameInstance()->getScore();
141149
ui->score_label->setText("Score: " + QString::number(score));
142150
}
143151

144152
void CGameWindow::resetGameWindow()
145153
{
154+
// Removes all widgets, resets the time and moves
146155
removeAllWidgets(mainGrid);
147156
time = new QTime(0,0);
148157
moves = 0;
@@ -190,6 +199,7 @@ void CGameWindow::removeAllWidgets(QLayout* layout)
190199

191200
void CGameWindow::setUndoButtonEnabled(bool enabled)
192201
{
202+
// Sets the undo button to be enabled or not
193203
ui->undoButton->setEnabled(enabled);
194204
}
195205

GameWindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CGameWindow : public QMainWindow
3535
// Is called after every move
3636
void incrementMove();
3737
void decrementMove();
38-
void incrementScore(int gameScore);
38+
void incrementScore(int scoreToAdd);
3939

4040
// Clears the gridlayout where all cards are displayed, needed, when new game is chosen
4141
void removeAllWidgets(QLayout *layout);

Main.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ int CMain::run(int argc, char* argv[])
2424
// Create the sound manager instance
2525
soundManager = new CSoundManager();
2626

27-
qDebug() << "Entering app loop";
28-
2927
// Run the app loop
3028
return app.exec();
3129
}

SoundManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ void CSoundManager::setEnableSoundEffects(bool enabled)
5151

5252
void CSoundManager::setEnableMusic(bool enabled)
5353
{
54-
// Set the music's volume
54+
// Set the music's volume so it won't completely stop when disabled
5555
this->bgMusicPlayer->setVolume(enabled ? 50 : 0);
5656
}

0 commit comments

Comments
 (0)