我开始了我的第一个Java项目,但陷入了类范围。我无法启动以下代码:

if (guessAttemts = MaxGuesses) {System.out.println("Sorry you used all your nine chances. Game Over.)

如果有人能帮助我弄清我对该代码做错的事情,我将不胜感激:此NewGame类如下所示。

class NewGame {
    GuessAttempts GuessAttempts = new GuessAttempts();
        private String WordToGuess;
        private String CorrectGuesses;
        private String misses;
        int guessAttempts;
        int MAX_Guesses = 9;


    public NewGame(String WordToGuess) {
            this.WordToGuess = WordToGuess;
            CorrectGuesses = "";
            misses = "";
            guessAttempts = 0;
    }

    public boolean UserGuessing(char letter) {
        boolean isHit = WordToGuess.indexOf(letter) != -1;
        if (isHit) {
            CorrectGuesses += letter;
        } else {
            misses += letter;
        }
        guessAttempts =+ 1;
        return isHit;
    }
    if (guessAttemts = MaxGuesses) {
        System.out.println("Sorry you used all your nine chances. Game Over.");
    }

}

最佳答案

要与值进行比较,应使用==

这意味着您的if语句应如下所示:

if (guessAttemts == MaxGuesses) {
   System.out.println("Sorry you used all your nine chances. Game Over.");
}

10-05 18:07