So I followed a youtube tutorial on how to create a score counter, the counters there and everything but it won't count anything. If the actor, Pacman, eats a coin the score should go up by one and if he eats a Kirsche (cherrie) the score should go up by 2. But it just doesn't go up. Can somebody help me?
Code of the counter1 class:
code of the actor, who eats the coins/Kirschen:
The world code:
I didn't put anythinf in the coin or Kirsche class, maybe that's the mistake? I don't know, please help me.
import greenfoot.*;
import java.awt.Color;
public class Counter1 extends Actor
{
int score = 0;
public Counter1()
{
setImage(new GreenfootImage("Score: " + score, 24, greenfoot.Color.WHITE, greenfoot.Color.BLACK));
}
public void addScore()
{
score++;
updateImage();
}
public void updateImage()
{
setImage(new GreenfootImage("Score: " + score, 24, greenfoot.Color.WHITE, greenfoot.Color.BLACK));
}
}Actor Kirsche = getOneIntersectingObject (Kirsche.class);
if(Kirsche!=null)
{
World myWorld = getWorld();
myWorld.removeObject(Kirsche);
RoboterWelt roboterwelt = (RoboterWelt) myWorld;
Counter1 counter1 = roboterwelt.getCounter1();
counter1.addScore();
counter1.addScore();
counter1.updateImage();
}
Actor Coin = getOneIntersectingObject (Coin.class);
if(Coin!=null)
{
World myWorld = getWorld();
myWorld.removeObject(Coin);
RoboterWelt roboterwelt = (RoboterWelt) myWorld;
Counter1 counter1 = roboterwelt.getCounter1();
counter1.addScore();
counter1.updateImage();public class RoboterWelt extends World
{
Counter1 counter1 = new Counter1();
private static int zellenGroesse = 20;
private int score = 0;}public Counter1 getCounter1()
{
return counter1;
}
