我正在创建然后从堆栈中删除项目。在这里,我通过原始套牌到一个方法,我试图决定甲板现在是否为空。如果是空的,我想通过创建新的牌组并将其引用回原始牌组来重置牌组。
我的逻辑出了什么问题?我知道有什么不对的,因为当我到达牌组的末尾时,最后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:
答案 0 :(得分:0)
checkDeck()
函数使用主函数没有的函数,并且没有显示(Deck.shuffleDeck()
)。鉴于您所展示的代码,我最好的猜测是错误就在那里。
答案 1 :(得分:0)
对于我所看到的,您的代码似乎没问题。 问题应该是你在做循环的地方,并向“玩家”询问动作。 看起来你要么每次都要创建一个新的空牌组,要么在这个循环中将其余的牌拿出来。