The world could not be constructed. The world subclass may not have a public constructor without parameters, or may not be public.
All my world subclasses are public, and there are no errors in the code there.
public CalamityBeginning(int score)
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
prepare();
counter counter = getCounter();
theCounter = new counter();
addObject(theCounter, 203, 104);
theCounter.setCount(score);
}
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
private void prepare()
{
Button button = new Button();
addObject (button,308,170);
button.setLocation(305,180);
CreditsButton creditsbutton = new CreditsButton();
addObject(creditsbutton,305,280);
creditsbutton.setLocation(305,250);
}
public counter getCounter()
{
return theCounter;
}public CalamityBeginning()
{
this(0); // calls your line 1 above
}public CalamityBeginning()
{
this(0); // calls your line 1 above
}public class CalamityBeginning extends World
{
private counter theCounter;
/**
* Constructor for objects of class CalamityBeginning.
*
*/
public CalamityBeginning(int score)
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
prepare();
counter counter = getCounter();
theCounter = new counter();
addObject(theCounter, 203, 104);
theCounter.setCount(score);
}
public CalamityBeginning()
{
this(0); // calls your line 1 above
}
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
private void prepare()
{
Button button = new Button();
addObject (button,308,170);
button.setLocation(305,180);
CreditsButton creditsbutton = new CreditsButton();
addObject(creditsbutton,305,280);
creditsbutton.setLocation(305,250);
}
public counter getCounter()
{
return theCounter;
}
}public class Replay extends Actor
{
/**
* Act - do whatever the Replay wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (Greenfoot.mouseClicked(this)) {
World world;
world = getWorld();
CalamityBeginning calWorld = (CalamityBeginning) getWorld();
counter counter = calWorld.getCounter();
Greenfoot.setWorld(new CalamityBeginning(counter.returnCount()));
}
}
}public class counter extends Actor
{
/**
* Act - do whatever the counter wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
}
public int totalCount = 0;
public void bumpCount(int amount)
{
totalCount += amount;
setImage(new GreenfootImage(""+ totalCount, 30, Color.WHITE, Color.BLACK));
}
public int returnCount(){
return totalCount;
}
public void setCount(int amount)
{
setImage(new GreenfootImage(""+ amount, 30, Color.WHITE, Color.BLACK));
}
}totalCount = amount;
totalCount = amount;
public class Gameover extends World
{
private counter theCounter;
private Replay theButton;
/**
* Constructor for objects of class Gameover.
*
*/
public Gameover(int score)
{
super(600, 400, 1);
prepare();
counter counter = getCounter();
theCounter = new counter();
addObject(theCounter, 203, 104);
theCounter.bumpCount(score);
theButton = new Replay();
addObject(theButton, 290, 225);
}
public void prepare ()
{
}
public counter getCounter()
{
return theCounter;
}
}public class Replay extends Actor
{
public void act()
{
if (Greenfoot.mouseClicked(this)) {
Gameover goWorld = (Gameover) getWorld();
counter counter = goWorld .getCounter();
Greenfoot.setWorld(new CalamityBeginning(counter.returnCount()));
}
}
}