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

2013/1/1

Lose/Win screen

comandodude101 comandodude101

2013/1/1

#
In my save the strawberries game, someone suggested I add a screen that tells you if you win and another if you lost. You lose if all of your strawberries are eaten and you if you eat all of the turtles and still have atleast one strawberry left. How would I code the Lose/Win screens?
danpost danpost

2013/1/1

#
Well, first create a sub-class of actor to be the screen that displays the message (whether it be the YOU WIN or the YOU LOSE message). Call it FinalScreen or something like that. The constructor will need a boolean parameter to determine which message to display. The act method of the world should have the following:
if(getObjects(Strawberry.class).isEmpty())
{
    addObject(new FinalScreen(false), getWidth()/2, getHeight()/2);
    Greenfoot.stop();
    return;
}
if(getObjects(Tutle.class).isEmpty())
{
    addObject(new FinalScreen(true), getWidth()/2, getHeight()/2);
    Greenfoot.stop();
    return;
}
comandodude101 comandodude101

2013/1/1

#
Oh ok thanks
You need to login to post a reply.