hi i need some help regarding the adding score when clicked.[Disallowed URL]
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class MyWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MyWorld extends World
{
/**
* Constructor for objects of class MyWorld.
*
*/
public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(1000, 600, 1);
prepare();
}
public Score getScoreCounter() {
return score; // this is the field that you created so if you change your classes to capital don't change this
}
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
private void prepare()
{
Dot dot = new Dot();
addObject(dot,500,300);
Score score = new Score();
addObject(score,108,58);
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class dot here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Dot extends prize
{
/**
* Act - do whatever the dot wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
turnrandom();
if (Greenfoot.mouseClicked(this));
{
((MyWorld)getWorld()).getScoreCounter().addScore();
}
}
public void turnrandom()
{
move(5);
if (Greenfoot.getRandomNumber(100) <2)
{
turn(90);
}
if (Greenfoot.getRandomNumber(100) <2)
{
turn(360);
}
if (Greenfoot.getRandomNumber(100) <2)
{
turn(270);
}
if (Greenfoot.getRandomNumber(100) <2)
{
turn(180);
}
}
}