Results 1 to 3 of 3
- 12-24-2012, 06:23 PM #1
Member
- Join Date
- Dec 2012
- Posts
- 5
- Rep Power
- 0
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);
}
}
-
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.
- 12-24-2012, 06:58 PM #3
Member
- Join Date
- Dec 2012
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
Help making a Menu system for Student List System
By jason3460 in forum New To JavaReplies: 0Last Post: 12-09-2012, 01:39 PM -
Need some advice with my sch work. Bowling Scoring Program.
By peter85 in forum New To JavaReplies: 1Last Post: 10-10-2011, 08:30 PM -
system.out.printf versus system.out.format
By bigsonny in forum New To JavaReplies: 10Last Post: 06-21-2011, 10:40 PM -
get hit scoring?
By Allasso in forum LuceneReplies: 9Last Post: 06-04-2010, 04:00 AM -
Feature extraction from a text file in java. this is used for scoring the sentences
By joe_2110 in forum Advanced JavaReplies: 1Last Post: 02-04-2008, 08:26 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks