Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用java和GUI使掷骰子游戏中的点数等于掷骰子_Java_User Interface_Boolean - Fatal编程技术网

如何使用java和GUI使掷骰子游戏中的点数等于掷骰子

如何使用java和GUI使掷骰子游戏中的点数等于掷骰子,java,user-interface,boolean,Java,User Interface,Boolean,基本上,我有一个随机数生成器,可以生成两卷模具,并将它们相加。变量M等于这两个掷骰子的总和。此集合中的某些代码也适用于用户看到的内容,例如显示点的Line.set。但是,我正在尝试设置该点,一旦设置了该点,如果稍后在代码中再次达到该点,则让用户获胜 if (M == 4 || M == 5 || M == 6 || M == 8 || M == 9 || M == 10) { // Determines the POINT value, all of these numbers cou

基本上,我有一个随机数生成器,可以生成两卷模具,并将它们相加。变量M等于这两个掷骰子的总和。此集合中的某些代码也适用于用户看到的内容,例如显示点的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
            }  
    }

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

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


特别是关于的部分,在代码的后面再次提到。通过什么到达?为了什么?

好的,在每一轮中设置一个点值,即4、5、6、8、9、10。这个数字成为用户需要再次滚动才能获胜的数字。因此,如果一轮开始,用户掷5,用户必须再掷5才能获胜。我认为您的问题可能在于“if countr>last”您将countr=设置为last,并且没有链接任何变量。那么countr>将在代码中的什么位置持续?如果您在代码的另一部分中没有显示,请更正我,以便我可以进一步推断您的答案。好的,我想这可能是一个问题,因为我试图使它成为最后一个=到达点时的转鼓数,countr=转鼓总数。如果在第一次滚动时设定了点,那么last=1和countr=1,在第二次滚动时last仍然=1,但countr=2,因为用户现在已经滚动了两次。然后,程序将能够在设定点后告知发生了另一次掷骰,并且程序将能够查看第二次掷骰是否等于该点值,并允许用户获胜