Hey everyone, thanks in advance for your help. I am giving a method here that is a portion of a game I am writing. If you can figure out the issue with it, I would be greatly appreciative.
For some reason, when prompted the question about whether player is 1 or 2, the user must enter 1 or 2 three times before the program reacts. I have initiated my player type variables elsewhere. I know I don't have a catch block yet.
public void setPlayerType() throws InputMismatchException{ while(firstPlayerType == -1){ System.out.println("Will player 1 be human or computer contolled? enter 1 for human, 2 for computer"); if(console.nextInt() < 1 || console.nextInt() > 2) System.out.println("That is not a valid selection"); else this.firstPlayerType = console.nextInt(); }// end while loop if(firstPlayerType == 1) System.out.println("Player 1 will be human controlled"); else System.out.println("Player 1 will be computer controlled."); while(secondPlayerType == -1){ System.out.println("Will player 2 be human or computer contolled? enter 1 for human, 2 for computer"); if(console.nextInt() < 1 || console.nextInt() > 2) System.out.println("That is not a valid selection"); else this.secondPlayerType = console.nextInt(); } if(secondPlayerType == 1) System.out.println("Player 2 will be human controlled"); else System.out.println("Player 2 will be computer controlled."); } //end set player type public int getPlayerType(int playerNumber){ if (playerNumber == 1) return firstPlayerType; else return secondPlayerType; }