首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么每个玩家的积分都在重新分配?

为什么每个玩家的积分都在重新分配?
EN

Stack Overflow用户
提问于 2013-12-15 00:52:23
回答 1查看 112关注 0票数 0

我的记分跟踪器是把两个球员的分数重新分配到原来的号码,每次我都这么做不止一次。

我不明白为什么每当我从任何一个玩家那里夺走更多的生命值,而不是使用之前的生命点数,它只是重置到我所做的任何生命点开始和从那里。

例:玩家-1有100个生命点。我拿走了一个生命点。玩家-1现在有99个生命点。现在我又做了一次。我又夺去了1号玩家的生命点。但是现在,不是从以前的生命点数99中取1,而是从100再取1,第二次给我99分。

我不知道我在哪里犯了一个错误,一直在重新计算分数。

代码语言:javascript
复制
 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;
                }

              }
           }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-15 00:57:53

您从不更改storage_1/2值。

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20590053

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档