I wanted to make a score that counts everytime it touches the Object Essen but it counts all the time could somebody please explain me where my fault is
first i was setting up the class counter with the method Punkterzielen to add up the score by one
then I was setting it into my World class Welt and made the method getCounter so I could later use it later
and then I created in the class Einhorn the method essen which should make that if the Einhorn touches the Essen it disappears and it will add a point to the score
I hope somebody can explain me why the counter just get up without the Einhorn touching the Essen
public class Counter extends Actor
{
int counter= 1;
/**
* 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: " + counter, 40, Color.PINK,Color.WHITE));
}
public void Punkterzielen(){
counter++;
}
}Counter counter= new Counter();
Einhorn unicorn = new Einhorn();
/**
* Constructor for objects of class Welt.
*
*/
public Welt()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(800, 376, 1, false);
//Einhorn in Welt setzen
addObject(unicorn, 100, getHeight()/2);
//Score in Welt setzen
addObject(counter, 700,50);
}
public Counter getCounter()
{
return counter;
}public void essen()
{
if(isTouching(Essen.class)==true);
{World myWorld =getWorld();
Welt welt= (Welt)myWorld;
Counter counter= welt.getCounter();
counter.Punkterzielen();
myWorld.removeObject(getOneIntersectingObject(Essen.class));}
}
