When the object eats something the counter will not increase
World
Object thats going to eat another object
And Counter
{
private int countDown = 0;
Counter counter = new Counter();
/**
* Constructor for objects of class WombatWorld.
*
*/
public WombatWorld()
{
super(600, 400, 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()
{
Wombat wombat = new Wombat();
addObject(wombat, 278, 152);
Wombat wombat2 = new Wombat();
addObject(wombat2, 215, 277);
Crab crab = new Crab();
addObject(crab, 455, 274);
Counter counter = new Counter();
addObject(counter, 61, 33);
}
}
import greenfoot.*;
/**
* Write a description of class Wombat here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Wombat extends Actor
{
/**
* Act - do whatever the Wombat wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(4);
if (Greenfoot.getRandomNumber(100) < 10)
{
turn(Greenfoot.getRandomNumber(90) - 45);
}
if (getX() <= 5 || getX() >= getWorld().getWidth() - 5)
{
turn(180);
}
if (getY() <= 5 || getY() >= getWorld().getWidth() - 5)
{
turn(180);
}
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
* 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.BLUE, null));
}
public void addScore()
{
score++;
}
}
