Register parent QObjects properly
This commit is contained in:
parent
aa446e9c43
commit
36167edc78
|
@ -21,7 +21,7 @@ void GameState::dealCards() {
|
||||||
qDebug() << "Dealing cards";
|
qDebug() << "Dealing cards";
|
||||||
cleanupBoard(false);
|
cleanupBoard(false);
|
||||||
|
|
||||||
QList<PlayingCard*> deck = PlayingCard::createDeck();
|
QList<PlayingCard*> deck = PlayingCard::createDeck(this);
|
||||||
|
|
||||||
// Randomly shuffle the deck
|
// Randomly shuffle the deck
|
||||||
std::random_device rd;
|
std::random_device rd;
|
||||||
|
@ -36,7 +36,7 @@ void GameState::dealCards() {
|
||||||
// Deal exactly i+1 cards to the i-th column
|
// Deal exactly i+1 cards to the i-th column
|
||||||
for (int j = 0; j <= i; j++) {
|
for (int j = 0; j <= i; j++) {
|
||||||
bool revealed = (j == i);
|
bool revealed = (j == i);
|
||||||
ColumnSlot* col = new ColumnSlot(deck[index], revealed);
|
ColumnSlot* col = new ColumnSlot(deck[index], revealed, this);
|
||||||
column.append(col);
|
column.append(col);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ void GameState::setupWinningDeck() {
|
||||||
cleanupBoard(false);
|
cleanupBoard(false);
|
||||||
|
|
||||||
// Create a sorted deck of cards (4 suits, ordered)
|
// Create a sorted deck of cards (4 suits, ordered)
|
||||||
QList<PlayingCard*> deck = PlayingCard::createDeck();
|
QList<PlayingCard*> deck = PlayingCard::createDeck(this);
|
||||||
|
|
||||||
// Setup the foundation with all cards except one per suit
|
// Setup the foundation with all cards except one per suit
|
||||||
for (int suit = 0; suit < 4; ++suit) {
|
for (int suit = 0; suit < 4; ++suit) {
|
||||||
|
@ -74,7 +74,7 @@ void GameState::setupWinningDeck() {
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
QList<ColumnSlot*> column;
|
QList<ColumnSlot*> column;
|
||||||
PlayingCard* kingCard = deck[i * 13 + 12]; // King of each suit
|
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);
|
column.append(slot);
|
||||||
m_columns[i] = column;
|
m_columns[i] = column;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ bool GameState::moveThrownCardToColumn(int columnId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Success, perform the move
|
// Success, perform the move
|
||||||
ColumnSlot* col = new ColumnSlot(cardToMove, true);
|
ColumnSlot* col = new ColumnSlot(cardToMove, true, this);
|
||||||
columnStack.append(col);
|
columnStack.append(col);
|
||||||
m_throwawayPile.removeLast();
|
m_throwawayPile.removeLast();
|
||||||
qDebug() << "> Moving complete";
|
qDebug() << "> Moving complete";
|
||||||
|
@ -494,7 +494,7 @@ bool GameState::tryAutoMoveSingleCard(PlayingCard& cardToMove, int skipColumnId)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (isColumnMoveValid(cardToMove, columnId)) {
|
if (isColumnMoveValid(cardToMove, columnId)) {
|
||||||
ColumnSlot* col = new ColumnSlot(&cardToMove, true);
|
ColumnSlot* col = new ColumnSlot(&cardToMove, true, this);
|
||||||
m_columns[columnId].append(col);
|
m_columns[columnId].append(col);
|
||||||
qDebug() << "* Auto-moved card " << cardToMove.toString() << " to column " << columnId;
|
qDebug() << "* Auto-moved card " << cardToMove.toString() << " to column " << columnId;
|
||||||
return true;
|
return true;
|
||||||
|
@ -522,7 +522,7 @@ bool GameState::tryAutoMoveMultipleCards(const QList<PlayingCard*>& cards, int s
|
||||||
|
|
||||||
if (isColumnMoveValid(*firstCard, columnId)) {
|
if (isColumnMoveValid(*firstCard, columnId)) {
|
||||||
for (auto card : cards) {
|
for (auto card : cards) {
|
||||||
ColumnSlot* col = new ColumnSlot(card, true);
|
ColumnSlot* col = new ColumnSlot(card, true, this);
|
||||||
m_columns[columnId].append(col);
|
m_columns[columnId].append(col);
|
||||||
qDebug() << "* Auto-moved card " << card->toString() << " to column " << columnId;
|
qDebug() << "* Auto-moved card " << card->toString() << " to column " << columnId;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,12 +59,12 @@ QString PlayingCard::toString() const {
|
||||||
return valueString() + " of " + suitString();
|
return valueString() + " of " + suitString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<PlayingCard*> PlayingCard::createDeck() {
|
QList<PlayingCard*> PlayingCard::createDeck(QObject* parent) {
|
||||||
QList<PlayingCard*> deck;
|
QList<PlayingCard*> deck;
|
||||||
|
|
||||||
for (int suitIndex = PlayingCard::Suit::Clubs; suitIndex <= PlayingCard::Suit::Spades; ++suitIndex) {
|
for (int suitIndex = PlayingCard::Suit::Clubs; suitIndex <= PlayingCard::Suit::Spades; ++suitIndex) {
|
||||||
for (int valueIndex = PlayingCard::Value::Ace; valueIndex <= PlayingCard::Value::King; ++valueIndex) {
|
for (int valueIndex = PlayingCard::Value::Ace; valueIndex <= PlayingCard::Value::King; ++valueIndex) {
|
||||||
PlayingCard* card = new PlayingCard();
|
PlayingCard* card = new PlayingCard(parent);
|
||||||
card->setSuit(static_cast<PlayingCard::Suit>(suitIndex));
|
card->setSuit(static_cast<PlayingCard::Suit>(suitIndex));
|
||||||
card->setValue(static_cast<PlayingCard::Value>(valueIndex));
|
card->setValue(static_cast<PlayingCard::Value>(valueIndex));
|
||||||
deck.append(card);
|
deck.append(card);
|
||||||
|
|
|
@ -54,7 +54,7 @@ class PlayingCard : public QObject {
|
||||||
|
|
||||||
QString toString() const;
|
QString toString() const;
|
||||||
|
|
||||||
static QList<PlayingCard*> createDeck();
|
static QList<PlayingCard*> createDeck(QObject* parent = nullptr);
|
||||||
static bool areOppositeColors(const PlayingCard& card1, const PlayingCard& card2);
|
static bool areOppositeColors(const PlayingCard& card1, const PlayingCard& card2);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
Loading…
Reference in a new issue