permaculture playing cards*
The moose likes Java in General and the fly likes Displaying the score of mole Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Displaying the score of mole" Watch "Displaying the score of mole" New topic
Author

Displaying the score of mole

Mac Subedi
Greenhorn

Joined: Nov 11, 2011
Posts: 5
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

Joined: Oct 13, 2005
Posts: 38517
    
  23
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.
 
Consider Paul's rocket mass heater.
 
subject: Displaying the score of mole