Results 1 to 2 of 2
Thread: Java Game, Really need help
- 09-11-2010, 05:02 AM #1
Member
- Join Date
- Sep 2010
- Posts
- 60
- Rep Power
- 0
Java Game, Really need help
Hey Guys, This is the assignment that i Received:
This assignment handles topics of events and GUI-elements. It's a little game. The task: create a button that randomly relocates to a different position on the screen each time it is hit. The player has to hit the button 15 times, the score is the time needed. You will be provided a framework that implements the button, the JFrame, the relocation, yet not the event handling.
Your first task: add the necessary event handling and the game-framework (counter, score etc.). Measure and display the time using java's System.currentTimeMillis() method (see API). Please re-label the button each time with the number of remaining hits.
Your second task: to make the game more mean, surround the button with 8 buttons (GridLayout 3x3) which the player is NOT allowed to hit. if the center button is sufficiently small, the game becomes really hard. If the user clicks one of the 8 bad buttons by accident, the following should happen:
first time: the center button becomes smaller, but the game continues.
second time: game over.
Here's the class JumpingButton, your starting point. If you create an instance of this class, a button in the center of the screen will appear. Clicking it results in nothing, since no event handling is built in. The class also has a method 'relocate()'. If you call that class, the button will be displayed at a random position on the screen.
This is the coded I have so far. I cannot go anymore further than this:
package jumpingbutton;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class JumpingButton
extends JFrame
{
JButton theButton; //our jumping button
Dimension screenSize; //class Dimension contains int width, int height
Dimension windowSize;
Random rand = new Random(); //used for generating random numbers
public JumpingButton() {
this.setDefaultCloseOperation(EXIT_ON_CLOSE); /* Frame will exit when close/X is pressed */
windowSize = new Dimension(100,100); /* Constructs new Dimension "windowSize" with values 100 for width and height */
setSize(windowSize.width, windowSize.height); /* Sets window's size to be 100x100 */
theButton = new JButton("Hit me!"); /* Create a JButton labeled with "Hit me!" */
getContentPane().add(theButton); /* Gets the content pane of "this" class, which is a JFrame, and attach the button */
pack();
setVisible(true); /* Display "this" (JFrame) that we attached the button to */
screenSize = Toolkit.getDefaultToolkit().getScreenSize(); /* Gets the screen dimensions, used for repositioning the button */
int windowX = (screenSize.width - windowSize.width ) / 2;
int windowY = (screenSize.height - windowSize.height) / 2; /* Get the coordinates needed to display button at middle of screen */
setLocation(windowX, windowY); /* Sets the window's location to the middle position */
}
public void relocate(){
/*If this function is called, it will reloatce the window to a new random position on the screen */
int x = rand.nextInt(screenSize.width - windowSize.width);
int y = rand.nextInt(screenSize.height - windowSize.height);
setLocation(x,y);
}
public static void main(String[] args){
new JumpingButton();
}
}
I will return the favor to you. THank you
-
Similar Threads
-
help Java game
By rawan in forum JCreatorReplies: 1Last Post: 12-25-2009, 06:43 PM -
Java Game
By MuslimCoder in forum New To JavaReplies: 6Last Post: 11-12-2009, 10:38 AM -
Java 2d game
By Mr.Beans in forum Java 2DReplies: 0Last Post: 08-05-2009, 09:27 PM -
java game
By mayhewj7 in forum New To JavaReplies: 1Last Post: 04-10-2009, 07:01 AM -
Help with my game in java
By lenny in forum New To JavaReplies: 1Last Post: 07-23-2007, 04:40 PM


LinkBack URL
About LinkBacks

Bookmarks