this is the game over calss code
import Greenfoot.*;
import java.awt.Color;
public class GameOver extends Actor
{
String msgTxt = "GAME OVER";
public GameOver()
{
updateImage();
}
public GameOver(String txt)
{
msgTxt = txt;
updateImage();
}
private void updateImage()
{
GreenfootImage image = new GreenfootImage(getWorld().getWidth(), getWorld().getHeight()); // or whatever size you want the object
image.setColor(Color.cyan); // color of your choice
image.fill();
GreenfootImage txtImg = new GreenfootImage(msgTxt, 36, Color.black, new Color(0, 0, 0, 0)); // colors and font size of your choice
image.drawImage(txtImg, (image.getWidth() - txtImg.getWidth()) / 2, (image.getHeight() - txtImg.getHeight) / 2);
// whatever else you might want to do for the image
setImage(image);
}
}
/**
* Write a description of class gameover here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class gameover extends Actor
{
/**
* Act - do whatever the gameover wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
}
}
and this is the world code
/**
* Write a description of class world1 here.
* a green swirly world
* @author (your name)
* @version (a version number or a date)
*/
public class world1 extends World
{
private counter thecounter;
/**
* Constructor for objects of class world1.
*
*/
public world1()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
thecounter = new counter();
addObject(thecounter, 40, 340);
prepare();
//addbattery();
}
/**
* Prepare the world for the start of the program. That is: create the initial
* objects and add them to the world.
*/
private void prepare()
{
frownyface frownyface = new frownyface();
addObject(frownyface, 559, 150);
you you = new you();
addObject(you, 250, 34);
you.setRotation(360);
battery battery = new battery();
addObject(battery, 310, 43);
Zapper zapper = new Zapper();
addObject(zapper, 300, 28);
battery.setLocation(300, 361);
}
//public void addbattery()
//{
// if (getObjects(battery.class).size() == 0)addObject(battery, 20, 390);
// }
/**
*
*
*
*
*/
public counter getcounter()
{
return thecounter;
}
public act; void()
{
if (getObjects(you.class).isEmpty())
addObject(new GameOver(), getWidth() / 2, getHeight() / 2);
Greenfoot.stop();
return;
}
}
}

