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;
}
}我已经看过其他问题了,但它们似乎没有帮助。我不知道我的代码出了什么问题。有人能帮我吗?THis应该是一个检查玩家的手牌是否超过21岁之类的功能(21点游戏)。
发布于 2020-11-07 11:15:25
else if (AiHand == 21) {
String x = "Sorry, you lost. Enemy hit the jackpot";
return x;
}想象一下,如果AiHand在这里不是21 :它将继续到最后而不返回任何内容。
修复此else if。
https://stackoverflow.com/questions/64724061
复制相似问题