Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By jeol

Thread: Need help with scoring system in game

  1. #1
    jeol is offline Member
    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0

    Default Need help with scoring system in game

    Hi,

    So Im pretty new to java and Im just now getting into 2D graphics and mouse clicks and Im having some Problems with a simple game Im making....
    The game is supposed generate a turtle graphic that I made(very minimum graphic) in a random spot on the back drop. The player is supposed to click the turtle to get a point and then it repaints a turtle somewhere else. The click part is working along with the repainting of the random turtle, however I tried to make a variable("int turtle") that tracks every time you click a turtle(the point system) and I cant get "int turtle" to change! no matter what I do it always stays what i set it in the beginning.... sorry if I sound like a Block head........





    import java.awt.*;
    import javax.swing.JFrame;
    import java.io.File;
    import javax.imageio.ImageIO;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseEvent;
    import java.util.Random;

    public class CatchTheTurtles extends Canvas implements MouseListener
    {

    private int lastX, lastY;
    private String message;
    Image park;
    Random r = new Random();
    int turtle = 1;
    int tsX = 1 + r.nextInt(500);
    int tsY = 1 + r.nextInt(800);


    public CatchTheTurtles() throws Exception
    {


    park = ImageIO.read( new File("park.jpg") );

    addMouseListener(this);
    message = "Catch The Turtles!! " + turtle;

    lastX = 0;
    lastY = 0;





    }



    public void paint( Graphics g )

    {

    g.drawImage(park,100,100,this);

    Color bro = new Color(74,48,13);
    Color gre = new Color(15,59,15);


    tsX = 1 + r.nextInt(500);
    tsY = 1 + r.nextInt(800);

    int tHX = (tsX + 35);
    int tHY = ( tsY );

    int tLX = (tsX + 35);
    int tLY = (tsY + 15);

    int tL2X = (tsX + 5);
    int tL2Y = (tsY + 15);


    g.setColor(Color.black);
    g.drawString(message, 50, 100);

    //turtle shell
    g.setColor(bro);
    g.fillOval(tsX,tsY,40,20);

    g.setColor(gre);


    //turtle head
    g.fillOval(tHX,tHY,20,10);
    //turtle leg
    g.fillRect(tLX,tLY,5,10);
    //turtle leg 2
    g.fillRect(tL2X,tL2Y,5,10);




    }

    public void mouseClicked( MouseEvent evt )
    {


    lastX = evt.getX();
    lastY = evt.getY();


    if ( lastX >= tsX );
    {
    turtle = turtle + 1;
    }



    repaint();
    }

    public void mousePressed( MouseEvent evt )
    {
    }

    public void mouseReleased( MouseEvent evt )
    {
    }

    public void mouseEntered( MouseEvent evt )
    {
    }

    public void mouseExited( MouseEvent evt )
    {
    }

    public static void main(String[] args) throws Exception
    {
    // You can change the title or size here if you want.
    JFrame win = new JFrame("CatchTheTurtles");
    win.setSize(1224,768);
    win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
    win.add( new CatchTheTurtles() );
    win.setVisible(true);
    }


    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Need help with scoring system in game

    I assume that you want the message to display the current "turtle" count. If so, you will need to ask yourself this -- where do you ever update the String held by the message variable?

    Consider adding to your program code that updates message with the new turtle count and then calls repaint() so the new message will be displayed.

  3. #3
    jeol is offline Member
    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0

    Default Re: Need help with scoring system in game

    Ok that makes sense!
    Fubarable likes this.

Similar Threads

  1. Help making a Menu system for Student List System
    By jason3460 in forum New To Java
    Replies: 0
    Last Post: 12-09-2012, 02:39 PM
  2. Replies: 1
    Last Post: 10-10-2011, 09:30 PM
  3. system.out.printf versus system.out.format
    By bigsonny in forum New To Java
    Replies: 10
    Last Post: 06-21-2011, 11:40 PM
  4. get hit scoring?
    By Allasso in forum Lucene
    Replies: 9
    Last Post: 06-04-2010, 05:00 AM
  5. Replies: 1
    Last Post: 02-04-2008, 09:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •