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

#
Yes, you are getting the same error, but you should get a line written above the error (you may have to resize the window).
BellesStruggle BellesStruggle

2017/6/10

#
It says this: input: "null --- wordToGuess: rotation" up top and below that the lines of usual lines of error: java.lang.NullPointerException at java.lang.String.indexOf(String.java:1718) at java.lang.String.indexOf(String.java:1698) at Spieler.act(Spieler.java:61) at greenfoot.core.Simulation.actActor(Simulation.java:604) at greenfoot.core.Simulation.runOneLoop(Simulation.java:562) at greenfoot.core.Simulation.runContent(Simulation.java:221) at greenfoot.core.Simulation.run(Simulation.java:211)
Super_Hippo Super_Hippo

2017/6/10

#
Hm, how can input be null if the line before makes sure input is not null? Try changing line 19 to:
if (input != null)
It shouldn't change anything, but who knows...
BellesStruggle BellesStruggle

2017/6/10

#
I realised that I've accidentally deleted the original line 19 which stated that it can't be null. Ow I included it again and now the game just gets stuck on an infinite loop as soon as I press the button which starts the word choosing thing
Super_Hippo Super_Hippo

2017/6/10

#
What I would do is to - add a } in line 15 - change the 'while' in line 16 to 'if' - open an else in line 46 for the rest of the act method (or add 'return;' after line 43) - have a boolean to save if the game already started and have this boolean as a condition for line 1 (+ also adding 'else return;' after the } (line 15) in line 16)
danpost danpost

2017/6/10

#
Or, you could try just inserting the following at around line 18:
Greenfoot.delay(1);
so the keyboard manager has a chance to do its updating.
BellesStruggle BellesStruggle

2017/6/10

#
Oh thanks so much! Danposts idea worked, so at least theres no more error now and also no infinite loop. It does tell me I've lost after 9 wrong tries and it does tell me the already guessed letters. However the "good guess" or "sorry you lost a life/try" text which are being printed into the world keep standing there even when you make a new guess... also it doesn't actually display the correctly guessed letters in the space with the "_" But thank you already for all your help!!
Super_Hippo Super_Hippo

2017/6/10

#
The showText method is an easy method to "print" text on the world's background. If there was a showText-text on the same position already, it will be replaced. So you can write an empty string "" at the position to remove the text. In the for loop starting in line 31, you have to use something like 500+20*i for the x coordinates.
BellesStruggle BellesStruggle

2017/6/10

#
Well that fixed that problem at least, thank you! I still don't know why it suddenly decided to work for the first round when I start greenfoot, but then when I press the button to pick a new word for the second time it starts crashing or going into an infinite loop or something
BellesStruggle BellesStruggle

2017/6/10

#
But thats not too big of a problem for now. I can always just use reset. At least the main part of the game logic is working. It picks a word, I can guess (though it doesnt yet show my guesses aka starts completing the empty space), it tells me how many tries I have left and when I reach the end it tells me what the word was
BellesStruggle BellesStruggle

2017/6/10

#
Ok so since I'm ignoring the bigger issues like the letters not displaying, I'm trying to make my gallows change with each wrong guess. I have a gallows class and all the pictures i have for the gallows work like I can setImage them etc. I guess the easiest way to do it is like if (livesLost = 1) { setImage.....} you know? But since livesLost is an integer in another class, how do I access it?
Super_Hippo Super_Hippo

2017/6/10

#
In your case I would say your could put the whole game to your world class and use the image as the background image. However, since you have it like that already: the gallows class (I am unsure if this is the correct translation, but I know what you mean), because it is only an image, does not have to access anything. You would only need to get a reference to the gallows object and change its image.
BellesStruggle BellesStruggle

2017/6/10

#
Well I'm supposed to do it in an extra class. And it has to change whenever a wrong guess is made. And since the wrong guesses are bing counted by the livesLost or also by totalLives I thought itd be best to use those. BUt I cant access them in that class since theyre part of another one... Is there any way I can like access an int in another class??
Super_Hippo Super_Hippo

2017/6/10

#
As I said, it is only an image, so it shouldn't access anything. Instead, you access this object every time a life is lost.
//whenever a life is lost
((Galgen) getWorld().getObjects(Galgen.class).get(0)).nextImage();
private int currentImage = -1;

private GreenfootImage[] images =
{
    new GreenfootImage("galgen1.png"),
    new GreenfootImage("galgen2.png"),
    //...
};

public Galgen()
{
    nextImage();
}

public void nextImage()
{
    currentImage++;
    images[currentImage];
}
BellesStruggle BellesStruggle

2017/6/10

#
OK now I got it, thank you very much. However it does give me a syntax error with the ,
images [currentImage];
saying that it is not a statement...?
There are more replies on the next page.
1
2
3