This site requires JavaScript, please enable it in your browser!
Greenfoot back
BellesStruggle
BellesStruggle wrote ...

2017/6/3

Hangman

1
2
3
Super_Hippo Super_Hippo

2017/6/10

#
Yeah, it should have been this:
setImage(images[currentImage]);
BellesStruggle BellesStruggle

2017/6/10

#
Great, it's working! Thank you very much! Now all thats left is figuring out how to exchnage the " _" for the correctly guessed letters... But I'm already much further than I was earlier today so thank you!!
Super_Hippo Super_Hippo

2017/6/10

#
Maybe this helps:
for (int i=0; i<wordToGuess.length(); i++)
{
    if (input.equals(wordToGuess.substring(i,i+1)))
    {
        getWorld().showText(input, 400+20*i, 540);
        lettersRemaining--;
    }
    else
    {
        getWorld().showText("_", 400+20*i, 540);
    }
}
BellesStruggle BellesStruggle

2017/6/10

#
Oh my god, yes it actually works!! Well technically at least, The correctly guessed letters disappear when a new correct one is being guessed... But thank you!!!!!!!
Super_Hippo Super_Hippo

2017/6/10

#
Right.. I guess you could have a String field. At the beginning, it is _____ (depending on the word length) and then when the input is used (last code I posted), the i-th position will be changed to that letter. And before using the else in line 8, you have another else if seeing if there is something else than a _ in the string already.
BellesStruggle BellesStruggle

2017/6/11

#
Well that sounds logical but I wouldnt really know hoe to execute it... But it's not too bad. I can always say having to remember where the corect letters where is an extra challenge ;) Thanks so much for all the help!
Super_Hippo Super_Hippo

2017/6/11

#
I hope you get the idea. I always need to try the subString method to make it work, so chances are there that you have to change some numbers there...
//before 'while (livesLost < 9)'
String currentString = "";
for (int i=0; i<wortLaenge; i++) currentString = currentString + "_";


//....
for (int i=0; i<wordToGuess.length(); i++)
{
    if (input.equals(wordToGuess.substring(i,i+1)))
    {
        currentString = currentString.subString(0, i) + input + currentString.subString(i+1);
    }
    getWorld().showText(currentString.subString(i, i+1), 400+20*i, 540);
}
You need to login to post a reply.
1
2
3