为什么每个玩家的积分都会重置?

时间:2013-12-15 00:52:24

标签: java reset points

我的点跟踪器每次不止一次将两个玩家的积分重置为原始号码。

我无法弄清楚为什么每当我从任何一个玩家身上夺走更多的生命点,而不是使用之前的生命点数时,它只会重置为我所做的任何生命点开始并形成的形式那里。

EX: player-1有100点生命值。 我带走了1点生命点。 玩家-1现在有99个生命点。 现在我再做一次。 我从球员1中夺走了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;
                }

              }
           }

1 个答案:

答案 0 :(得分:1)

您永远不会更改storage_1/2值。

display_2 = storage_2 - ch_2;之类的线将继续计算与原始生命点数(100)的差异,而不是从先前计算的数量中减去。在计算storage_x值后,请尝试更新这些display_x值。