I need help with my score counter. I trieed some code and it deosnt seem to be working
heres the code in my actor
And heres the code in myWorld
and heres the code in my Counter class
it throws the error in my actor class after the myWorld.getCounter saying cannot find symbol. any help is appreciated please.
Thanks
Actor PIZZA = getOneIntersectingObject(PIZZA.class);
if(PIZZA!=null)
{
World myWorld = getWorld();
myWorld.removeObject(PIZZA);
myWorld space = (myWorld)myWorld;
Counter counter = myWorld.getCounter();
counter.addScore();
myWorld.removeObject(this);
}public class myWorld extends World
{
Counter counter = new Counter();
/**
* Constructor for objects of class myWorld.
*
*/
public myWorld()
{
super(640, 480, 1);
addObject(new MainCharacter(), 10, 390);
addObject(new platformc(), 10, 410);
addObject(new platformc(), 45, 410);
addObject(new platformc(), 150, 380);
addObject(new platformc(), 251, 180);
addObject(new platformc(), 280, 180);
addObject(new platformc(), 300, 210);
addObject(new platformc(), 320, 250);
addObject(new platformc(), 340, 290);
addObject(new platformc(), 360, 330);
addObject(new platformc(), 400, 330);
addObject(new platformc(), 440, 330);
addObject(new platformc(), 573, 330);
addObject(new platformc(), 630, 330);
addObject(new redTube(), 505, 350);
addObject(counter, 45, 30);
addObject(new ladder(), 191, 275);
}
public Counter getCounter()
{
return counter;
}
}import greenfoot.*;
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.GREEN, Color.BLACK));
}
public void addScore()
{
score++;
}
}
