これをマルチプレイヤーにしようとしています...最大5人のプレイヤーである必要があります。私はすでに基本を持っていますが、マルチプレイヤーで機能させる方法がわかりません。私が試した方法では、各人の推測を保存していません。これは、削除されたバージョンです。
import java.util. * ;
public class randomNumber {
public static void hint(int answer, int guess) {
if(answer < guess) {
System.out.println("Incorrect! \n TOO HIGH!.");
} else if(answer > guess) {
System.out.println("Incorrect! \n TOO LOW!.");
} else if(answer == guess) {
System.out.println("YOU GOT IT!");
}
}
public static void main(String[] args) {
System.out.println("How many Players will be playing?");
int players = players();
int player = 0;
player++;
System.out.println("Player " + player + " Enter a number");
int guess = guess();
int answer = random();
int count = 0;
while (guess != answer) {
hint(answer, guess);
count = count(count);
guess = guess();
}
hint(answer, guess);
System.out.println("It took " + count(count) + " tries!");
}
public static int random() {
return(int)(Math.random() * 100) + 1;
}
public static int players() {
Scanner my_input = new Scanner(System. in );
return my_input.nextInt();
}
public static int guess() {
Scanner my_input = new Scanner(System. in );
return my_input.nextInt();
}
public static int count(int c){
c++;
return c;
}
}