Hello, I'm trying to make a counter. I need some help here.
This is the world's code:
This is the counter's code:
This is the spider's code:
I want to make it so everytime the spider eats an ant, the score goes up.
public class Floor extends World
{
/**
* Constructor for objects of class Floor.
*
*/
public Floor()
{
super(600, 400, 1);
}
Counter counter = new Counter();
public Counter getCounter()
{
return counter;
}
private void prepare()
{
addObject(counter,6,0);
Spider spider = new Spider();
addObject(spider,5,1);
Spider spider2 = new Spider();
addObject(spider2,1,1);
}
}public class Counter extends Actor
{
private int totalCount = 0;
public Counter()
{
setImage(new GreenfootImage("0",20,Color.WHITE, Color.BLACK));
}
public void bumpCount(int amount)
{
totalCount += amount;
setImage(new GreenfootImage("" + totalCount, 20, Color.WHITE, Color.BLACK));
}
} Actor Ant;
Ant = getOneObjectAtOffset(0,0,Ant.class);
if (Ant !=null)
{
World world;
world = getWorld();
world.removeObject(Ant);
Floor floor = (Floor) getWorld();
Counter counter = floor.getCounter();
Counter.bumpCount(1);
