【发布时间】:2020-11-07 03:08:48
【问题描述】:
public static String determiner(String userResponse, int playerHand, int AiHand) {
if (userResponse.equals("hit") && playerHand < 21 && AiHand <21) {
int RandomGen = (int) (Math.random()*11 + 1);
int newHand = playerHand + RandomGen;
int AIRandomGen = (int) (Math.random()*11 + 1);
int newAIHand = AiHand + AIRandomGen;
return "Your current hand is " + newHand;
}
else if (userResponse.equals("stay") && playerHand > 21 && AiHand < 21) {
if (playerHand > AiHand) {
String x = "You won!";
return x;
}
else if (AiHand > playerHand) {
String x = "Sorry, you lost.";
return x;
}
else if (playerHand == 21) {
String x = "You won! You hit the jackpot :0";
return x;
}
else if (AiHand == 21) {
String x = "Sorry, you lost. Enemy hit the jackpot";
return x;
}
}
else if (userResponse.equals("hit") && playerHand > 21) {
String x = "Game over, you lost. You went boom boom";
return x;
}
else {
return null;
}
}
我查看了其他问题,但它们似乎没有帮助。我不知道我的代码有什么问题。有人能帮我吗?这应该是一个检查玩家的手牌是否超过 21 点之类的功能(二十一点游戏)。
【问题讨论】: