Skip to content

Commit 9742850

Browse files
committed
refill card if runs out
1 parent f53a6d4 commit 9742850

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

SOLUTIONS/Exercise 10.1.2/CardGameGUI/blackjack.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ void BlackJack::dealHand()
6464
dealerHand = nullptr;
6565
}
6666

67+
if(deck->count() <= 4) {
68+
qDebug() << "insufficient amount of cards...";
69+
shuffleDeck();
70+
}
71+
6772
playerHand = deck->deal(2);
6873
dealerHand = deck->deal(2);
6974

@@ -84,6 +89,10 @@ void BlackJack::shuffleDeck()
8489

8590
void BlackJack::hitMe()
8691
{
92+
if(deck->count() <= 1) {
93+
qDebug() << "insufficient amount of cards...";
94+
shuffleDeck();
95+
}
8796
qDebug() << "Adding card...";
8897
playerHand->append(deck->last());
8998
deck->removeLast();

0 commit comments

Comments
 (0)