0

I have created a You Lose/You Win message after a player runs out of lives or hits all the bricks. However, the code I've used seems repetitive and that's always bad!

I'm thinking I could put the loop inside the GLabel function, but I'm not sure if/how this would work. What do you think?

Max

breakout GLabel loop

1 Answer 1

1

You could call the initScoreboard() function to create the new GLabel, like this:

GLabel final = initScoreboard(window);
setFont(final, "SansSerif-40");
setColor(final, "GREEN");

if (bricks)
{
    setColor(final, "RED");
    setLabel(final, "Sorry, you lost!");
}
else 
    setLabel(final, "You win! You cleared all bricks!");

setLocation(final, (WIDTH - getWidth(final))/ 2, (HEIGHT + getFontAscent(final))/2);

Since it's the same label, you don't need to repeat the setLocation for both possibilities.

(I used different variable names but you get the idea I hope)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .