我的记分跟踪器是把两个球员的分数重新分配到原来的号码,每次我都这么做不止一次。
我不明白为什么每当我从任何一个玩家那里夺走更多的生命值,而不是使用之前的生命点数,它只是重置到我所做的任何生命点开始和从那里。
例:玩家-1有100个生命点。我拿走了一个生命点。玩家-1现在有99个生命点。现在我又做了一次。我又夺去了1号玩家的生命点。但是现在,不是从以前的生命点数99中取1,而是从100再取1,第二次给我99分。
我不知道我在哪里犯了一个错误,一直在重新计算分数。
package yu.gi.oh.life.point.counter;
import java.util.Scanner;
public class YuGiOhLifePointCounter {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
double choice_1;
System.out.print("\nEnter the starting life points for player-1: ");
choice_1 = sc.nextDouble();
double storage_1;
storage_1 = choice_1;
double choice_2;
System.out.print("\nEnter the starting life points for player-2: ");
choice_2 = sc.nextDouble();
double storage_2;
storage_2 = choice_2;
double lp1;
System.out.print("\nEnter a 6 to change the life-points of either player: ");
lp1 = sc.nextDouble();
while (lp1 == 6) {
double choose_1_2;
System.out.print("\nEnter a 1 to change player-1's life-points, or enter a 2 to change player-2's life-points: ");
choose_1_2 = sc.nextDouble();
if (choose_1_2 == 1) {
double ch_1;
System.out.print("\nEnter the number subtracted from or added to player-1's life-points: ");
ch_1 = sc.nextDouble();
double c_1;
System.out.print("\nEnter a 1 to subtract this number from player-1's life-points, or enter a 2 to add this number to player-1's life-points: ");
c_1 = sc.nextDouble();
double display_1;
if (c_1 == 1) {
display_1 = storage_1 - ch_1;
System.out.println("\nPlayer-1's life-points are currently " + display_1);
}
if (c_1 == 2) {
display_1 = storage_1 + ch_1;
System.out.println("\nPlayer-1's life-points are currently " + display_1);
}
}
if (choose_1_2 == 2) {
double ch_2;
System.out.print("\nEnter the number subtracted from or added to player-2's life-points: ");
ch_2 = sc.nextDouble();
double c_2;
System.out.print("\nEnter a 1 to subtract this number from player-2's life-points, or enter a 2 to add this number to player-1's life-points: ");
c_2 = sc.nextDouble();
double display_2;
if (c_2 == 1) {
display_2 = storage_2 - ch_2;
System.out.println("\nPlayer-2's life-points are currently " + display_2);
}
if (c_2 == 2) {
display_2 = storage_2 + ch_2;
System.out.println("\nPlayer-2's life-points are currently " + display_2);
}
}
lp1 = 6;
}
}
}发布于 2013-12-15 00:57:53
您从不更改storage_1/2值。
像display_2 = storage_2 - ch_2;这样的线将继续用生命点的原始数目(100)计算差额,而不是从先前计算的数量中减去。在计算storage_x值之后尝试更新这些display_x值。
https://stackoverflow.com/questions/20590053
复制相似问题