[英]Blackjack println game Java programming
I have a problem with my dealerhand method in my blackjack game. 我在二十一点游戏中的发牌人方法有问题。
I have a method to produce a random card from the class deck. 我有一种方法可以从班级甲板上产生一张随机卡片。
The cards have assigned values to them and so forth. 卡已为其分配了值,依此类推。 however the problem lies in the code where i want the dealer to draw a new card, and add the value to the existing total hand value.
但是,问题出在代码中,我希望发牌人开出一张新卡,并将该值添加到现有的总手值中。 the code is a following.
代码如下。
//Basics for the values of dealers cards //经销商卡价值的基础
int dealerHandValue = 0;
int tempDealerHandValue = 0;
int totalDealerHandValue= 0;
//Dealers first card //交易者第一张牌
randomGenNum = (int)((range * Math.random()) + 1)*2;
dealerHandValue = arrayCardRank[randomGenNum];
CardSuit = arrayCardSuit[randomGenNum];
System.out.println("Dealer First Card Shows : " + (CardSuit));
tempDealerHandValue = dealerHandValue;
//Code executed when player stops drawing and stands. //玩家停止绘画并站立时执行的代码。
while (totalDealerHandValue < 18 && totalDealerHandValue <21)
{
randomGenNum = (int)((range * Math.random()) + 1)*2;
dealerHandValue = arrayCardRank[randomGenNum];
CardSuit = arrayCardSuit[randomGenNum];
System.out.println("Dealer next Card Shows : " + (CardSuit));
tempDealerHandValue = dealerHandValue;
totalDealerHandValue = (tempDealerHandValue) + (dealerHandValue);
System.out.println("Dealer total hand value is " + (totalDealerHandValue));
}
{
System.out.println("Dealer stopped drawing");
if (totalDealerHandValue >= totalUserHandValue)
{
System.out.println("Dealer wins");
return;
}
else
System.out.println("Congratulations! You Win!");
return;
}
This method will just add the new cards value to itself, on and on until the while statement ends. 这种方法只会不断地向其自身添加新的卡值,直到while语句结束。
i have gone blind on the problem, and i know it is easily fixed. 我对这个问题视而不见,而且我知道很容易解决。 can anyone help me towards what i am missing?
谁能帮助我实现我所缺少的东西?
you're never incrementing totalDealerHandValue, just overwriting the value over and over again. 您永远不会递增totalDealerHandValue,而只是一遍又一遍地覆盖该值。
Replace these two lines: 替换这两行:
tempDealerHandValue = dealerHandValue;
totalDealerHandValue = (tempDealerHandValue) + (dealerHandValue);
with 同
totalDealerHandValue += dealerHandValue;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.