I am working on Jack's programming language and trying to make a hangman game code I have written the code for the game without graphical representation. but I can't find any help for debugging my code so far is
class HangmanGame {
field String secretWord;
field String guessedLetters;
field int maxAttempts;
field int attempts;
constructor HangmanGame new(String word) {
let secretWord = word;
let guessedLetters = "";
let maxAttempts = 6;
let attempts = 0;
return this;
}
method void play() {
var String displayWord;
var char letter;
var int i;
let displayWord = "";
while (i < secretWord.length())
{
let letter = secretWord.charAt(i);
if (guessedLetters.contains(String.valueOf(letter)))
{
let displayWord = displayWord + String.valueOf(letter);
}
else
{
let displayWord = displayWord + "_";
}
let i = i + 1;
}
do Output.printString(displayWord);
while (displayWord != secretWord && attempts < maxAttempts) {
do Output.printString("\nEnter a letter: ");
let char guess = Keyboard.readChar();
let guessedLetters = guessedLetters + String.valueOf(guess);
let boolean found = false;
let int j = 0;
while (j < secretWord.length()) {
if (secretWord.charAt(j) == guess) {
let found = true;
let displayWord = displayWord.substring(0, j) + String.valueOf(guess) + displayWord.substring(j + 1);
}
let j = j + 1;
}
if (!found) {
let attempts = attempts + 1;
do Output.printString("Incorrect guess. Attempts remaining: " + (maxAttempts - attempts));
}
do Output.printString(displayWord);
}
do Output.printString("\nCongratulations! You guessed the word.");
}
}
now while compiling. i have the error In HangmanGame.jack (line 34): In subroutine play: Expected ) In HangmanGame.jack (line 34): In subroutine play: Expected { In HangmanGame.jack (line 34): In subroutine play: Expected statement(do, let, while, return or if)
line 34 is
while (displayWord != secretWord && attempts < maxAttempts) {
what am I doing wrong
i have tried puting brackets it removes the ) and { error but the Expected statement(do, let, while, return or if) stays tehre which make no Sense at all to me