Hey guys
I have a score counter in my greenfoot game and i need to make it increment by one each time the mouse is clicked i have tried adding in an if statement for each time the mouse is clicked but that is not working.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 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 { private int score; public Counter() { score = 0 ; setImage ( new GreenfootImage( 200 , 30 )); update(); } public void addScore() { score++; update(); } public void update() { GreenfootImage img = getImage(); img.clear(); img.setColor(Color.WHITE); img.drawString( "Coloured Balls: " + score, 4 , 20 ); } } |
1 2 3 4 | if (Greenfoot.mouseClicked( null )) { score++; } |
1 2 3 4 | if (Greenfoot.mouseClicked( null )) { addScore(); } |
1 2 3 4 | if (Greenfoot.mouseClicked( null )) { addScore(); } |
1 2 3 4 5 6 7 | public void act() { if (Greenfoot.mouseClicked( null )) { addScore(); } } |