Я пытаюсь внедрить рекордер в мою стреляющую стрельбу. Все это выполняется в консоли. Мне нужна игра, чтобы сохранить рекорды с именем игрока, поэтому я предполагаю, что мне нужно поместить их в массив. Однако я не уверен, как сделать добавление оценок и имен в массив в моем текущем коде.Как добавить рекордер в свою игру?
public class Target {
public static int score = 0;
public static int i = 0;
public static String gameStart;
public void TargetInfo(Player l) {
Scanner scan = new Scanner(System.in);
//Loop for all 25 targets
for(i=0; i<25; i++) {
System.out.println("\nhit Enter to shoot");
gameStart = scan.nextLine();
if(gameStart.equals("")){
int random1 = (int) (Math.random() * 105 + 15);
//Distance 15-35ft
if (random1 >= 15 && random1 <= 35) {
System.out.println("Your target is " + random1 + "ft away");
int random2 = (int) (Math.random() * 5 + 1);
if(random2<=3) {
score++;
System.out.println("You got one!");
}
else{
System.out.println("You missed");
}
}
//Distance 36-75ft
else if (random1 >=36 && random1 <=75) {
System.out.println("Your target is " + random1 + "ft away");
int random3 = (int) (Math.random() * 21 + 1);
if (random3 <= 11) {
score++;
System.out.println("You got one!");
}
else{
System.out.println("You missed");
}
}
//Target Distance 76-105ft
else if (random1 >=76 && random1 <=105){
System.out.println("Your target is " + random1 + "ft away");
int random4 = (int) (Math.random() * 11 + 1);
if (random4 <= 2) {
score++;
System.out.println("You got one!");
}
else{
System.out.println("You missed");
}
}
}
}
System.out.println(l.name + ", your score is: " + score);
}
}
Сохранить рекорды в файл. – 3kings