2014-06-05 77 views
-2

基本上,我有一個隨機數生成器,它生成兩個擲骰子並將它們相加。變量M等於這兩個骰子卷的總和。該集合中的一些代碼也適用於用戶看到的內容,例如顯示POINT的Line.set。但是,我試圖設置這一點,一旦設置了該點,如果稍後在代碼中再次達到該點,則用戶將獲勝。如何使用java和GUI在骰子擲骰遊戲中創建POINT

if (M == 4 || M == 5 || M == 6 || M == 8 || M == 9 || M == 10) {  // Determines the POINT value, all of these numbers could be the point 


final int point = M;  // The point is equal to the value that M is when the POINT is rolled the fist time           

final int last = countr; // The last value is trying to determine which roll the POINT was set on, and if that same POINT value is reached later in the code, the user wins 


     if (first == false) { // If this is the first point value rolled,           

      Line.setText("The Point is now: " + point); // The Line Label tells the user what the point is     

      first = true; // To ensure multiple POINTs aren't set, this if statement will now always be true             

     } 

     if (countr > last && point == M && first == true){ // states that if the user has rolled more times after setting the point, the sum of the dice is equal to the point, and the variable that states the point has already been set is true 
       Line.setText("You Win"); // Tells the user they have won 
       W = true; // Setting W to true, which means the user has won 
      } 
    } 

回答

0

我準備好回答,但我需要你爲我澄清一些事情。你究竟是什麼意思

但是,我試圖設置點,並且一旦設置了點,如果稍後在代碼中再次達到該點,則讓用戶獲勝。

具體是關於在代碼後面再次達成的部分。通過什麼獲得?爲了什麼?

+0

好的,所以,在每一輪中,POINT值設置爲4,5,6,8,9,10。這個數字成爲用戶爲了獲勝而需要再次滾動的值。所以如果一輪比賽開始,並且用戶擲出一個5,用戶必須擲出另一個5才能獲勝。 –

+0

我認爲你的問題可能在於「if countr> last」你設置countr =最後並且沒有鏈接任何變量。那麼代碼中的哪個地方會最後?如果你在代碼的另一部分沒有顯示,請糾正我,以便我可以進一步推導出你的答案。 – Nelle

+0

好吧,我想這可能會是一個問題,因爲我試圖讓它最後=當達到POINT時的卷數,而countr =總卷數。你將如何做到這一點,以便如果POINT在第一次滾動時被設置,則last = 1和countr = 1,並且在第二次滾動時last still = 1,而countr = 2,因爲用戶現在滾動了兩次。然後,程序將能夠告訴在POINT被設置後發生了另一個滾動,程序將能夠看到第二個滾動是否等於POINT值,並且允許用戶贏得 –