Hello Guys i made a Wack a mole program where moles appears in random position. But I don't know how i can write the code to record the score when user hit the mole. Can i get help
Thank You
Here is my code:
import java.awt.Color;
import java.awt.event.MouseEvent;
import acm.program.GraphicsProgram;
import acm.util.RandomGenerator;
import acm.graphics.*;
public class Walkamole extends GraphicsProgram
{
public final static double MOLE_SIZE=40;
public void run()
{
setSize(400,430);
addMouseListeners();
GLabel();
createmole();
}
public void createmole()
{
RandomGenerator rgen= RandomGenerator.getInstance();
double StartX=50;
double StartY=50;
for( int i=1; i<=NUM_ROUNDS; i++)
{
GOval mole= new GOval(StartX,StartY,MOLE_SIZE,MOLE_SIZE);
mole= new GOval(45*rgen.nextInt(0,8), 45*rgen.nextInt(0,8),40,40);
mole.setFillColor(Color.YELLOW);
mole.setFilled(true);
pause(800);
add(mole);
}
}
public void mouseClicked(MouseEvent event)
{
GObject itemClicked = getElementAt(event.getX(), event.getY());
if(itemClicked !=null)
{
remove(itemClicked);
}
}
public void GLabel()
{
GLabel label= new GLabel("SCORE:", 0,30);
label.setColor(Color.RED);
add(label);
}
}