• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Displaying the score of mole

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);


}
}
















 
Marshal
Posts: 79654
381
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
money grubbing section goes here:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic