• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying the score of mole

 
Mac Subedi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);


}
}
















 
Campbell Ritchie
Sheriff
Pie
Posts: 49472
64
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pencil, paper and eraser. That is the help you want. Write down in words of one syllable (as far as possible) how you think you ought to gather the scores.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic