[英]BlackJack game not working Java
Here's pretty much my issue in steps. 这几乎是我逐步解决的问题。 1. I shuffle my deck and display cards to make sure it shuffled (works perfectly). 1.我对我的卡座和显示卡进行洗牌,以确保洗牌(正常工作)。 2. I play my blackjack game, work perfectly. 2.我玩我的二十一点游戏,工作完美。 3. I shuffle my deck again and display cards again and it doesnt't work. 3.我再次打乱我的卡座并再次显示卡,但它不起作用。 Answers to some questions you guys might ask: 1. The whole program is in a big while loop, the program doesn't end unless i select exit game as an option. 回答您可能会问的一些问题:1.整个程序处于while循环中,除非我选择退出游戏作为选项,否则该程序不会结束。 2. I have tried to display my deck again without shuffling it a second time and it works fine. 2.我试图再次显示我的牌组,而没有第二次改组,它可以正常工作。
public Card deal()
{
Card temp;
temp = storage[top];
storage[top] = null;
top++;
return temp;
}
public void shuffle()
{
int n = storage.length;
for (int i = 0; i < storage.length; i++)
{
// Get a random index of the array past i.
int random = i + (int) (Math.random() * (n - i));
// Swap the random element with the present element.
Card randomElement = storage[random];
storage[random] = storage[i];
storage[i] = randomElement;
}
}
public void display ()
{
for (int i = top; i<52; i++)
storage[i].display();
}
Here is my stack trace Exception in thread "main" java.lang.NullPointerException J of C at blackjack.Deck.display(Deck.java:104) at blackjack.BlackJack.main(BlackJack.java:55) Java Result: 1 这是我在线程“ main”中的堆栈跟踪异常java.lang.NullPointerException J of blackjack.Deck.display(Deck.java:104)在blackjack.BlackJack.main(BlackJack.java:55)上的Java结果:1
case 3:
{
myDeck.display();
break;
}
and my code from deck.display 和我的代码从deck.display
public void display ()
{
for (int i = top; i<storage.length; i++)
storage[i].display();
}
You never reset your top variable, I think you need to do that. 您永远不会重置顶部变量,我认为您需要这样做。 Post your stack trace and the rest of your code, too. 也发布您的堆栈跟踪和其余代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.