2013-12-15 45 views
0

我的點數跟蹤器每次重複執行時,都會將兩位玩家的分數重設爲原始數字。爲什麼每個玩家的積分都會重置?

我不知道爲什麼每當我從任一玩家身上拿走更多的生命值而不是使用之前的生命點數時,它就會重置爲我所做的任何生命點的開始和結束在那裏形成。

EX: 玩家-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

您永遠不會更改storage_1/2值。

display_2 = storage_2 - ch_2;這樣的一行將繼續計算與原始生命點數(100)的差值,而不是從先前計算的金額中減去。在計算display_x值後,請嘗試更新這些storage_x值。

+0

謝謝你,這是我今天在這個項目中第100萬分鐘的時刻。無論如何,謝謝,我只需要將某些變量的某些區域移動到不同的位置,並且似乎可以修復它。謝謝你的幫助。 – Andyo98

相關問題