我正在尝试解决一个问题,即我在抽完所有牌后尝试重置我的牌组。当我到达牌组的尽头时,我确实应该收到消息Deck is empty! You must recreate and reshuffle deck of cards!
,但是一旦牌组被重新创建并重新洗牌,它仍然会不断显示此消息。
所以我将 Card 对象传递给以堆栈方式存储在数组中的 Deck 类。
为什么我会在确实重置纸牌的地方得到这样的输出?
deal, bet, hit, stay, split, leave: deal
Drawing Player's card... 9 ♥
Drawing Dealer's card... A ♣
Drawing Player's card... 7 ♦
Drawing Dealer's card... K ♦
Dealers Hand: K_♦ A_♣ = 21
Players Hand: 7_♦ 9_♥ = 16
Dealer has BLACKJACK!
deal, bet, hit, stay, split, leave: deal
Deck is empty! You must recreate and reshuffle deck of cards!
Creating deck...
Shuffling deck...
Drawing Player's card... 7 ♥
Drawing Dealer's card... 5 ♥
Drawing Player's card... K ♠
Drawing Dealer's card... 6 ♦
Dealers Hand: 6_♦ 5_♥ = 11
Players Hand: K_♠ 7_♥ = 17
deal, bet, hit, stay, split, leave: deal
Deck is empty! You must recreate and reshuffle deck of cards!
Creating deck...
Shuffling deck...
Drawing Player's card... Q ♦
Drawing Dealer's card... 9 ♥
Drawing Player's card... 8 ♥
Drawing Dealer's card... 10 ♠
Dealers Hand: 10_♠ 9_♥ = 19
Players Hand: 8_♥ Q_♦ = 18
deal, bet, hit, stay, split, leave: deal
Deck is empty! You must recreate and reshuffle deck of cards!
Creating deck...
Shuffling deck...
Drawing Player's card... 3 ♣
Drawing Dealer's card... 6 ♠
Drawing Player's card... 4 ♠
Drawing Dealer's card... K ♠
Dealers Hand: K_♠ 6_♠ = 16
Players Hand: 4_♠ 3_♣ = 7
deal, bet, hit, stay, split, leave:
这就是我重置牌组的方式:
private static Deck createDeck(Deck deck)
{
System.out.println("Creating deck...");
deck = new Deck(DECKSIZE);
deck.createDeck();
System.out.println("Shuffling deck...");
deck.shuffleDeck();
return deck;
}
这就是我检查甲板是否为空的方式:
private static Deck checkDeck(Deck deck)
{
if(deck == null)
return createDeck(deck);
if(deck.isEmpty())
{
deck = new Deck(DECKSIZE);
System.out.print("Deck is empty! You must recreate and reshuffle deck of cards!\n");
return createDeck(deck);
}
else
return deck;
}
我每次抽牌前都会检查牌组:
public static void drawFromDeck(Deck deck, Hand hand)
{
deck = checkDeck(deck);
Card temp = new Card(deck.pop());
System.out.println("Drawing " + hand.getName() + "'s card... " + temp.toString());
hand.insert(temp);
System.out.print("\n");
}
初始绘制()
private static void initialDraw(Deck deck, Hand player, Hand dealer)
{
deck = checkDeck(deck);
drawFromDeck(deck, player); // drawing players card
deck = checkDeck(deck);
drawFromDeck(deck, dealer); // drawing dealers card
deck = checkDeck(deck);
drawFromDeck(deck, player); // drawing players card
deck = checkDeck(deck);
drawFromDeck(deck, dealer); // drawing dealers card
System.out.print("Dealers Hand:");
dealer.displayHand();
System.out.print(" = " + dealer.getHandTotal() + "\n");
System.out.print("Players Hand:");
player.displayHand();
System.out.print(" = " + player.getHandTotal() + "\n");
checkInitialDraw(player, dealer);
}