0

私の質問は、一般的なゲーム アルゴリズムに関するものではありません。「続行しますか? true または false を入力してください」という質問に「true」と答えると、プログラムは次のように出力します。

"Player one, throw your shape(rock, paper, scissors)! 
 Player two, throw your shape(rock, paper, scissors)!"  

したがって、最初のサイクルでは値を入力できますが、2 番目のサイクルでは入力できません。どうすれば修正できますか?ありがとう。

コード:

public static void main(String[] args) {

        String playerOne;
        String playerTwo;
        Scanner myScan = new Scanner(System.in);
        boolean playAgain = true;

        do 
        {
            System.out.println("Player one, throw your shape(rock, paper, scissors)! ");
            playerOne = myScan.nextLine();        
            System.out.println("Player two, throw your shape(rock, paper, scissors)! ");
            playerTwo = myScan.nextLine();




            if (playerOne.equals("scissors") && playerTwo.equals("rock"))
            {
            System.out.println("Player one lost! Playr two won!");
            } 

              else if (playerOne.equals("scissors") && playerTwo.equals("paper")) 
              {
              System.out.println("Player one won! Player two lost!");
              } 


              else if (playerOne.equals("rock") && playerTwo.equals("paper")) 
              {
               System.out.println("Player one lost! Player two won!");
              }


              else if (playerOne.equals("rock") && playerTwo.equals("scissors")) 
              {
              System.out.println("Player one won! Player two lost!");
              }


              else if (playerOne.equals("paper") && playerTwo.equals("scissors")) 
              {
              System.out.println("Player one lost! Player two won!");
              }


              else if (playerOne.equals("paper") && playerTwo.equals("rock")) 
              {
              System.out.println("Player one won! Player two lost!");
              }

              System.out.println("Do you want to continue? Enter true or false.");
              playAgain = myScan.nextBoolean();

        }while(playAgain);


    }
} 
4

1 に答える 1