java如何在游戏中添加高分系统?
我试图在双向飞碟射击游戏中实施高分制。这一切都在控制台中运行。我需要游戏用玩家的名字保存最高分,所以我假设我需要将他们放入一个数组中。不过,我不知道如何在我当前的代码中将分数和名称添加到数组中
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);
}
}
共 (0) 个答案