[英]java: missing return statement for blackjack game
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;
}
}
I've taken a look at other questions but they don't seem to be helping.我已经查看了其他问题,但它们似乎没有帮助。 I dont' know what is wrong with my code.
我不知道我的代码有什么问题。 Can someone help me?
有人能帮我吗? THis is supposed to be a function that checks if the player's hand is over 21 and stuff like that (Blackjack game).
这应该是一个函数,用于检查玩家的手牌是否超过 21 点之类的(二十一点游戏)。
else if (AiHand == 21) {
String x = "Sorry, you lost. Enemy hit the jackpot";
return x;
}
Imagine what if AiHand
is not 21 here: it'll go on to the end without returning anything.想象一下,如果这里的
AiHand
不是 21 岁会怎样:它会一直持续到最后而不返回任何东西。
Fix this else if
. else if
.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.