如何使用java和GUI在掷骰子游戏中使POINT等于掷骰子

时间:2014-06-05 01:16:07

标签: java user-interface boolean

基本上,我有一个随机数生成器,它生成两个骰子卷,并将它们加在一起。变量M等于这两个骰子卷的总和。此集合中的某些代码也适用于用户看到的内容,例如显示POINT的Line.set。但是,我正在尝试设置该点,并且一旦设置了该点,如果稍后在代码中再次到达该点,则让用户获胜。

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
            }  
    }

1 个答案:

答案 0 :(得分:0)

我准备回答,但我需要你为我澄清一些事情。你到底是什么意思

  

但是,我正在尝试设置该点,一旦设置了该点,如果稍后在代码中再次到达该点,则让用户获胜。

具体来说,代码后面的部分再次到达。到了什么?为了什么?