Add a quick function to set up a winning deck
This commit is contained in:
parent
aa611b81ed
commit
492f8cfec4
|
@ -13,6 +13,7 @@ GameState::GameState(QObject *parent)
|
|||
|
||||
void GameState::dealCards()
|
||||
{
|
||||
// BUG: This causes a memory leak when called again
|
||||
qDebug() << "Dealing cards";
|
||||
|
||||
QList<PlayingCard*> deck = PlayingCard::createDeck();
|
||||
|
@ -56,6 +57,47 @@ void GameState::dealCards()
|
|||
emit foundationChanged();
|
||||
}
|
||||
|
||||
void GameState::setupWinningDeck()
|
||||
{
|
||||
// BUG: This causes a memory leak when called again
|
||||
qDebug() << "Setting up a winning deck";
|
||||
|
||||
// Create a sorted deck of cards (4 suits, ordered)
|
||||
QList<PlayingCard*> deck = PlayingCard::createDeck();
|
||||
|
||||
// Setup the foundation with all cards except one per suit
|
||||
for (int suit = 0; suit < 4; ++suit) {
|
||||
QList<PlayingCard*> foundationPile;
|
||||
for (int rank = 1; rank <= 12; ++rank) { // Leave the King (rank 13) out
|
||||
foundationPile.prepend(deck[suit * 13 + rank - 1]);
|
||||
}
|
||||
m_foundation[suit] = foundationPile;
|
||||
}
|
||||
|
||||
// The remaining four Kings are placed in the columns
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
QList<ColumnSlot*> column;
|
||||
PlayingCard* kingCard = deck[i * 13 + 12]; // King of each suit
|
||||
ColumnSlot* slot = new ColumnSlot(kingCard, true); // Revealed
|
||||
column.append(slot);
|
||||
m_columns[i] = column;
|
||||
}
|
||||
|
||||
// Ensure other columns are empty
|
||||
for (int i = 4; i < 7; ++i) {
|
||||
m_columns[i].clear();
|
||||
}
|
||||
|
||||
// The draw pile and throwaway pile are empty
|
||||
m_drawPile.clear();
|
||||
m_throwawayPile.clear();
|
||||
|
||||
emit drawPileChanged();
|
||||
emit throwawayPileChanged();
|
||||
emit columnsChanged();
|
||||
emit foundationChanged();
|
||||
}
|
||||
|
||||
void GameState::drawNextCard()
|
||||
{
|
||||
qDebug() << "Drawing next card.";
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
|
||||
// General functions
|
||||
Q_INVOKABLE void dealCards();
|
||||
Q_INVOKABLE void setupWinningDeck();
|
||||
Q_INVOKABLE void drawNextCard();
|
||||
|
||||
// Manual moves (from X to Y)
|
||||
|
|
Loading…
Reference in a new issue