Well, sort of -- it is just the condition that would be similar (but not quite the same). Line 3 asks if there is a GameOver object in the world -- you would need to ask if there are no players in the world.
import greenfoot.*;
/**
* Write a description of class GameOverScreen here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class GameOverScreen extends World
{
/**
* Constructor for objects of class GameOverScreen.
*
*/
public GameOverScreen()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
if ( ! getObjects(Player_p1.class).isEmpty() ) Greenfoot.stop();
prepare();
}
/**
* Prepare the world for the start of the program. That is: create the initial
* objects and add them to the world.
*/
private void prepare()
{
Back_button back_button2 = new Back_button();
addObject(back_button2, 294, 333);
GameOverText gameovertext = new GameOverText();
addObject(gameovertext, 309, 175);
gameovertext.setLocation(300, 176);
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class CrabWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Playerx2 extends World
{
/**
* Constructor for objects of class CrabWorld.
*
*/
public Playerx2()
{
super(1000, 660, 1);
if ( ! getObjects(Player_1.class).isEmpty() ) Greenfoot.stop();
prepare();if (getObjects(Player_1.class).isEmpty() && getObjects(Player_2.class).isEmpty()) Greenfoot.setWorld(new GameOverScreen());
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class CrabWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Playerx2 extends World
{
/**
* Constructor for objects of class CrabWorld.
*
*/
public Playerx2()
{
super(1000, 660, 1);
if (getObjects(Player_1.class).isEmpty() && getObjects(Player_2.class).isEmpty()) Greenfoot.setWorld(new GameOverScreen());
prepare();
}