import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class MyWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Space extends World
{
counter counter = new counter();
/**
* Constructor for objects of class MyWorld.
*
*/
public Space()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(420, 780, 1);
prepare();
}
public counter getCounter()
{
return counter;
}
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
private void prepare()
{
block0 block0 = new block0();
addObject(block0,218,765);
block0.setLocation(211,750);
block1 block1 = new block1();
addObject(block1,211,704);
block1.setLocation(211,692);
block1.setLocation(91,691);
block1.setLocation(270,690);
block1.setLocation(271,693);
block1.setLocation(211,690);
block1.setLocation(270,691);
block1.setLocation(271,689);
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class MyWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class world2 extends World
{
/**
* Constructor for objects of class MyWorld.
*
*/
public world2()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(420, 780, 1);
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()
{
block0 block0 = new block0();
addObject(block0,218,765);
block0.setLocation(211,750);
block1 block1 = new block1();
addObject(block1,211,704);
block1.setLocation(211,692);
block1.setLocation(91,691);
block1.setLocation(270,690);
block1.setLocation(271,693);
block1.setLocation(211,690);
block1.setLocation(270,691);
block1.setLocation(271,689);
block1.setLocation(211,689);
block1 block12 = new block1();
addObject(block12,210,488);
block1.setLocation(231,682);
removeObject(block1);
block0 block02 = new block0();
addObject(block02,217,697);
block02.setLocation(211,688);
block12.setLocation(211,631);
block12.setLocation(271,632);
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class counter here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class counter extends Actor
{
int score = 0;
/**
* 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()
{
setImage(new GreenfootImage("Score : " + score, 24, Color.GREEN, Color.BLACK));
}
public void addScore()
{
score++;
if (score == 1) Greenfoot.setWorld(new world2());
if (score == 2) Greenfoot.setWorld(new world3());
}
}
