每回合最多30点,但整体Java Game Pig增加点

时间:2018-09-30 19:31:25

标签: java

我正在做一个项目,该项目每回合最多可以赚取30分,然后,它从计算机生成的播放器切换为人工播放器。
这是用Java编写的,是游戏Pig。我现在的问题是我不知道该怎么做,所以它每回合以30分停下来,但是每回合所获得的分将总得分提高了。
这就是我到目前为止所拥有的!当前发生的情况是,它的总积分为30分,不允许累积更多的积分。
我认为,如果我将转弯得分设为30后将其转为0,但将其增加记录在另一个变量中,这是可行的。 但是,我已经尝试了多次,但所有尝试都没有效果。 任何帮助将不胜感激!

public static void computerTurn(ArrayList<String> diceWords, int playerGameScore, int computerGameScore) {

    while (computerGameScore <= 30) {

        int diceNum1 = (int)(Math.random()*6 + 1);
        int diceNum2 = (int)(Math.random()*6 + 1);

        String diceWord1 = diceWords.get(diceNum1);
        String diceWord2 = diceWords.get(diceNum2);

        System.out.println("\nComputer's turn: ");
        System.out.println("Computer rolled the numbers " + diceWord1 + " and " + diceWord2 + ".");

        computerGameSum(diceWords, playerGameScore, computerGameScore, diceNum1, diceNum2);
    }
}

public static void computerGameSum(ArrayList<String> diceWords, int playerGameScore, int computerGameScore, int diceNum1, int diceNum2) {
    int computerTurnScore = diceNum1 + diceNum2;

    if (computerGameScore >= 100) {
        finalWinner(playerGameScore, computerGameScore);
    }

    if (diceNum1 == 6 && diceNum2 == 6) {
        computerTurnScore = 0;
        computerGameScore = 0;
        System.out.println("DOUBLE SIXES!");
        System.out.println("Computer's turn sum is: " + computerTurnScore + " and game sum would be: " + computerGameScore + ".");
        playerTurn(diceWords, playerGameScore, computerGameScore);
    }

    else if (diceNum1 == 6 || diceNum2 == 6) {
        computerTurnScore = 0;
        System.out.println("TURN OVER! Turn sum is zero and game sum is " + computerGameScore + "!");
        playerTurn(diceWords, playerGameScore, computerGameScore);
    }

    else if (diceNum1 == diceNum2 && diceNum1 != 6 && diceNum2 != 6) {
        computerTurnScore = (diceNum1 + diceNum2)*2;
        System.out.println("DOUBLES!");

        if ((computerGameScore + computerTurnScore) >= 100) {
            computerGameScore = computerGameScore + computerTurnScore;
            System.out.println("Computer's turn sum is: " + computerTurnScore + " and game sum would be: " + computerGameScore + ".");
            finalWinner(playerGameScore, computerGameScore);
        }
    }

    computerGameScore = computerGameScore + computerTurnScore;
    System.out.println("Computer's turn sum is: " + computerTurnScore + " and game sum would be: " + computerGameScore + ".");

    if (computerGameScore >= 100) {
        finalWinner(playerGameScore, computerGameScore);
    }

    computerTurn(diceWords, playerGameScore, computerGameScore);
}

0 个答案:

没有答案