これは推測ゲームの完全なコードの一部です。推測ゲームクラスでエラーが見つかりません
public static void Game(){ //Second page of game with option of continue playing when guessed close enough to answer.
Scanner scan = new Scanner(System.in);
GuessingGame testgame=new GuessingGame();
testgame.Generator();
int num = testgame.GetGenNum();
//Produces a random number between 1 and 100 inclusive of 1 and 100
System.out.println("Guess the target integer which is between 1 and 100 inclusive");
int guess=scan.nextInt();
int difference=(guess-num);
while(guess!=num){
int yesCounter=0;
System.out.println("Guess again " +num+" "+difference);
guess=scan.nextInt();
difference=(guess-num);
///something wrong here, shouldnt repeat if difference too big
if(difference<=5||difference>=-5){ //something wrong with the condition, it says its close enough even tho it isnt.
while(yesCounter<1){
System.out.println("Close enough, do you want to keep Guessing? Y/N ");
yesCounter++;
String play = scan.nextLine();
//play=play1;
while(!(play.equalsIgnoreCase("y")))
{
if(play.equalsIgnoreCase("n")){
System.exit(1);
}
else{
if((play.equalsIgnoreCase("y"))){
invalid();
guess=scan.nextInt();
}
else{
Game(); ///TAKE note as it might restart the game with new random integer
}
}
}
}
}
}
出力は次のようになります。
.........................
プレイ? Y/N
Y
は、再び1及び100包括
推測間44 6
44十分に近い
ターゲット整数を推測に行います推測を続けたいですか? Y/N
は1と100包括
間にあるターゲットの整数を推測..........................
問題は、ユーザーが数字を推測したときの条件は、推測値と生成された数値の差が5以下であれば、その状態が十分に近いことをユーザーに伝え、推測を続けるかどうかを尋ねますが、まだ成就していますが、誰かを助けることができますか?
大変感謝!私は今それを探しています。 – Liquified
while条件の前に、機能しなかった行があったという別の問題がありました。String play = scan.nextLine();コマンドはまったく機能しませんでした。未知の理由から私はまだ見つかっておらず、私を夢中にしています... – Liquified