Java GameContinue()无法运行。应该循环回main()的开头

Java GameContinue()无法运行。应该循环回main()的开头,java,loops,main,Java,Loops,Main,我目前正在创建一个猪游戏,并有大多数功能的工作。 我需要的代码工作,如果玩家1决定停止滚动,而玩家2决定停止滚动,游戏将循环,直到一名玩家达到20分。目前,代码在运行1次后结束 import java.util.Random; import java.util.Scanner; public class Project3_Part1_Submit { static int playerScore = 0; static int playerTotal = 0; stati

我目前正在创建一个猪游戏,并有大多数功能的工作。 我需要的代码工作,如果玩家1决定停止滚动,而玩家2决定停止滚动,游戏将循环,直到一名玩家达到20分。目前,代码在运行1次后结束

import java.util.Random;
import java.util.Scanner;
public class Project3_Part1_Submit {
    static int playerScore = 0;
    static int playerTotal = 0;
    static int dice = 0;
    static final int FINAL_SCORE = 20;
    static int playerTwoScore = 0;
    static int playerTwoTotal = 0;
    static boolean gameOver = false;
    static boolean turnOver = false;
    static char repeat;
    static String input;
    static Scanner key = new Scanner(System.in);

    static Random rand = new Random();
    
    public static void main(String[] args) {
        PlayerOneTurn();
        PlayerTwoTurn();
        GameContinue();
        if (playerTotal >= FINAL_SCORE) {
            System.out.print("Current Score: Player 1 has " + playerTotal);
            System.out.print(", Player 2 has " + playerTwoTotal);
            System.out.println("");
            System.out.println("Player 1 wins!");
        }
        if (playerTwoTotal >= FINAL_SCORE) {
            System.out.print("Current Score: Player 1 has " + playerTotal);
            System.out.print(", Player 2 has " + playerTwoTotal);
            System.out.println("");
            System.out.println("Player 2 wins!");
        }
    }
    
    public static void PlayerOneTurn() {
        while (turnOver == false) {
            do {
                System.out.print("Player 1 turn total is " + playerTotal);       // welcome line
                System.out.print(". Enter (r)oll or (s)top: ");
                System.out.println("");
                
                input = key.next();                                              // input = next key entered
                repeat = input.charAt(0);
                
                if (repeat == 'r')                                               // if input letter = r
                {
                    dice = rand.nextInt(3) + 1;                                  // set dice to number between 1-6
                    System.out.println("Player 1 rolled: " + dice);              // display number, signifying the amount rolled
                    
                    if (dice == 1)                                               // if the number rolled happens to be 1...
                    {
                        playerScore = 0;                                         // reset score to 0
                        System.out.print("Player 1 lost their turn! ");
                        System.out.print("Player 1 total is " + playerTotal);
                        System.out.println("");
                        return;
                    }
                    else 
                    {
                        playerScore += dice;                                      // add dice amount to player score
                        
                        System.out.print("Player 1 turn total is " + playerScore);// print out total amount earned 
                        System.out.print(" Enter (r)oll or (s)top: ");             // repeat question
                        System.out.println("");
                        input = key.next();
                        repeat = input.charAt(0);
                        if (playerScore >= 20) {
                            playerTotal = playerScore;
                            gameOver = true;
                            return; 
                        }
                        
                    }
                
                }
                else if (repeat == 's')                                           // if neither option is called
                {
                    return;    
                }
                else 
                {
                    System.out.println("Incorrect entry, please try again");       // prompt retry
                    System.out.println("");
                    input = key.next();
                }
            }while(turnOver == false || dice != 1);
            
            
            playerTotal += playerScore;
            playerScore = 0;
            if (playerTotal >= FINAL_SCORE) {
                // System.out.println("YOU WIN!");
                gameOver = true;
                while (playerTotal >= FINAL_SCORE)
                    ;

                break;
            }
        }       
    }
    
    public static void PlayerTwoTurn() {
        System.out.println("success");
        while (turnOver == false) {
            do {
                System.out.print("Player 2 turn total is " + playerTwoTotal);       // welcome line
                System.out.print(". Enter (r)oll or (s)top: ");
                System.out.println("");
                input = key.next();                                              // input = next key entered
                repeat = input.charAt(0);
                
                if (repeat == 'r')                                               // if input letter = r
                {
                    dice = rand.nextInt(3) + 1;                                  // set dice to number between 1-6
                    System.out.println("Player 2 rolled: " + dice);              // display number, signifying the amount rolled
                    System.out.println("");
                    
                    if (dice == 1)                                               // if the number rolled happens to be 1...
                    {
                        playerTwoScore = 0;                                         // reset score to 0
                        System.out.print("Player 2 lost their turn! ");
                        System.out.print("Player 2 total is " + playerTwoTotal);
                        System.out.println("");
                        return;
                    }
                    else 
                    {
                        playerTwoScore += dice;                                      // add dice amount to player score
                        
                        System.out.print("Player 2 turn total is " + playerTwoScore);// print out total amount earned 
                        System.out.print(" Enter (r)oll or (s)top: ");            // repeat question.
                        System.out.println("");
                        input = key.next();
                        repeat = input.charAt(0);
                        if (playerTwoScore >= 20) {
                            playerTwoTotal = playerTwoScore;
                            gameOver = true;
                            return; 
                        }
                        
                    }
                
                }
                else if (repeat == 's')                                           // if neither option is called
                {
                    turnOver = true;  
                    return; 
                }
                else 
                {
                    System.out.println("Incorrect entry, please try again");       // prompt retry
                    System.out.println("");
                    input = key.next();
                }
            }while(turnOver == false || dice != 1);
            
            
            playerTwoTotal += playerTwoScore;
            playerTwoScore = 0;
            if (playerTwoTotal >= FINAL_SCORE) {
                // System.out.println("YOU WIN!");
                gameOver = true;
                while (playerTwoTotal >= FINAL_SCORE)
                    ;

                break;
            }
        }
    }
    public static void GameContinue() {
        if (playerTotal < 20 && playerTwoTotal < 20) {                          //if neither players totals or 20 or greater
            PlayerOneTurn(); //go back to playerOne
        }
        else //if either one is 20 or greater
        {
            return; //go to main method and finish
        }
    }
    
}
import java.util.Random;
导入java.util.Scanner;
公共类项目3\u第1部分\u提交{
静态int playerScore=0;
静态整数playerTotal=0;
静态整数骰子=0;
静态最终int最终_分数=20;
静态整数playerTwoScore=0;
静态整数playerTwoTotal=0;
静态布尔gameOver=false;
静态布尔转换=假;
静态字符重复;
静态字符串输入;
静态扫描仪键=新扫描仪(System.in);
静态随机兰德=新随机();
公共静态void main(字符串[]args){
playeronturn();
PlayerTwoTurn();
GameContinue();
如果(球员总得分>=最终得分){
系统输出打印(“当前分数:玩家1有”+玩家总数);
系统输出打印(“,播放器2有”+playerTwoTotal);
System.out.println(“”);
System.out.println(“玩家1获胜!”);
}
如果(球员总得分>=最终得分){
系统输出打印(“当前分数:玩家1有”+玩家总数);
系统输出打印(“,播放器2有”+playerTwoTotal);
System.out.println(“”);
System.out.println(“玩家2赢了!”);
}
}
公共静态无效PlayerTurn(){
while(营业额==假){
做{
System.out.print(“玩家1回合总数为”+玩家总数);//欢迎线
系统输出打印(“.Enter(r)oll或(s)top:”);
System.out.println(“”);
输入=键。下一个();//输入=输入的下一个键
重复=输入字符(0);
if(repeat=='r')//如果输入字母=r
{
dice=rand.nextInt(3)+1;//将dice设置为1-6之间的数字
System.out.println(“玩家1掷骰子:“+骰子”);//显示数字,表示掷骰子的数量
if(dice==1)//如果掷骰子的数字正好是1。。。
{
playerScore=0;//将分数重置为0
系统输出打印(“玩家1失去了他们的回合!”);
系统输出打印(“玩家1总计为”+玩家总数);
System.out.println(“”);
返回;
}
其他的
{
playerScore+=骰子;//将骰子数量添加到玩家分数中
System.out.print(“玩家1回合总数为”+玩家核心);//打印获得的总金额
System.out.print(“输入(r)oll或(s)top:”;//重复问题
System.out.println(“”);
输入=key.next();
重复=输入字符(0);
如果(playerScore>=20){
playerTotal=playerCore;
gameOver=true;
返回;
}
}
}
else if(repeat=='s')//如果两个选项都未调用
{
返回;
}
其他的
{
System.out.println(“输入不正确,请重试”);//提示重试
System.out.println(“”);
输入=key.next();
}
}而(营业额==false | |骰子!=1);
playerTotal+=playerCore;
playerScore=0;
如果(球员总得分>=最终得分){
//System.out.println(“你赢了!”);
gameOver=true;
while(玩家总得分>=最终得分)
;
打破
}
}       
}
公共静态无效播放机WOTURN(){
System.out.println(“成功”);
while(营业额==假){
做{
System.out.print(“玩家2回合总数为”+playerTwoTotal);//欢迎行
系统输出打印(“.Enter(r)oll或(s)top:”);
System.out.println(“”);
输入=键。下一个();//输入=输入的下一个键
重复=输入字符(0);
if(repeat=='r')//如果输入字母=r
{
dice=rand.nextInt(3)+1;//将dice设置为1-6之间的数字
System.out.println(“玩家2掷:+骰子);//显示数字,表示掷骰数量
System.out.println(“”);
if(dice==1)//如果掷骰子的数字正好是1。。。
{
playerTwoScore=0;//将分数重置为0
系统输出打印(“玩家2失去了他们的回合!”);
系统输出打印(“玩家2总计为”+playerTwoTotal);
System.out.println(“”);
public static void GameContinue() {
        if (playerTotal < 20 && playerTwoTotal < 20) { //if neither players totals or 20 or greater
            gameOver = false;
            PlayerOneTurn(); //go back to playerOne
        }
        else //if either one is 20 or greater
        {
            return; //go to main method and finish
        }
    }
public static void GameContinue() {
        if (playerTotal < 20 && playerTwoTotal < 20) { //if neither players totals or 20 or greater
            gameOver = false;
            PlayerOneTurn(); //go back to playerOne
            PlayerTwoTurn();
            GameContinue();
        }
        else //if either one is 20 or greater
        {
            return; //go to main method and finish
        }
    }
public static void main(String[] args) {
    while (GameContinue()) {
        PlayerOneTurn();
        PlayerTwoTurn();
    }
    if (playerTotal >= FINAL_SCORE) {
        System.out.print("Current Score: Player 1 has " + playerTotal);
        System.out.print(", Player 2 has " + playerTwoTotal);
        System.out.println("");
        System.out.println("Player 1 wins!");
    }
    if (playerTwoTotal >= FINAL_SCORE) {
        System.out.print("Current Score: Player 1 has " + playerTotal);
        System.out.print(", Player 2 has " + playerTwoTotal);
        System.out.println("");
        System.out.println("Player 2 wins!");
    }
}
public static boolean GameContinue() {
    if (playerTotal < 20 && playerTwoTotal < 20) {
        gameOver = false;
        return true;
    } else {
        return false;
    }
}