diff --git a/src/gamestate.cpp b/src/gamestate.cpp index 5815409..cfc51f6 100644 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp @@ -21,7 +21,7 @@ void GameState::dealCards() { qDebug() << "Dealing cards"; cleanupBoard(false); - QList deck = PlayingCard::createDeck(); + QList deck = PlayingCard::createDeck(this); // Randomly shuffle the deck std::random_device rd; @@ -36,7 +36,7 @@ void GameState::dealCards() { // Deal exactly i+1 cards to the i-th column for (int j = 0; j <= i; j++) { bool revealed = (j == i); - ColumnSlot* col = new ColumnSlot(deck[index], revealed); + ColumnSlot* col = new ColumnSlot(deck[index], revealed, this); column.append(col); index++; } @@ -59,7 +59,7 @@ void GameState::setupWinningDeck() { cleanupBoard(false); // Create a sorted deck of cards (4 suits, ordered) - QList deck = PlayingCard::createDeck(); + QList deck = PlayingCard::createDeck(this); // Setup the foundation with all cards except one per suit for (int suit = 0; suit < 4; ++suit) { @@ -74,7 +74,7 @@ void GameState::setupWinningDeck() { for (int i = 0; i < 4; ++i) { QList column; PlayingCard* kingCard = deck[i * 13 + 12]; // King of each suit - ColumnSlot* slot = new ColumnSlot(kingCard, true); // Revealed + ColumnSlot* slot = new ColumnSlot(kingCard, true, this); // Revealed column.append(slot); m_columns[i] = column; } @@ -127,7 +127,7 @@ bool GameState::moveThrownCardToColumn(int columnId) { } // Success, perform the move - ColumnSlot* col = new ColumnSlot(cardToMove, true); + ColumnSlot* col = new ColumnSlot(cardToMove, true, this); columnStack.append(col); m_throwawayPile.removeLast(); qDebug() << "> Moving complete"; @@ -494,7 +494,7 @@ bool GameState::tryAutoMoveSingleCard(PlayingCard& cardToMove, int skipColumnId) continue; if (isColumnMoveValid(cardToMove, columnId)) { - ColumnSlot* col = new ColumnSlot(&cardToMove, true); + ColumnSlot* col = new ColumnSlot(&cardToMove, true, this); m_columns[columnId].append(col); qDebug() << "* Auto-moved card " << cardToMove.toString() << " to column " << columnId; return true; @@ -522,7 +522,7 @@ bool GameState::tryAutoMoveMultipleCards(const QList& cards, int s if (isColumnMoveValid(*firstCard, columnId)) { for (auto card : cards) { - ColumnSlot* col = new ColumnSlot(card, true); + ColumnSlot* col = new ColumnSlot(card, true, this); m_columns[columnId].append(col); qDebug() << "* Auto-moved card " << card->toString() << " to column " << columnId; } diff --git a/src/playingcard.cpp b/src/playingcard.cpp index dbb2e8a..55aea7d 100644 --- a/src/playingcard.cpp +++ b/src/playingcard.cpp @@ -59,12 +59,12 @@ QString PlayingCard::toString() const { return valueString() + " of " + suitString(); } -QList PlayingCard::createDeck() { +QList PlayingCard::createDeck(QObject* parent) { QList deck; for (int suitIndex = PlayingCard::Suit::Clubs; suitIndex <= PlayingCard::Suit::Spades; ++suitIndex) { for (int valueIndex = PlayingCard::Value::Ace; valueIndex <= PlayingCard::Value::King; ++valueIndex) { - PlayingCard* card = new PlayingCard(); + PlayingCard* card = new PlayingCard(parent); card->setSuit(static_cast(suitIndex)); card->setValue(static_cast(valueIndex)); deck.append(card); diff --git a/src/playingcard.h b/src/playingcard.h index b9ef68b..124b82f 100644 --- a/src/playingcard.h +++ b/src/playingcard.h @@ -54,7 +54,7 @@ class PlayingCard : public QObject { QString toString() const; - static QList createDeck(); + static QList createDeck(QObject* parent = nullptr); static bool areOppositeColors(const PlayingCard& card1, const PlayingCard& card2); signals: