我正在创建然后从堆栈中删除项目。在这里,我将原始牌组传递给一个方法,在该方法中我尝试确定牌组现在是否为空。如果为空,我想通过创建新牌组并将其引用回原始牌组来重置牌组。
我的逻辑有什么问题?我知道出了点问题,因为当我到达牌组的尽头,最后 if 语句开始运行时,它不会让我稍后逃脱,并且一直告诉我牌组是空的。
private static Deck checkDeck(Deck deck)
{
if(deck.isEmpty())
{
System.out.print("Deck is empty! You must recreate and reshuffle deck of cards!\n\n");
System.out.println("Creating deck...");
deck = new Deck(DECKSIZE);
deck.createDeck();
System.out.println("Shuffling deck...");
deck.shuffleDeck();
System.out.print("\n");
}
return deck;
}
主类:
public static void main(String[] args) throws IOException
{
Deck deck = null;
Hand playersHand = null;
Hand dealersHand = null;
System.out.println("Creating deck...");
deck = new Deck(DECKSIZE);
deck.createDeck();
// Remove elements of deck...
deck = checkDeck(deck);
temp = new Card(deck.pop());
System.out.println("Drawing players card... " + temp.toString());
playersHand.insert(temp);
}
示例输出运行:
deal, bet, hit, stay, split, leave: deal
Drawing players card... 9 ♣
Drawing dealers card... 6 ♠
Drawing players card... 11 ♠
Drawing dealers card... 13 ♥
Dealers Hand: K_♥ 6_♠ = 16
Players Hand: J_♠ 9_♣ = 19
deal, bet, hit, stay, split, leave: deal
Deck is empty! You must recreate and reshuffle deck of cards!
Creating deck...
Shuffling deck...
Drawing players card... 13 ♥
Drawing dealers card... 6 ♣
Drawing players card... 7 ♠
Drawing dealers card... 11 ♣
Dealers Hand: J_♣ 6_♣ = 16
Players Hand: 7_♠ K_♥ = 17
deal, bet, hit, stay, split, leave: deal
Deck is empty! You must recreate and reshuffle deck of cards!
Creating deck...
Shuffling deck...
Drawing players card... 4 ♦
Drawing dealers card... 9 ♥
Drawing players card... 3 ♥
Drawing dealers card... 9 ♦
Dealers Hand: 9_♦ 9_♥ = 18
Players Hand: 3_♥ 4_♦ = 7
deal, bet, hit, stay, split, leave: