I have a function that prints how many guesses there are for a player.
Here is the code:
public void drawString(Graphics g){
g.setColor(Color.RED);
g.drawString("You have " + getN() + " guesses left", 400, 50);
if (lastN != getN()){
repaint();
lastN = getN();
}
}
My problem is that it repaints every other time. I mean:
First it prints: You have 10 guesses left
then it stays 10 when only 9 guesses left
Then it prints: You have 8 guesses left
ect. until there are 0…
how to make it change every time?
So you need to do :
repaintoutside ofifcondition, now in this casepaintwill be called every time