If you really want to end the game, try this:
Within the World:
if (myMainActor.getY() <= 1)
{
Greenfoot.stop();
}
If you want to do something other than end the game, you should put the code you want to run in the output of the if statement instead of Greenfoot.stop(). Hope that helps
First you need to set up the condition, as I did in my code above.
Then you need something to do when the game ends. I suggest the easiest way is to draw a picture in Paint that you want to display. Create an Actor with no code in it set to your painted image. Finally, when you detect that the player has achieved your goal, display that new Actor on the Screen and call Greenfoot.stop().
That's the easiest way. There are many better and more interesting ways to end a game but try this as a starting point.