我正在尝试编写二十一点的基本游戏。我遇到的问题是我无法让程序在循环中的第一个选择之后允许输入。例如,如果玩家选择在第一回合击球,它可以工作,但在他们的下一回合,我无法让程序允许输入。这就是我所拥有的。有什么建议么?
import java.util.Scanner;
public class BlackJack {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Welcome to BlackJack");
int guess = 1+(int)(Math.random()*13);
int guess2 = 1+(int)(Math.random()*13);
int answer = guess + guess2;
System.out.println("Player 1 hand: " + answer);
System.out.println("Do you want to hit(1) or stay(2)");
boolean looping = true;
while(looping){
int choice = scan.nextInt();
int guess3 = 1+(int)(Math.random()*13);
int hand = guess3 + answer;
if(choice == 1){
if(guess3 == 1){
System.out.println("Player 1 drew an Ace!");
System.out.println("Player 1 hand: " + hand);
System.out.println("Do you want to hit(1) or stay(2)");
}else if(guess3 > 1 && guess3 <= 10){
System.out.println("Player 1 drew a" + guess3 +"!");
System.out.println("Player 1 hand: " + hand);
System.out.println("Do you want to hit(1) or stay(2)");
}else if(guess3 == 11){
System.out.println("Player 1 drew a Jack!");
System.out.println("Player 1 hand: " + hand);
System.out.println("Do you want to hit(1) or stay(2)");
}else if(guess3 == 12){
System.out.println("Player 1 drew a Queen");
System.out.println("Player 1 hand: " + hand);
System.out.println("Do you want to hit(1) or stay(2)");
}else if(guess3 == 13){
System.out.println("Player 1 drew a King!");
System.out.println("Player 1 hand: " + hand);
System.out.println("Do you want to hit(1) or stay(2)");
}
if(choice == 2){
looping = false;
System.out.println("Player 1 has decided to stay");
}if(hand > 21){
looping = false;
System.out.println("You have busted!");
}