2013-10-05 66 views
0

我已經閱讀了幾個提交的問題與「骰子游戲」標題,比較它與我寫的,似乎無法找到邏輯錯誤我的循環。有關程序的一切運行良好。但是當我進入點狀態時,當值7或點號達到時,循環不終止。我爲此寫了自己的die和pairOfDie類。下面是代碼:做,而循環爲胡扯遊戲程序沒有正常終止

 //if/else statement for entering point state on initial roll 
     else 
     { 
      System.out.println("You rolled an " + die1.getValue()); 
      System.out.println("You've entered Point State!"); 

      //tally money total and save point number 
      moneyTotal = start + point; 
      pointNumber = die1.getValue(); 

      //print information for user 
      System.out.println("Money Total is: " + moneyTotal); 
      System.out.println("You need to roll another " + pointNumber 
        + " to Win $25 "); 
      System.out.println("Roll anything BUT a 7 or your Point " 
          + "you win $10 and roll again."); 

      /*"point state" loop that should continue to roll die unless 
      the player'spoint number or a 7 is rolled. 
      This should also keep tally of money won during each roll*/ 

      do 
       { 
       //point state roll 
       die1.Value(); 
       System.out.println("You rolled a " + die1.getValue()); 
       System.out.println("You win $10 and " + 
          "get to roll again! "); 
       moneyTotal += point; 
       System.out.println("Money Total is: " + moneyTotal); 

       }while(die1.getValue() != pointNumber || die1.getValue() != 7); 

       //statement to handle if the roll comes up as point number 
       //after entering point state 
       if(die1.getValue()== pointNumber) 
       { 
        System.out.println("You rolled your point number! " 
          + "you win $25 but the game is over. "); 
        moneyTotal += point; 
        System.out.println("Money Total is: " + moneyTotal); 
       } 

       //statement to handle if roll is a 7 after entering 
       //point state 
       else if(die1.getValue() == 7) 
       { 
        System.out.println("You rolled a 7 " 
          + "you lose $25 and the game is over"); 
        moneyTotal -= lose; 
        System.out.println("Money Total is: " + moneyTotal); 
       } 
     } 

編輯:輸出爲
您推出的4您所輸入點的狀態!錢總數是:110
你需要滾出另一個4贏得$ 25
滾動任何東西,但7或你的點你贏了10美元,再滾動。
你捲了10你贏了10美元,再次滾動!總計金額是:120
你擲出8你贏了10美元,再次滾動!現金總額爲:130
你擲出4你贏了10美元,再次滾動!現金總額爲:140
您已將您的積分編號翻了!你贏了25美元,但比賽結束了。總計金額是:150
你擲出7你贏了$ 10並且再次滾動!

回答

0

你需要 「& &」,而不是 「||」,在你的病情。模具必須不等於點OR不等於7.您要繼續,而不等於點AND不等於7.

0

它必須是AND語句而不是OR而條件。

while(die1.getValue() != pointNumber && die1.getValue() != 7); 
+0

哇。我很愚蠢。我覺得我太靠近了。我一直盯着它3個小時。謝謝。對於這個愚蠢的問題抱歉。 –

+0

沒有必要感覺不好,我們都有我們的時刻:D! – samuraijourney