Code for Pin Ball Game

Ball.java

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

/**

 *

 * @author 00e5

 */

import java.awt.*;//import the all the java.awt library

import java.awt.geom.AffineTransform;//import the java.awt geometry affine transform library

import java.awt.geom.Ellipse2D;//import the java.awt geometry ellipse2D library

import java.awt.geom.Rectangle2D;//import the java.awt geometry rectangle2D library

import java.io.File;//import the java input output file library

 

public class Ball {//class constructer for ball

 

    public Point loc;//create a public variable called loc of type point

    public int rad;//create an integer variable called rad

    protected double changeInX = 0.0;//create a protected variable of type double called changeInX and setting it's initial value to 0.0

    protected double changeInY = 0.0;//create a protected variable of type double called changeInY and setting it's initial value to 0.0

    protected Color color = Color.blue;//create a protected variable of type color called color and set it's value to blue

    public File boundaryCollision = new File(new File(getClass().getResource("dataFiles").getFile()), "HAMMER.WAV");//create a public variable of type file called boundaryCollision and set its value to hammer.wav

    public File colliderCollision = new File(new File(getClass().getResource("dataFiles").getFile()), "EXPLODE.WAV");//create a public variable of type file called colliderCollision and set its value to explode.wav

    public Shape theBall;//create a public variable of type shape called theBall

//    public Rectangle2D ballBox = theBall.getBounds2D();

//    public Rectangle2D collider00Box = GameWorld.collider00.getBounds2D();

//    public Rectangle2D collider01Box = GameWorld.collider01.getBounds2D();

//    public Rectangle2D collider02Box = GameWorld.collider02.getBounds2D();

    public static int score = 0;//create a public static integer vaiable called score and set it's initial vale to 0

    public static int lives = 5;//create a public static integer vaiable called lives and set it's initial vale to 5

 

    public Ball(Point lc, int r) {//method constuctor for ball with inputs of type point and integer having variable names lc and r respectively

        setLoc(lc);//set the value of setLoc to the point variable lc

        setRad(r);//set the value of setRad to the integer value r

    }//closing bracket for the method ball

 

    public void setColor(Color newColor) {//method constructor for the non-returning setColor which takes a variable called newColor of type color

        color = newColor;//set the variable color to the value of newColor

    }//closing bracket for the method setColor

 

    public void setLoc(Point locs) {//method constructor for the non-returning setLoc which takes a point variable called locs

        loc = locs;//set the variable loc to the value of locs

    }//closing bracket for the method setLoc

 

    public void setRad(int rads) {//method constructor for the non-returning setRad which takes an integer variable called rads

        rad = rads;//set the variable rad to the value of rads

    }//closing bracket for the method setRad

 

    public Point getLoc() {//method constructor for the point type getLoc

        return loc;//return the value of loc

    }//closing bracket for the method getLoc

 

    public int getRad() {//method constructor for the integer type getRad

        return rad;//return the value of rad

    }//closing bracket for the method getRad

 

    public void paint(Graphics g) {//method constructor for the non-returning paint which takes a variable g of type graphics

        Graphics2D g1 = (Graphics2D) g;//create a graphic 2d object g1 of type graphics 2d with a value g

        g1.setColor(color);//set the colour of g1 to the value of color

        g1.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);//set the rendering hints of g1

        //g1.fillOval(loc.x - rad, loc.y - rad, 2 * rad, 2 * rad);

 

        theBall = new Ellipse2D.Double(loc.x - rad, loc.y - rad, 2 * rad, 2 * rad);//set the value of theBall to to new ellipse2d double with the value set to loc.x minus a radius and loc.y minus a radius with a size of 2 times a radius

        g1.draw(theBall);//using g1 draw the variable theBall

        g1.fill(theBall);//using g1 fill the variable theBall

 

 

        g1.drawImage(null, AffineTransform.getScaleInstance(1, 1), null);//using g1 draw the image

    }//clsoing bracket for the method paint

 

    public void reflectVert() {//method constructor for the reflectVert method

        changeInY = -changeInY;//change in y direction

    }//closing bracket for the reflectVert method

 

    public void reflectHoriz() {//method constructor for the reflectHoriz method

        changeInX = -changeInX;//chamge in x direction

    }//closing bracket for the reflectHoriz method

 

    public void setMotion(double dx, double dy) {//method constructor setMotion method which takes the double variables dx and dy

        System.out.println("inside motion");//print out of inside motion method

        changeInX = dx;//set the changeInX variable to the value of dx

        changeInY = dy;//set the changeInY variable to the value od dy

    }//closing bracket for the method setMotion

 

    public void moveTo(int x, int y) {//method constructor for the moveTo method which takes two integer variables x and y

        loc.move(x, y);//move the position of the variable loc to the values of x and y

        System.out.println("inside moveto");//system print out for the inside moveTo method

    }//closing bracket for the moveTo method

 

    public void move() {//method constructor for the move method

        loc.translate((int) changeInX, (int) changeInY);//translate the the variable loc by the integer variables changeInX and changeInY

        System.out.println("x = " + loc.x + "  y = " + loc.y);//system print out for the x and y positions

 

        chkBoundary(loc);//call to the chkBoundary method with the variable loc

        System.out.println(loc);//system print out for the loc variable

    }//closing bracket for the method move

 

    public void chkBoundary(Point loc) {//method statement for the chkBoundary method which accepts the point variable loc

        PanelSetup ps = new PanelSetup();//create an instance of the class PanelSetup called ps

 

        if (loc.y >= ps.getHeight()) {//if statement to check the y position of the variable loc against the height of ps

            lives -= 1;//subtract 1 from the variable lives

            PanelWorld.world.reset();//using the world interface of PanelWorld reset it

        }//closing bracket of the if statement

 

        if (loc.y <= (0 + 2 * getRad())) {//if statement to evaluate the loc.y variable is less than twice the radius

            reflectVert();//call to the reflectVert method

            GameAudio.soundClip(boundaryCollision);//call to the GameAudio class to play the variable boundaryCollision

            System.out.println("inside the Vertical if");//system print out to say that we are inside the vertical if statement

        }//closing bracket for the if statement

 

        if (loc.x >= ps.getWidth() - getRad() || loc.x <= 0 + getRad()) {//if statement to evaluate if the variable loc.x is greatrer than or equal to the width of ps or less than or equal to 0 plus a radius

            reflectHoriz();//call to the reflectHoriz method

            GameAudio.soundClip(boundaryCollision);//call to the GameAudio class to play the variable boundaryCollision

            System.out.println("inside the Horiz if");//system print out to say that we are inside the horizontal if statement

        }//closing bracket for the if statement

 

        if (PanelWorld.launch == true && loc.y <= 0 + (2 * getRad())) {//if statement to evaluate if the variable launch is true and that the position of the variable loc.y is less than or equal to 0 plus twice the radius

            setMotion(-3.0, 6.0);//set the value of the method setMotion to -3 and 6

            PanelWorld.launch = false;//set the variable launch to false

        }//closing bracket for the if statement

 

        chkCollision(loc);//call to the chkBoundary method with the vaule of loc

    }//clsing bracket for the method move

 

    public void chkCollision(Point loc) {//method constructor for the chkBoundary method which accepts the point variable loc

        Rectangle2D ballBox = new Rectangle2D.Double(loc.x - (rad - 3), loc.y - (rad - 4), 2 * rad, 2 * rad);//create a 2d rectangle called ballBox which is based on the values of loc.x and loc.y

        Rectangle2D collider00Box = GameWorld.collider00.getBounds2D();//create a bounding box from collider00

        Rectangle2D collider01Box = GameWorld.collider01.getBounds2D();//create a bounding box from collider01

        Rectangle2D collider02Box = GameWorld.collider02.getBounds2D();//create a bounding box from collider02

 

        Rectangle sliderBox = new Rectangle(GameWorld.slider00.getPaddleXLocation(), PanelWorld.world.pnlGameWorld.getHeight()- GameWorld.slider00.paddle.getHeight(null),100,25);//create a rectangle called sliderBox from the variable slide00's height and width

 

        if (ballBox.intersects(collider00Box) || ballBox.intersects(collider01Box) || ballBox.intersects(collider02Box) || ballBox.intersects(sliderBox)) {//if statement to evaluate wether the variabel ballBox intersects the colliders or the paddle

            reflectVert();//call to the reflectVert method

            score += 20;//add 20 to the score

            GameAudio.soundClip(colliderCollision);//call to the GameAudio class to play the colliderCollision variable

        }//closing bracket for the if statement

    }//closing bracket for the method chkCollision method

}//closing bracket for the class constructor

GameAudio.java

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

/**

 *

 * @author Andrew

 */

import java.applet.AudioClip;// import the java applet AudioClip

import sun.audio.*;    //import the sun.audio package

import java.io.*;      //import the java.io package

import java.applet.*;//import the java applet library

 

/**

 *

 * @author Andrew

 */

public class GameAudio {//class constructor for GameAudio

 

    public GameAudio() {//method constructor for the GameAudio method

    }//closing bracket for the method GameAudio

 

    public static void soundClip(File file) {//method constructor for the soundClip method which accepts a file variable file

 

        try {//try statement

 

            InputStream in = new FileInputStream(file);// Open an input stream  to the audio file

            AudioStream as = new AudioStream(in);// Create an AudioStream object from the input stream

            AudioPlayer.player.start(as);// Use the static class member "player" from class AudioPlayer to play clip

        } catch (Exception e) {//closing bracket for the try statement and a catch of exception e

        }//closing bracket for the catch statement

    }//closing bracket for the method soundClip

}//closing bracket for the class

GameWorld.java

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

/*

 * GameWorld.java

 *

 * Created on 10-Feb-2010, 18:06:56

 */

/**

 *

 * @author 00e5

 */

import java.awt.*;//import the java awt library

import java.awt.geom.Ellipse2D;//import the java awt geometry ellipse2D library

 

public class GameWorld extends javax.swing.JPanel {//class constructor for GameWorld

 

    PanelSetup pnlSetup;//create an instance of PanelSetup called pnlSetup

    private int pnlHeight = 0;//set the value of the private integer variable pnlHeight to zero

    private int pnlWidth = 0;//set the value of the private integer variable pnlWidth to zero

    PanelWorld world;//create an interface for the class PanelWorld called world

    Image image;//create an image variable called image

    public static Shape collider00;//create a public static shape variable collider00

    public static Shape collider01;//create a public static shape variable collider01

    public static Shape collider02;//create a public static shape variable collider02

    public static Shape life00, life01, life02, life03;//create the public static shape variables called life00, life01, life02 and life03

    public static Paddle slider00 = new Paddle(350);//create a new instance of the class paddle called slider00 and set its value to 350

 

    /** Creates new form GameWorld */

    public GameWorld(boolean vis) {//method constructor for the method GameWorld which accepts the boolean variable vis

        initComponents();//method called to initComponents

 

        pnlSetup = new PanelSetup();//set the value of the variable pnlSetup to the default vaules of the class PanelSetup

        pnlHeight = pnlSetup.getHeight();//set the vaule of pnlHeight to the value of pnlSetup.getHeight

        pnlWidth = pnlSetup.getWidth();//set the vaule of pnlWidth to the value of pnlSetup.getWidth

        this.setVisible(vis);//set the vaule of setVisible of this method to the value of the variable vis

        this.setBounds(0, 0, pnlWidth, pnlHeight);//set the bounds of this method

        this.setMinimumSize(new Dimension(pnlWidth, pnlHeight));//set the MinimumSize to the dimensions of pnlWidth and pnlHeight

        this.setPreferredSize(new Dimension(pnlWidth, pnlHeight));//set the PreferredSize of this method to the dimensions of pnlWidth and pnlHeight

        this.setSize(pnlWidth, pnlHeight);//set the size of this method to pnlWidth and pnlHeight

        this.setBackground(Color.green);//set the colour of the background to green

        this.isFocusable();//set the focus

        setBackground();//call to the setBackground method

    }//closing bracket for the GameWorld method

 

    public void setBackground() {//method constructor for the setBackground method

        try {//try statement

            image = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("wizardGame.gif"), "wizardGame.gif"));//set the variable image to the file value of wizardGame.gif

 

 

        } catch (Exception e) {//clsoing bracket for the try statement and catch exception e

            System.out.println("can not find image");//system print out to say it can not find the image

        }//closing bracket for the catch statement

    }//closing bracket for the method

 

    @Override//the @overide command

    public void paint(Graphics g) {//method constructor for the method paint which accepts the graphics variable g

        super.paint(g);//paint the variable g to the super class

    }//closing bracket for the method paint

 

    /** This method is called from within the constructor to

     * initialize the form.

     * WARNING: Do NOT modify this code. The content of this method is

     * always regenerated by the Form Editor.

     */

    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed" desc="Generated Code">                         

    private void initComponents() {

 

        addKeyListener(new java.awt.event.KeyAdapter() {

            public void keyPressed(java.awt.event.KeyEvent evt) {

                formKeyPressed(evt);

            }

        });

 

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);

        this.setLayout(layout);

        layout.setHorizontalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGap(0, 400, Short.MAX_VALUE)

        );

        layout.setVerticalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGap(0, 300, Short.MAX_VALUE)

        );

    }// </editor-fold>                        

 

    private void formKeyPressed(java.awt.event.KeyEvent evt) {                               

        int left = 92, right = 47;//declare the integer variable left and right and assign their vaules to 92 and 47 respectively

 

        if (evt.getKeyCode() == left && slider00.getPaddleXLocation() > 0) {//if statement to evaluate if the keyCode equals left and the position of the slider is greater than zero

            slider00.moveLeft();//move the slider left

        }//clsoing bracket for the if statement

        if (evt.getKeyCode() == right && slider00.getPaddleXLocation() < this.getWidth() - slider00.paddle.getWidth(this)) {//if statement to evaluate if the keyCode is equal to right and the slider position is less than the width of the screen

            slider00.moveRight();//move the slider right

        }//closing bracket for the if statement

 

        if (evt.getKeyCode() == 32){

            PanelWorld.world.pnlGameWorld.requestFocusInWindow();

            PanelWorld.world.launch();

        }

 

        if(evt.getKeyCode() == 80){

            PanelWorld.world.pnlGamePaused.requestFocusInWindow();

            PanelWorld.world.changeState(4, 1);

        }

    }                              

 

    // Variables declaration - do not modify                    

    // End of variables declaration                  

    @Override//the @overide command

    protected void paintComponent(Graphics g) {

        super.paintComponent(g);

        if (image != null) {

            g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this);

            g.setColor(Color.orange);

            g.fill3DRect(pnlWidth - 100, pnlHeight - (pnlHeight - 200), 10, pnlHeight, true);

 

            g.drawImage(slider00.paddle, slider00.getPaddleXLocation(), this.getHeight() - slider00.paddle.getHeight(this), this);

 

 

            Graphics2D g2 = (Graphics2D) g;

            collider00 = new Ellipse2D.Double(pnlWidth - 300, pnlHeight - (pnlHeight - 300), 60, 60);

            g2.draw(collider00);

            g2.fill(collider00);

 

            collider01 = new Ellipse2D.Double(pnlWidth - 500, pnlHeight - (pnlHeight - 250), 60, 60);

            g2.draw(collider01);

            g2.fill(collider01);

 

            collider02 = new Ellipse2D.Double(pnlWidth - 600, pnlHeight - (pnlHeight - 100), 60, 60);

            g2.draw(collider02);

            g2.fill(collider02);

 

//            Paddle Paddle = new Paddle();

            //          Paddle.paint(g);

 

           //g.setColor(Color.red);

            //g.drawRect(pnlWidth - 300, pnlHeight - (pnlHeight - 300), 60, 60);

            //g.drawRect(pnlWidth - 500, pnlHeight - (pnlHeight - 250), 60, 60);

            //g.drawRect(pnlWidth - 600, pnlHeight - (pnlHeight - 100), 60, 60);

            //g.drawRect(PanelWorld.aBall.loc.x - PanelWorld.aBall.rad - 3, PanelWorld.aBall.loc.y - 2 * PanelWorld.aBall.rad - 4, 2 * PanelWorld.aBall.rad, 2 * PanelWorld.aBall.rad);

 

            g.drawString(Integer.toString(Ball.score), 20, pnlHeight - 50);

 

            life00 = new Ellipse2D.Double(pnlWidth - 270, pnlHeight - 50, 35, 35);

            life01 = new Ellipse2D.Double(pnlWidth - 235, pnlHeight - 50, 35, 35);

            life02 = new Ellipse2D.Double(pnlWidth - 200, pnlHeight - 50, 35, 35);

            life03 = new Ellipse2D.Double(pnlWidth - 165, pnlHeight - 50, 35, 35);

 

            g.setColor(Color.orange);

 

            g2.draw(life00);

            g2.fill(life00);

            g2.draw(life01);

            g2.fill(life01);

            g2.draw(life02);

            g2.fill(life02);

            g2.draw(life03);

            g2.fill(life03);

 

            if (Ball.lives == 4) {

                g.setColor(Color.red);

                g2.draw(life03);

                g2.fill(life03);

            }

 

            if (Ball.lives == 3) {

                g.setColor(Color.red);

                g2.draw(life03);

                g2.fill(life03);

                g2.draw(life02);

                g2.fill(life02);

            }

 

            if (Ball.lives == 2) {

                g.setColor(Color.red);

                g2.draw(life03);

                g2.fill(life03);

                g2.draw(life02);

                g2.fill(life02);

                g2.draw(life01);

                g2.fill(life01);

            }

 

            if (Ball.lives == 1) {

                g.setColor(Color.red);

                g2.draw(life03);

                g2.fill(life03);

                g2.draw(life02);

                g2.fill(life02);

                g2.draw(life01);

                g2.fill(life01);

                g2.draw(life00);

                g2.fill(life00);

            }

 

            if (Ball.lives == 0) {

                PanelWorld.world.changeState(5, 1);

            }

        }

    }

}

Paddle.java

import java.awt.Image;

import java.awt.Point;

 

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

/**

 *

 * @author 00c0

 */

public class Paddle {

 

    private int paddleXLocation;

    public Image paddle;

 

    public Paddle(int paddleXLocation) {

 

        setPaddleXLocation(paddleXLocation);

        try {

            paddle = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("paddle.jpg"), "paddle.jpg"));

        } catch (Exception e) {

            System.out.println("load failed");

        }

    }

 

    public int getPaddleXLocation() {

        return paddleXLocation;

    }

 

    public void setPaddleXLocation(int paddleXLocation) {

        this.paddleXLocation = paddleXLocation;

    }

 

    public void moveLeft() {

 

        paddleXLocation -= 5;

 

    }

 

    public void moveRight() {

 

        paddleXLocation += 5;

    }

}

PanelEnterHighScores.java

 

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Image;

import java.io.EOFException;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.ObjectInputStream;

import java.io.ObjectOutputStream;

import java.util.Arrays;

import java.util.Collections;

import java.util.Vector;

import javax.swing.JOptionPane;

 

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

/*

 * PanelEnterHighScores.java

 *

 * Created on 24-Mar-2010, 11:34:25

 */

/**

 *

 * @author 00e5

 */

public class PanelEnterHighScores extends javax.swing.JPanel {

 

    PanelSetup pnlSetup;

    private int pnlHeight = 0;

    private int pnlWidth = 0;

    static PanelEnterHighScores pnlEnterHighScore;

    Image image;

    public Vector<VectorRecord> vector = new Vector<VectorRecord>();                   //create a new instance of a vector for the BMIRecord class called vector

    public VectorRecord record;                                                        //create a variable record for the BMIRecord class called record

    File vectorFile = new File(new File(getClass().getResource("dataFiles").getFile()), "SCORESdata.txt");       //create a new instance of the class file and navigate to the resources directory dataFiles

    ObjectInputStream input;                                                    //create a variable for the in put stream called input

    ObjectOutputStream output;                                                  //create a variable for the out put stream called output

    public int[] userHighestScore;

 

    /** Creates new form PanelEnterHighScores */

    public PanelEnterHighScores(boolean vis) {

        initComponents();

        pnlSetup = new PanelSetup();

        pnlHeight = pnlSetup.getHeight();

        pnlWidth = pnlSetup.getWidth();

        this.setVisible(vis);

        this.setBounds(0, 0, pnlWidth, pnlHeight);

        this.setMinimumSize(new Dimension(pnlWidth, pnlHeight));

        this.setPreferredSize(new Dimension(pnlWidth, pnlHeight));

        this.setSize(pnlWidth, pnlHeight);

        this.setBackground(Color.red);

        // setBackground();

 

    }

//    public void setBackground() {

//        try {

//            image = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("instructions.jpg"), "instructions.jpg"));

//

//

//        } catch (Exception e) {

//            System.out.println("can not find image");

//        }

//    }

//

//    @Override

//    public void paint(Graphics g) {

//        super.paint(g);

//    }

 

    /** This method is called from within the constructor to

     * initialize the form.

     * WARNING: Do NOT modify this code. The content of this method is

     * always regenerated by the Form Editor.

     */

    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed" desc="Generated Code">                         

    private void initComponents() {

 

        cmdOk = new javax.swing.JButton();

        lblWizardHat = new javax.swing.JLabel();

        txtGamerName = new javax.swing.JTextField();

 

        cmdOk.setBackground(new java.awt.Color(255, 192, 0));

        cmdOk.setFont(new java.awt.Font("Trebuchet MS", 1, 48)); // NOI18N

        cmdOk.setForeground(new java.awt.Color(160, 191, 216));

        cmdOk.setText("Ok");

        cmdOk.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                cmdOkActionPerformed(evt);

            }

        });

 

        lblWizardHat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Wizard_hat.png"))); // NOI18N

        lblWizardHat.setVerticalAlignment(javax.swing.SwingConstants.TOP);

 

        txtGamerName.setFont(new java.awt.Font("Trebuchet MS", 1, 36));

 

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);

        this.setLayout(layout);

        layout.setHorizontalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(layout.createSequentialGroup()

                .addComponent(lblWizardHat)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                    .addGroup(layout.createSequentialGroup()

                        .addGap(87, 87, 87)

                        .addComponent(txtGamerName, javax.swing.GroupLayout.PREFERRED_SIZE, 306, javax.swing.GroupLayout.PREFERRED_SIZE)

                        .addContainerGap(73, Short.MAX_VALUE))

                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                        .addComponent(cmdOk)

                        .addGap(179, 179, 179))))

        );

        layout.setVerticalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(layout.createSequentialGroup()

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                    .addComponent(lblWizardHat)

                    .addGroup(layout.createSequentialGroup()

                        .addGap(109, 109, 109)

                        .addComponent(txtGamerName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                        .addGap(87, 87, 87)

                        .addComponent(cmdOk)))

                .addContainerGap(98, Short.MAX_VALUE))

        );

    }// </editor-fold>                       

 

    private void cmdOkActionPerformed(java.awt.event.ActionEvent evt) {                                     

        openData();

        validateUserName();

 

 

    }                                    

    // Variables declaration - do not modify                    

    private javax.swing.JButton cmdOk;

    private javax.swing.JLabel lblWizardHat;

    private javax.swing.JTextField txtGamerName;

    // End of variables declaration                  

//      @Override

//    protected void paintComponent(Graphics g) {

//        super.paintComponent(g);

//        if (image != null) {

//            g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this);

//

//        }

//    }

 

    public void saveFile() {                                                   //declaration of the method createFile

 

        try {                                                            //try statement with the opening bracket

            output = new ObjectOutputStream(new FileOutputStream(vectorFile));        //assign the value of file to the file output stream as part of a new instance of the input output stream which is the value of a variable output

            int count = 0;                                                      //create a local integer variable called count and set it to zero

            if (vectorFile.exists()) {                                                //if statement to check that the file exists, with the opening bracket of the if statement

                if (vectorFile.isFile()) {                                            //if statement to check that the file is actually a file, with the opening bracket of the if statement

                    while (count < vector.size()) {                             //while loop, while the variable count is less than the size of the vector vector and the opening bracket to the while statement

                        record = vector.get(count);

                        System.out.println(record.getScore());

                        //assign the value of vector for a specific index value, count, to the variable record

                        output.writeObject(record);                             //using the variable output write the contents of record to file

                        count++;                                                //increament the variable count by plus one

                    }                                                           //closing brackets for the while statement

                }                                                               //closing bracket for the if statement

            }                                                                   //closing bracket for the if statement

        } catch (IOException e) {                                               //closing bracket for the try statement, a catch of input output exception and the opening bracket for the catch statement

        }                                                                       //closing bracket for the catch statement

    }

 

    public void openData() {                                                    //declaration of the method openData

 

        try {                                                                   //try statement with the opening bracket

            vector.clear();                                                     //clear the vector called vector

            input = new ObjectInputStream(new FileInputStream(vectorFile));           //assign the value of file to the file input stream as part of a new instance of the output input stream

            while (true) {                                                      //until the end of file as a while loop with the opening bracket

                record = (VectorRecord) input.readObject();                     //read the value of a record into the variable record from the file

                vector.add(record);

                System.out.println(record.getScore() + " read in");//add the vaule of record to the vector called vector

            }                                                                   //closing bracket for the while loop

        } catch (EOFException e) {                                              //closing bracket of the try statement the an end of file exception catch statement with the opening bracket of the cath statement

        } catch (IOException i) {                                               //closing bracket of the catch statement, a catch statement of input output exception with the opening bracket of the catch statement

        } catch (ClassNotFoundException e) {                                    //closing bracket of the catch statement, a catch statement of class not found exception with the opening bracket of the catch statement

        }                                                                       //closing bracket of the catch statement

 

    }

 

    public void populateHighScores() {

        int scoreCounter = 0;

        if (vector.size() < 5) {

            scoreCounter = vector.size();

        } else {

            scoreCounter = 5;

        }

        for (int a = 0; a < scoreCounter; a++) {                               //for loop based on the size of the vector

            record = vector.get(a);                                             //set the value of record to the value of vector at position i

            PanelWorld.world.pnlHighScores.txtAreaHighScores.append(record.getgamerName() + "\t" + Integer.toString(record.getScore()) + "\n");

        }

    }

 

    public void validateUserName() {

        try {

            int row = 0;

            String chkGamerName = txtGamerName.getText();

            char[] gamerNameChar = new char[chkGamerName.length()];                    //create a character array called FirstNameChar and define its length to the variable size of FirstName

 

            for (row = 0; row <= (chkGamerName.length() - 1); row++) {                       //for statement, row equal zero, if row less than or equal to the length of FirstName minus one, increament row by plus one, with the opening bracket for the for loop

                gamerNameChar[row] = chkGamerName.charAt(row);                             //set the value of the character array gamerNameChar at the value of row to FirstName character at position row

            }                                                                       //closing bracket foir the for loop

            if (Character.isLetter(gamerNameChar[0])) //if statement, if the character at position zero of gamerNameChar is a letter)                             //or the character at position zeroof SurnameChar is a letter

            {                                                                       //closing bracket for the if statement

                record = new VectorRecord( //create record as an instance of the class VectorRecord

                        txtGamerName.getText(), //get the value of the variable txtTodaysDate and add it to record

                        Ball.score);

                vector.add(record);                                                     //add the variable record to the vector vector

 

                VectorSort.sort();//call the class and method VectorSort.sort

                saveFile();                                                                 //calling the method Save

 

                VectorSort.sort();

 

                int scoreCounter = 0;

                if (vector.size() < 5) {

                    scoreCounter = vector.size();

                } else {

                    scoreCounter = 5;

                }

                for (int a = 0; a < scoreCounter; a++) {                               //for loop based on the size of the vector

                    record = vector.get(a);                                             //set the value of record to the value of vector at position i

                    PanelWorld.world.pnlHighScores.txtAreaHighScores.append(record.getgamerName() + "\t" + Integer.toString(record.getScore()) + "\n");

                }

                int i = 0;

                userHighestScore = new int[vector.size()];

                for (int a = 0; a < vector.size(); a++) {                               //for loop based on the size of the vector

                    record = vector.get(a);

                    if (record.getgamerName().equalsIgnoreCase(txtGamerName.getText())) {

                        userHighestScore[i] = record.getScore();

                        i++;

                    }

                }

                Arrays.sort(userHighestScore);

                PanelWorld.world.pnlHighScores.txtUserHighestScore.setText(Integer.toString(userHighestScore[userHighestScore.length - 1]));

 

                PanelWorld.world.changeState(3, 6);

 

            } else {                                                                //closing bracket for the if statement, an else statement and the opening bracket for the else statement

                txtGamerName.setText("");

                JOptionPane.showMessageDialog( //show message dialog box

                        this, //using this, the dialog box

                        "You have not entered a valid start " + //set the message text of the dialog box

                        "character for the Gamer Name", //set the message text of the dialog box

                        "Invalid Name Entry", //set the title of the dialog box

                        JOptionPane.ERROR_MESSAGE);                             //use the JOptionPane error message modal

                PanelWorld.world.changeState(6, 6);

                txtGamerName.requestFocus(true);                                        //set the focus to txtFirstName text box

                txtGamerName.setFocusable(true);      //set the focus to txtFirstName text box

            }

        } catch (ArrayIndexOutOfBoundsException e) {

            txtGamerName.setText("");

            JOptionPane.showMessageDialog( //show message dialog box

                    this, //using this, the dialog box

                    "You have not entered a valid start " + //set the message text of the dialog box

                    "character for the Gamer Name", //set the message text of the dialog box

                    "Invalid Name Entry", //set the title of the dialog box

                    JOptionPane.ERROR_MESSAGE);                             //use the JOptionPane error message modal

            PanelWorld.world.changeState(6, 6);

            txtGamerName.requestFocus(true);                                        //set the focus to txtGamerName text box

            txtGamerName.setFocusable(true);      //set the focus to txtGamerName text box

        }

    }

}

PanelGameOver.java

 

import java.awt.*;

 

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

/*

 * PanelGameOver.java

 *

 * Created on 18-Mar-2010, 14:36:56

 */

/**

 *

 * @author 00e5

 */

public class PanelGameOver extends javax.swing.JPanel {

 

    PanelSetup pnlSetup;

    private int pnlHeight = 0;

    private int pnlWidth = 0;

    PanelWorld world;

    Image image;

  

 

    /** Creates new form PanelGameOver */

    public PanelGameOver(boolean vis) {

        initComponents();

        pnlSetup = new PanelSetup();

        pnlHeight = pnlSetup.getHeight();

        pnlWidth = pnlSetup.getWidth();

        this.setVisible(vis);

        this.setBounds(0, 0, pnlWidth, pnlHeight);

        this.setMinimumSize(new Dimension(pnlWidth, pnlHeight));

        this.setPreferredSize(new Dimension(pnlWidth, pnlHeight));

        this.setSize(pnlWidth, pnlHeight);

        this.setBackground(Color.white);

        //setBackground();

      

 

    }

   

 

//    public void setBackground() {

//        try {

//            image = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("instructions.jpg"), "instructions.jpg"));

//

//

//        } catch (Exception e) {

//            System.out.println("can not find image");

//        }

//    }

//

//    @Override

//    public void paint(Graphics g) {

//        super.paint(g);

//    }

 

    /** This method is called from within the constructor to

     * initialize the form.

     * WARNING: Do NOT modify this code. The content of this method is

     * always regenerated by the Form Editor.

     */

    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed" desc="Generated Code">                         

    private void initComponents() {

 

        lblWizardHat = new javax.swing.JLabel();

        lblGameOver = new javax.swing.JLabel();

        lblScore = new javax.swing.JLabel();

        lblScoreValue = new javax.swing.JLabel();

        cmdEnterHighScore = new javax.swing.JButton();

        cmdGameOverQuit = new javax.swing.JButton();

 

        lblWizardHat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Wizard_hat.png"))); // NOI18N

 

        lblGameOver.setFont(new java.awt.Font("Trebuchet MS", 1, 36));

        lblGameOver.setText("Game Over");

 

        lblScore.setFont(new java.awt.Font("Trebuchet MS", 1, 48));

        lblScore.setText("Score:");

 

        lblScoreValue.setFont(new java.awt.Font("Trebuchet MS", 1, 48));

        lblScoreValue.setText("Score Value");

 

        cmdEnterHighScore.setBackground(new java.awt.Color(255, 192, 0));

        cmdEnterHighScore.setFont(new java.awt.Font("Trebuchet MS", 1, 48)); // NOI18N

        cmdEnterHighScore.setForeground(new java.awt.Color(160, 191, 216));

        cmdEnterHighScore.setText("Enter High Score");

        cmdEnterHighScore.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                cmdEnterHighScoreActionPerformed(evt);

            }

        });

 

        cmdGameOverQuit.setBackground(new java.awt.Color(255, 192, 0));

        cmdGameOverQuit.setFont(new java.awt.Font("Trebuchet MS", 1, 48)); // NOI18N

        cmdGameOverQuit.setForeground(new java.awt.Color(160, 191, 216));

        cmdGameOverQuit.setText("Quit");

        cmdGameOverQuit.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                cmdGameOverQuitActionPerformed(evt);

            }

        });

 

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);

        this.setLayout(layout);

        layout.setHorizontalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(layout.createSequentialGroup()

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                    .addGroup(layout.createSequentialGroup()

                        .addGap(226, 226, 226)

                        .addComponent(lblGameOver))

                    .addGroup(layout.createSequentialGroup()

                        .addGap(169, 169, 169)

                        .addComponent(lblScore)

                        .addGap(18, 18, 18)

                        .addComponent(lblScoreValue, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE))

                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

                        .addContainerGap()

                        .addComponent(lblWizardHat)

                        .addGap(209, 209, 209)))

                .addContainerGap())

            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

                .addContainerGap(178, Short.MAX_VALUE)

                .addComponent(cmdEnterHighScore)

                .addGap(75, 75, 75))

            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

                .addContainerGap(324, Short.MAX_VALUE)

                .addComponent(cmdGameOverQuit)

                .addGap(211, 211, 211))

        );

        layout.setVerticalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(layout.createSequentialGroup()

                .addContainerGap()

                .addComponent(lblWizardHat)

                .addGap(18, 18, 18)

                .addComponent(lblGameOver)

                .addGap(48, 48, 48)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                    .addComponent(lblScore)

                    .addComponent(lblScoreValue, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

                .addGap(50, 50, 50)

                .addComponent(cmdEnterHighScore)

                .addGap(57, 57, 57)

                .addComponent(cmdGameOverQuit)

                .addGap(31, 31, 31))

        );

    }// </editor-fold>                       

 

    private void cmdEnterHighScoreActionPerformed(java.awt.event.ActionEvent evt) {                                                  

 

        PanelWorld.world.changeState(6, 5);//utilising the world interface change the panel to the highscores screen and hide the game over screen

 

    }                                                

 

    private void cmdGameOverQuitActionPerformed(java.awt.event.ActionEvent evt) {                                               

 

        System.exit(0);//quits the game

 

    }                                              

 

    // Variables declaration - do not modify                    

    private javax.swing.JButton cmdEnterHighScore;

    private javax.swing.JButton cmdGameOverQuit;

    private javax.swing.JLabel lblGameOver;

    private javax.swing.JLabel lblScore;

    private javax.swing.JLabel lblScoreValue;

    private javax.swing.JLabel lblWizardHat;

    // End of variables declaration                  

 

    @Override

    protected void paintComponent(Graphics g) {

        super.paintComponent(g);

        if (image != null) {

            g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this);

        }

         setScore();

    }

 

    public void setScore(){

        lblScoreValue.setText(Integer.toString(Ball.score));

    }

 

}

PanelGamePaused.java

 

import java.awt.*;

 

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

/*

 * PanelGamePaused.java

 *

 * Created on 18-Mar-2010, 14:34:20

 */

/**

 *

 * @author 00e5

 */

public class PanelGamePaused extends javax.swing.JPanel {

 

    PanelSetup pnlSetup;

    private int pnlHeight = 0;

    private int pnlWidth = 0;

    PanelWorld world;

    Image image;

 

    /** Creates new form PanelGamePaused */

    public PanelGamePaused(boolean vis) {

        initComponents();

        pnlSetup = new PanelSetup();

        pnlHeight = pnlSetup.getHeight();

        pnlWidth = pnlSetup.getWidth();

        this.setVisible(vis);

        this.setBounds(0, 0, pnlWidth, pnlHeight);

        this.setMinimumSize(new Dimension(pnlWidth, pnlHeight));

        this.setPreferredSize(new Dimension(pnlWidth, pnlHeight));

        this.setSize(pnlWidth, pnlHeight);

        this.setBackground(Color.yellow);

        this.isFocusable();//set the focus

        setBackground();

    }

 

  public void setBackground() {

        try {

            image = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("wizardGame.gif"), "wizardGame.gif"));

 

 

        } catch (Exception e) {

            System.out.println("can not find image");

        }

    }

 

    @Override

    public void paint(Graphics g) {

        super.paint(g);

    }

 

    /** This method is called from within the constructor to

     * initialize the form.

     * WARNING: Do NOT modify this code. The content of this method is

     * always regenerated by the Form Editor.

     */

    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed" desc="Generated Code">                         

    private void initComponents() {

 

        lblPaused = new javax.swing.JLabel();

        lblResume = new javax.swing.JLabel();

 

        addKeyListener(new java.awt.event.KeyAdapter() {

            public void keyPressed(java.awt.event.KeyEvent evt) {

                formKeyPressed(evt);

            }

        });

 

        lblPaused.setFont(new java.awt.Font("Trebuchet MS", 1, 48)); // NOI18N

        lblPaused.setText("The game is Paused");

 

        lblResume.setFont(new java.awt.Font("Trebuchet MS", 1, 48)); // NOI18N

        lblResume.setText("press R to resume");

 

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);

        this.setLayout(layout);

        layout.setHorizontalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(layout.createSequentialGroup()

                .addGap(138, 138, 138)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                    .addComponent(lblResume)

                    .addComponent(lblPaused))

                .addContainerGap(106, Short.MAX_VALUE))

        );

        layout.setVerticalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(layout.createSequentialGroup()

                .addGap(36, 36, 36)

                .addComponent(lblPaused)

                .addGap(18, 18, 18)

                .addComponent(lblResume)

                .addContainerGap(132, Short.MAX_VALUE))

        );

    }// </editor-fold>                        

 

    private void formKeyPressed(java.awt.event.KeyEvent evt) {                               

if (evt.getKeyCode() ==82){

    System.out.println(evt.getKeyCode());

    PanelWorld.world.pnlGameWorld.requestFocusInWindow();

    PanelWorld.world.changeState(1, 4);

}

    }                              

 

    // Variables declaration - do not modify                    

    private javax.swing.JLabel lblPaused;

    private javax.swing.JLabel lblResume;

    // End of variables declaration                  

   

    @Override

    protected void paintComponent(Graphics g) {

        super.paintComponent(g);

        if (image != null) {

            g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this);

 

        }

    }

 

}

PanelHighScores.java

 

import java.awt.*;

import java.io.EOFException;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.ObjectInputStream;

import java.io.ObjectOutputStream;

import java.util.Collections;

import java.util.Vector;

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

/*

 * PanelHighScores.java

 *

 * Created on 18-Mar-2010, 14:30:44

 */

 

/**

 *

 * @author 00e5

 */

public class PanelHighScores extends javax.swing.JPanel {

 

    PanelSetup pnlSetup;

    private int pnlHeight = 0;

    private int pnlWidth = 0;

    PanelWorld world;

    Image image;

    public Vector<VectorRecord> vector = new Vector<VectorRecord>();                   //create a new instance of a vector for the BMIRecord class called vector

    public VectorRecord record;                                                        //create a variable record for the BMIRecord class called record

    File vectorFile = new File(new File(getClass().getResource("dataFiles").getFile()), "SCORESdata.txt");       //create a new instance of the class file and navigate to the resources directory dataFiles

    ObjectInputStream input;                                                    //create a variable for the in put stream called input

    ObjectOutputStream output;                                                  //create a variable for the out put stream called output

 

 

    /** Creates new form PanelHighScores */

    public PanelHighScores(boolean vis) {

        initComponents();

        pnlSetup = new PanelSetup();

        pnlHeight = pnlSetup.getHeight();

        pnlWidth = pnlSetup.getWidth();

        this.setVisible(vis);

        this.setBounds(0, 0, pnlWidth, pnlHeight);

        this.setMinimumSize(new Dimension(pnlWidth, pnlHeight));

        this.setPreferredSize(new Dimension(pnlWidth, pnlHeight));

        this.setSize(pnlWidth, pnlHeight);

        this.setBackground(Color.yellow);

        //setBackground();

 

       //setHighScores();

 

    }

//    public void setBackground() {

//        try {

//            image = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("instructions.jpg"), "instructions.jpg"));

//

//

//        } catch (Exception e) {

//            System.out.println("can not find image");

//        }

//    }

//

//    @Override

//    public void paint(Graphics g) {

//        super.paint(g);

//    }

 

 

    /** This method is called from within the constructor to

     * initialize the form.

     * WARNING: Do NOT modify this code. The content of this method is

     * always regenerated by the Form Editor.

     */

    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed" desc="Generated Code">                         

    private void initComponents() {

 

        lblWizardHat = new javax.swing.JLabel();

        jScrollPane1 = new javax.swing.JScrollPane();

        txtAreaHighScores = new javax.swing.JTextArea();

        txtUserHighestScore = new javax.swing.JTextField();

        lblUserHighestScore = new javax.swing.JLabel();

        cmdHighScoresStartGame = new javax.swing.JButton();

 

        setPreferredSize(new java.awt.Dimension(800, 600));

 

        lblWizardHat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Wizard_hat.png"))); // NOI18N

        lblWizardHat.setVerticalAlignment(javax.swing.SwingConstants.TOP);

        lblWizardHat.setPreferredSize(new java.awt.Dimension(150, 200));

 

        txtAreaHighScores.setColumns(20);

        txtAreaHighScores.setEditable(false);

        txtAreaHighScores.setFont(new java.awt.Font("Trebuchet MS", 1, 28)); // NOI18N

        txtAreaHighScores.setRows(5);

        jScrollPane1.setViewportView(txtAreaHighScores);

 

        txtUserHighestScore.setEditable(false);

        txtUserHighestScore.setFont(new java.awt.Font("Trebuchet MS", 1, 36));

 

        lblUserHighestScore.setFont(new java.awt.Font("Trebuchet MS", 1, 36));

        lblUserHighestScore.setText("Users Highest Score");

 

        cmdHighScoresStartGame.setBackground(new java.awt.Color(255, 192, 0));

        cmdHighScoresStartGame.setFont(new java.awt.Font("Trebuchet MS", 1, 48)); // NOI18N

        cmdHighScoresStartGame.setForeground(new java.awt.Color(160, 191, 216));

        cmdHighScoresStartGame.setText("Play Game");

        cmdHighScoresStartGame.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                cmdHighScoresStartGameActionPerformed(evt);

            }

        });

 

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);

        this.setLayout(layout);

        layout.setHorizontalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(layout.createSequentialGroup()

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                    .addGroup(layout.createSequentialGroup()

                        .addComponent(lblWizardHat, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)

                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                            .addGroup(layout.createSequentialGroup()

                                .addGap(133, 133, 133)

                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)

                                    .addComponent(txtUserHighestScore)

                                    .addComponent(lblUserHighestScore, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))

                            .addGroup(layout.createSequentialGroup()

                                .addGap(162, 162, 162)

                                .addComponent(cmdHighScoresStartGame))))

                    .addGroup(layout.createSequentialGroup()

                        .addGap(22, 22, 22)

                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 768, Short.MAX_VALUE)))

                .addContainerGap())

        );

        layout.setVerticalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(layout.createSequentialGroup()

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                    .addComponent(lblWizardHat, javax.swing.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE)

                    .addGroup(layout.createSequentialGroup()

                        .addGap(35, 35, 35)

                        .addComponent(cmdHighScoresStartGame)

                        .addGap(18, 18, 18)

                        .addComponent(lblUserHighestScore)

                        .addGap(18, 18, 18)

                        .addComponent(txtUserHighestScore, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)))

                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE)

                .addContainerGap())

        );

    }// </editor-fold>                       

 

    private void cmdHighScoresStartGameActionPerformed(java.awt.event.ActionEvent evt) {                                                      

        Ball.lives = 5;

        Ball.score = 0;

        PanelWorld.world.changeState(2, 3);//calls Panel World changeState method utilising the world interface to display the play game screen

        PanelWorld.world.pnlGameWorld.requestFocusInWindow();//using the Panel World world interface set the focus in the window to pnlGameWorld

}                                                     

 

 

    // Variables declaration - do not modify                     

    private javax.swing.JButton cmdHighScoresStartGame;

    private javax.swing.JScrollPane jScrollPane1;

    private javax.swing.JLabel lblUserHighestScore;

    private javax.swing.JLabel lblWizardHat;

    public javax.swing.JTextArea txtAreaHighScores;

    public javax.swing.JTextField txtUserHighestScore;

    // End of variables declaration                  

//      @Override

//    protected void paintComponent(Graphics g) {

//        super.paintComponent(g);

//        if (image != null) {

//            g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this);

//

//        }

//    }

     public void saveFile() {                                                   //declaration of the method createFile

 

        try {                                                            //try statement with the opening bracket

            output = new ObjectOutputStream(new FileOutputStream(vectorFile));        //assign the value of file to the file output stream as part of a new instance of the input output stream which is the value of a variable output

            int count = 0;                                                      //create a local integer variable called count and set it to zero

            if (vectorFile.exists()) {                                                //if statement to check that the file exists, with the opening bracket of the if statement

                if (vectorFile.isFile()) {                                            //if statement to check that the file is actually a file, with the opening bracket of the if statement

                    while (count < vector.size()) {                             //while loop, while the variable count is less than the size of the vector vector and the opening bracket to the while statement

                        record = vector.get(count);

                        System.out.println(record.getScore());

                                //assign the value of vector for a specific index value, count, to the variable record

                        output.writeObject(record);                             //using the variable output write the contents of record to file

                        count++;                                                //increament the variable count by plus one

                    }                                                           //closing brackets for the while statement

                }                                                               //closing bracket for the if statement

            }                                                                   //closing bracket for the if statement

        } catch (IOException e) {                                               //closing bracket for the try statement, a catch of input output exception and the opening bracket for the catch statement

        }                                                                       //closing bracket for the catch statement

    }

 

    public void openData() {                                                    //declaration of the method openData

 

        try {                                                                   //try statement with the opening bracket

            vector.clear();                                                     //clear the vector called vector

            input = new ObjectInputStream(new FileInputStream(vectorFile));           //assign the value of file to the file input stream as part of a new instance of the output input stream

            while (true) {                                                      //until the end of file as a while loop with the opening bracket

                record = (VectorRecord) input.readObject();                     //read the value of a record into the variable record from the file

                vector.add(record);

                 System.out.println(record.getScore() + " read in");//add the vaule of record to the vector called vector

            }                                                                   //closing bracket for the while loop

        } catch (EOFException e) {                                              //closing bracket of the try statement the an end of file exception catch statement with the opening bracket of the cath statement

        } catch (IOException i) {                                               //closing bracket of the catch statement, a catch statement of input output exception with the opening bracket of the catch statement

        } catch (ClassNotFoundException e) {                                    //closing bracket of the catch statement, a catch statement of class not found exception with the opening bracket of the catch statement

        }                                                                       //closing bracket of the catch statement

 

    }

 

    public void setHighScores(){

        PanelEnterHighScores.pnlEnterHighScore.openData();

       

        System.out.println("open Data");

        Collections.sort(vector, new VectorRecord.score());

        System.out.println("sort Data");

        for (int a = 0; a < PanelEnterHighScores.pnlEnterHighScore.vector.size(); a++) {                               //for loop based on the size of the vector

            record = PanelEnterHighScores.pnlEnterHighScore.vector.get(a);                                             //set the value of record to the value of vector at position i

            txtAreaHighScores.append(PanelEnterHighScores.pnlEnterHighScore.record.getgamerName() + "\t" + Integer.toString(PanelEnterHighScores.pnlEnterHighScore.record.getScore()) + "\n");

        }

    }

}

PanelInstructions.java

 

import java.awt.*;

import java.awt.geom.Ellipse2D;

 

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

/*

 * PanelInstructions.java

 *

 * Created on 17-Mar-2010, 19:13:13

 */

/**

 *

 * @author 00e5

 */

public class PanelInstructions extends javax.swing.JPanel {

 

    PanelSetup pnlSetup;

    private int pnlHeight = 0;

    private int pnlWidth = 0;

    PanelWorld world;

    Image image;

 

    /** Creates new form PanelInstructions */

    public PanelInstructions(boolean vis) {

        initComponents();

 

        pnlSetup = new PanelSetup();

        pnlHeight = pnlSetup.getHeight();

        pnlWidth = pnlSetup.getWidth();

        this.setVisible(vis);

        this.setBounds(0, 0, pnlWidth, pnlHeight);

        this.setMinimumSize(new Dimension(pnlWidth, pnlHeight));

        this.setPreferredSize(new Dimension(pnlWidth, pnlHeight));

        this.setSize(pnlWidth, pnlHeight);

        this.setBackground(Color.yellow);

        setBackground();

 

    }

 

    public void setBackground() {

        try {

            image = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("instructions.jpg"), "instructions.jpg"));

 

 

        } catch (Exception e) {

            System.out.println("can not find image");

        }

    }

 

    @Override

    public void paint(Graphics g) {

        super.paint(g);

    }

 

    /** This method is called from within the constructor to

     * initialize the form.

     * WARNING: Do NOT modify this code. The content of this method is

     * always regenerated by the Form Editor.

     */

    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed" desc="Generated Code">                         

    private void initComponents() {

 

        lblGameInstructions = new javax.swing.JLabel();

        lblFireBall = new javax.swing.JLabel();

        lblMoveLeft = new javax.swing.JLabel();

        lblMoveRight = new javax.swing.JLabel();

        lblPause = new javax.swing.JLabel();

        lblQuit = new javax.swing.JLabel();

        lblRightControl = new javax.swing.JLabel();

        lblLeftControl = new javax.swing.JLabel();

        lblSpaceBar = new javax.swing.JLabel();

        lblP = new javax.swing.JLabel();

        lblQ = new javax.swing.JLabel();

        cmdInstructionsHighScores = new javax.swing.JButton();

        cmdInstructionsStartGame = new javax.swing.JButton();

        cmdInstructionsQuit = new javax.swing.JButton();

 

        lblGameInstructions.setFont(new java.awt.Font("Trebuchet MS", 1, 48)); // NOI18N

        lblGameInstructions.setForeground(new java.awt.Color(0, 112, 192));

        lblGameInstructions.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        lblGameInstructions.setText("Game Instructions");

 

        lblFireBall.setFont(new java.awt.Font("Trebuchet MS", 1, 48)); // NOI18N

        lblFireBall.setForeground(new java.awt.Color(0, 112, 192));

        lblFireBall.setText("Fire Ball");

 

        lblMoveLeft.setFont(new java.awt.Font("Trebuchet MS", 1, 48)); // NOI18N

        lblMoveLeft.setForeground(new java.awt.Color(0, 112, 192));

        lblMoveLeft.setText("Move Left");

 

        lblMoveRight.setFont(new java.awt.Font("Trebuchet MS", 1, 48)); // NOI18N

        lblMoveRight.setForeground(new java.awt.Color(0, 112, 192));

        lblMoveRight.setText("Move Right");

 

        lblPause.setFont(new java.awt.Font("Trebuchet MS", 1, 48)); // NOI18N

        lblPause.setForeground(new java.awt.Color(0, 112, 192));

        lblPause.setText("Pause");

 

        lblQuit.setFont(new java.awt.Font("Trebuchet MS", 1, 48)); // NOI18N

        lblQuit.setForeground(new java.awt.Color(0, 112, 192));

        lblQuit.setText("Quit");

 

        lblRightControl.setFont(new java.awt.Font("Trebuchet MS", 1, 48)); // NOI18N

        lblRightControl.setForeground(new java.awt.Color(255, 0, 0));

        lblRightControl.setText("/");

 

        lblLeftControl.setFont(new java.awt.Font("Trebuchet MS", 1, 48)); // NOI18N

        lblLeftControl.setForeground(new java.awt.Color(255, 0, 0));

        lblLeftControl.setText("\\");

 

            lblSpaceBar.setFont(new java.awt.Font("Trebuchet MS", 1, 48)); // NOI18N

            lblSpaceBar.setForeground(new java.awt.Color(255, 0, 0));

            lblSpaceBar.setText("Space Bar");

 

            lblP.setFont(new java.awt.Font("Trebuchet MS", 1, 48)); // NOI18N

            lblP.setForeground(new java.awt.Color(255, 0, 0));

            lblP.setText("P");

 

            lblQ.setFont(new java.awt.Font("Trebuchet MS", 1, 48)); // NOI18N

            lblQ.setForeground(new java.awt.Color(255, 0, 0));

            lblQ.setText("Q");

 

            cmdInstructionsHighScores.setBackground(new java.awt.Color(255, 192, 0));

            cmdInstructionsHighScores.setFont(new java.awt.Font("Trebuchet MS", 1, 36)); // NOI18N

            cmdInstructionsHighScores.setForeground(new java.awt.Color(160, 191, 216));

            cmdInstructionsHighScores.setText("High Scores");

            cmdInstructionsHighScores.addActionListener(new java.awt.event.ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent evt) {

                    cmdInstructionsHighScoresActionPerformed(evt);

                }

            });

 

            cmdInstructionsStartGame.setBackground(new java.awt.Color(255, 192, 0));

            cmdInstructionsStartGame.setFont(new java.awt.Font("Trebuchet MS", 1, 48));

            cmdInstructionsStartGame.setForeground(new java.awt.Color(160, 191, 216));

            cmdInstructionsStartGame.setText("Start");

            cmdInstructionsStartGame.addActionListener(new java.awt.event.ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent evt) {

                    cmdInstructionsStartGameActionPerformed(evt);

                }

            });

 

            cmdInstructionsQuit.setBackground(new java.awt.Color(255, 192, 0));

            cmdInstructionsQuit.setFont(new java.awt.Font("Trebuchet MS", 1, 36));

            cmdInstructionsQuit.setForeground(new java.awt.Color(161, 191, 216));

            cmdInstructionsQuit.setText("Quit");

            cmdInstructionsQuit.addActionListener(new java.awt.event.ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent evt) {

                    cmdInstructionsQuitActionPerformed(evt);

                }

            });

 

            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);

            this.setLayout(layout);

            layout.setHorizontalGroup(

                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                .addGroup(layout.createSequentialGroup()

                    .addContainerGap()

                    .addComponent(lblGameInstructions, javax.swing.GroupLayout.DEFAULT_SIZE, 1007, Short.MAX_VALUE)

                    .addContainerGap())

                .addGroup(layout.createSequentialGroup()

                    .addGap(31, 31, 31)

                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                        .addComponent(lblFireBall)

                        .addComponent(lblPause)

                        .addComponent(lblMoveRight)

                        .addComponent(lblMoveLeft)

                        .addComponent(lblQuit))

                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 520, Short.MAX_VALUE)

                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                        .addComponent(lblSpaceBar)

                        .addComponent(lblQ)

                        .addGroup(layout.createSequentialGroup()

                            .addGap(6, 6, 6)

                            .addComponent(lblP))

                        .addGroup(layout.createSequentialGroup()

                            .addGap(15, 15, 15)

                            .addComponent(lblRightControl))

                        .addGroup(layout.createSequentialGroup()

                            .addGap(17, 17, 17)

                            .addComponent(lblLeftControl)))

                    .addGap(10, 10, 10))

                .addGroup(layout.createSequentialGroup()

                    .addContainerGap()

                    .addComponent(cmdInstructionsHighScores)

                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 314, Short.MAX_VALUE)

                    .addComponent(cmdInstructionsStartGame)

                    .addGap(214, 214, 214)

                    .addComponent(cmdInstructionsQuit)

                    .addGap(8, 8, 8))

            );

            layout.setVerticalGroup(

                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                .addGroup(layout.createSequentialGroup()

                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                        .addGroup(layout.createSequentialGroup()

                            .addContainerGap()

                            .addComponent(lblGameInstructions)

                            .addGap(18, 18, 18)

                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                                .addComponent(lblFireBall)

                                .addComponent(lblSpaceBar))

                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                                .addGroup(layout.createSequentialGroup()

                                    .addGap(93, 93, 93)

                                    .addComponent(lblMoveRight)

                                    .addGap(93, 93, 93)

                                    .addComponent(lblQuit))

                                .addGroup(layout.createSequentialGroup()

                                    .addGap(18, 18, 18)

                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                                        .addGroup(layout.createSequentialGroup()

                                            .addGap(75, 75, 75)

                                            .addComponent(lblRightControl))

                                        .addGroup(layout.createSequentialGroup()

                                            .addComponent(lblLeftControl)

                                            .addGap(93, 93, 93)

                                            .addComponent(lblP)))

                                    .addGap(18, 18, 18)

                                    .addComponent(lblQ))))

                        .addGroup(layout.createSequentialGroup()

                            .addGap(161, 161, 161)

                            .addComponent(lblMoveLeft)

                            .addGap(93, 93, 93)

                            .addComponent(lblPause)))

                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 56, Short.MAX_VALUE)

                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                        .addComponent(cmdInstructionsHighScores)

                        .addComponent(cmdInstructionsQuit)

                        .addComponent(cmdInstructionsStartGame))

                    .addGap(52, 52, 52))

            );

        }// </editor-fold>                       

 

    private void cmdInstructionsHighScoresActionPerformed(java.awt.event.ActionEvent evt) {                                                          

        PanelWorld.world.pnlEnterHighScores.openData();//using the world interface call the method openData from pnlEnterHighScores

        PanelWorld.world.pnlEnterHighScores.populateHighScores();//using the world interface call the method populateHighScores from pnlEnterHighScores

        PanelWorld.world.changeState(3, 2);//calls Panel World changeState method utilising the world interface to display the high scores screen

        PanelWorld.world.pnlHighScores.requestFocusInWindow();//using the Panel World world interface set the focus in the window to pnlHighScores

    }                                                        

 

    private void cmdInstructionsStartGameActionPerformed(java.awt.event.ActionEvent evt) {                                                        

        Ball.lives = 5;//set the value of the variable lives to five

        Ball.score = 0;//set the value of the variable score to zero

        PanelWorld.world.changeState(1, 2);//calls Panel World changeState method utilising the world interface to display the play game screen

        PanelWorld.world.pnlGameWorld.requestFocusInWindow();//using the Panel World world interface set the focus in the window to pnlGameWorld

    }                                                       

 

    private void cmdInstructionsQuitActionPerformed(java.awt.event.ActionEvent evt) {                                                   

 

        System.exit(0);//exit the system

    }                                                  

    // Variables declaration - do not modify                    

    private javax.swing.JButton cmdInstructionsHighScores;

    private javax.swing.JButton cmdInstructionsQuit;

    private javax.swing.JButton cmdInstructionsStartGame;

    private javax.swing.JLabel lblFireBall;

    private javax.swing.JLabel lblGameInstructions;

    private javax.swing.JLabel lblLeftControl;

    private javax.swing.JLabel lblMoveLeft;

    private javax.swing.JLabel lblMoveRight;

    private javax.swing.JLabel lblP;

    private javax.swing.JLabel lblPause;

    private javax.swing.JLabel lblQ;

    private javax.swing.JLabel lblQuit;

    private javax.swing.JLabel lblRightControl;

    private javax.swing.JLabel lblSpaceBar;

    // End of variables declaration                  

 

    @Override

    protected void paintComponent(Graphics g) {

        super.paintComponent(g);

        if (image != null) {

            g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this);

 

        }

    }

}

PanelSetup.java

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

/**

 *

 * @author 00e5

 */

public class PanelSetup {

 

    private int height = 600;

    private int width = 800;

 

    public int getHeight(){

        return height;

    }

 

    public int getWidth(){

        return width;

    }

 

}

PanelWelcomeWorld.java

 

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Graphics;

import java.awt.Image;

import java.io.File;

 

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

/*

 * WelcomeWorld.java

 *

 * Created on 10-Feb-2010, 18:06:28

 */

/**

 *

 * @author 00e5

 */

public class PanelWelcomeWorld extends javax.swing.JPanel {

 

    PanelSetup pnlSetup;

    PanelWorld pnlWorld;

    Image image;

    int pnlHeight = 0;

    int pnlWidth = 0;

    public File backgroundLoad = new File(new File(getClass().getResource("dataFiles").getFile()), "thunder.wav");

 

    /** Creates new form WelcomeWorld */

    public PanelWelcomeWorld(boolean vis) {

        initComponents();

 

 

        pnlSetup = new PanelSetup();

        pnlHeight = pnlSetup.getHeight();

        pnlWidth = pnlSetup.getWidth();

        this.setVisible(vis);

        this.setBounds(0, 0, pnlWidth, pnlHeight);

        this.setMinimumSize(new Dimension(pnlWidth, pnlHeight));

        this.setPreferredSize(new Dimension(pnlWidth, pnlHeight));

        this.setSize(pnlWidth, pnlHeight);

        this.setBackground(Color.red);

 

 

        try {

            image = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("BlackRobeWizard.jpg"), "BlackRobeWizard.jpg"));

 

            GameAudio.soundClip(backgroundLoad);

 

        } catch (Exception e) {

            System.out.println("can not find image");

        }

    }

 

    /** This method is called from within the constructor to

     * initialize the form.

     * WARNING: Do NOT modify this code. The content of this method is

     * always regenerated by the Form Editor.

     */

    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          

    private void initComponents() {

 

        lblWelcomeText00 = new javax.swing.JLabel();

        jLabel1 = new javax.swing.JLabel();

        cmdWelcomeStart = new javax.swing.JButton();

        cmdWelcomeHighScores = new javax.swing.JButton();

        cmdWelcomeQuit = new javax.swing.JButton();

 

        lblWelcomeText00.setFont(new java.awt.Font("Trebuchet MS", 1, 48));

        lblWelcomeText00.setForeground(new java.awt.Color(255, 255, 255));

        lblWelcomeText00.setText("Welcome to Pinball");

 

        jLabel1.setFont(new java.awt.Font("Trebuchet MS", 1, 48));

        jLabel1.setForeground(new java.awt.Color(255, 255, 255));

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        jLabel1.setText("Wizard the Game");

 

        cmdWelcomeStart.setBackground(new java.awt.Color(255, 192, 0));

        cmdWelcomeStart.setFont(new java.awt.Font("Trebuchet MS", 1, 48));

        cmdWelcomeStart.setForeground(new java.awt.Color(160, 191, 216));

        cmdWelcomeStart.setText("Start");

        cmdWelcomeStart.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                cmdWelcomeStartActionPerformed(evt);

            }

        });

 

        cmdWelcomeHighScores.setBackground(new java.awt.Color(255, 192, 0));

        cmdWelcomeHighScores.setFont(new java.awt.Font("Trebuchet MS", 1, 36));

        cmdWelcomeHighScores.setForeground(new java.awt.Color(160, 191, 216));

        cmdWelcomeHighScores.setText("High Scores");

        cmdWelcomeHighScores.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                cmdWelcomeHighScoresActionPerformed(evt);

            }

        });

 

        cmdWelcomeQuit.setBackground(new java.awt.Color(255, 192, 0));

        cmdWelcomeQuit.setFont(new java.awt.Font("Trebuchet MS", 1, 36));

        cmdWelcomeQuit.setForeground(new java.awt.Color(161, 191, 216));

        cmdWelcomeQuit.setText("Quit");

        cmdWelcomeQuit.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                cmdWelcomeQuitActionPerformed(evt);

            }

        });

 

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);

        this.setLayout(layout);

        layout.setHorizontalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(layout.createSequentialGroup()

                .addComponent(cmdWelcomeHighScores)

                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 336, Short.MAX_VALUE)

                .addComponent(cmdWelcomeStart)

                .addGap(192, 192, 192)

                .addComponent(cmdWelcomeQuit)

                .addContainerGap())

            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

                .addContainerGap(414, Short.MAX_VALUE)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 432, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(lblWelcomeText00, javax.swing.GroupLayout.PREFERRED_SIZE, 443, javax.swing.GroupLayout.PREFERRED_SIZE))

                .addGap(162, 162, 162))

        );

        layout.setVerticalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

                .addContainerGap()

                .addComponent(lblWelcomeText00, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)

                .addGap(18, 18, 18)

                .addComponent(jLabel1)

                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 527, Short.MAX_VALUE)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                        .addComponent(cmdWelcomeHighScores)

                        .addComponent(cmdWelcomeQuit))

                    .addComponent(cmdWelcomeStart))

                .addContainerGap())

        );

    }// </editor-fold>                       

 

    private void cmdWelcomeStartActionPerformed(java.awt.event.ActionEvent evt) {                                               

 

        PanelWorld.world.changeState(2, 0);//calls Panel World changeState method utilising the world interface to display the instructions screen

        PanelWorld.world.pnlInstructions.requestFocusInWindow();//using the Panel World world interface set the focus in the window to pnlInstructions

 

    }                                              

 

    private void cmdWelcomeHighScoresActionPerformed(java.awt.event.ActionEvent evt) {                                                    

        PanelWorld.world.pnlEnterHighScores.openData();//using the world interface call the method opendData from the panel enterHighScores

        PanelWorld.world.pnlEnterHighScores.populateHighScores();//using the world interface call the method populateHighScores

        PanelWorld.world.changeState(3, 0);//calls Panel World changeState method utilising the world interface to display the instructions screen

        PanelWorld.world.pnlHighScores.requestFocusInWindow();//using the Panel World world interface set the focus in the window to pnlInstructions

 

    }                                                   

 

    private void cmdWelcomeQuitActionPerformed(java.awt.event.ActionEvent evt) {                                              

 

        System.exit(0);//exit the game

 

    }                                             

    // Variables declaration - do not modify                    

    private javax.swing.JButton cmdWelcomeHighScores;

    private javax.swing.JButton cmdWelcomeQuit;

    private javax.swing.JButton cmdWelcomeStart;

    private javax.swing.JLabel jLabel1;

    private javax.swing.JLabel lblWelcomeText00;

    // End of variables declaration                  

 

    @Override

    protected void paintComponent(Graphics g) {

        super.paintComponent(g);

        if (image != null) {

            g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this);

        }

    }

}

PanelWorld.java

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

/*

 * PanelWorld.java

 *

 * Created on 10-Feb-2010, 18:05:42

 */

/**

 *

 * @author 00e5

 */

import java.awt.*;

import java.awt.geom.AffineTransform;

import java.io.EOFException;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.ObjectInputStream;

import java.io.ObjectOutputStream;

import java.util.Vector;

 

public class PanelWorld extends javax.swing.JFrame implements Runnable {

 

    Container container;

    public static PanelWorld world;

    public PanelWelcomeWorld pnlWorld;

    public GameWorld pnlGameWorld;

    public PanelInstructions pnlInstructions;

    public PanelGameOver pnlGameOver;

    public PanelGamePaused pnlGamePaused;

    public PanelHighScores pnlHighScores;

    public PanelEnterHighScores pnlEnterHighScores;

    private int gameState = 0;

    PanelSetup pnlSetup;

    int frameHeight = 0;

    int frameWidth = 0;

    public static Ball aBall = new Ball(new Point(50, 50), 20);

    Boolean running = false;

    Image image;

    public int pnlHeight = 0;

    public int pnlWidth = 0;

    public static Boolean launch = false;

    public Vector<VectorRecord> vector = new Vector<VectorRecord>();                   //create a new instance of a vector for the BMIRecord class called vector

    public VectorRecord record;                                                        //create a variable record for the BMIRecord class called record

    File vectorFile = new File(new File(getClass().getResource("dataFiles").getFile()), "SCORESdata.txt");       //create a new instance of the class file and navigate to the resources directory dataFiles

    ObjectInputStream input;                                                    //create a variable for the in put stream called input

    ObjectOutputStream output;                                                  //create a variable for the out put stream called output

   

 

 

    //creates a new form of PanelWorld

    public PanelWorld(boolean vis) {

        initComponents();

        container = this.getContentPane();

        pnlWorld = new PanelWelcomeWorld(false);

        container.setBackground(Color.yellow);

        container.add(pnlWorld);

        pnlGameWorld = new GameWorld(false);

        container.add(pnlGameWorld);

        pnlInstructions = new PanelInstructions(false);

        container.add(pnlInstructions);

        pnlEnterHighScores = new PanelEnterHighScores(false);

        container.add(pnlEnterHighScores);

        pnlHighScores = new PanelHighScores(false);

        container.add(pnlHighScores);

        pnlGamePaused = new PanelGamePaused(false);

        container.add(pnlGamePaused);

        pnlGameOver = new PanelGameOver(false);

        container.add(pnlGameOver);

      

        // btnCancel.setVisible(false);

        pnlSetup = new PanelSetup();

        pnlHeight = pnlSetup.getHeight();

        pnlWidth = pnlSetup.getWidth();

        this.setVisible(vis);

        this.setBounds(0, 0, pnlWidth, pnlHeight + 70);

        this.setMinimumSize(new Dimension(pnlWidth, pnlHeight + 70));

        this.setPreferredSize(new Dimension(pnlWidth, pnlHeight +70));

        //this.setSize(pnlWidth, pnlHeight);

        this.setBackground(Color.red);

        aBall.setMotion(3.0,6.0);

        reset();

     

    }

 

 

 

   

 

    /** This method is called from within the constructor to

     * initialize the form.

     * WARNING: Do NOT modify this code. The content of this method is

     * always regenerated by the Form Editor.

     */

    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed" desc="Generated Code">                         

    private void initComponents() {

 

        cmdReset = new javax.swing.JButton();

        cmdQuit = new javax.swing.JButton();

 

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

 

        cmdReset.setText("Reset");

        cmdReset.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                cmdResetActionPerformed(evt);

            }

        });

 

        cmdQuit.setText("Quit");

        cmdQuit.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                cmdQuitActionPerformed(evt);

            }

        });

 

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

        getContentPane().setLayout(layout);

        layout.setHorizontalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(layout.createSequentialGroup()

                .addContainerGap()

                .addComponent(cmdReset)

                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 262, Short.MAX_VALUE)

                .addComponent(cmdQuit)

                .addContainerGap())

        );

        layout.setVerticalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

                .addContainerGap(266, Short.MAX_VALUE)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                    .addComponent(cmdReset)

                    .addComponent(cmdQuit))

                .addContainerGap())

        );

 

        pack();

    }// </editor-fold>                        

 

    private void cmdResetActionPerformed(java.awt.event.ActionEvent evt) {                                        

 

        reset();//calls the method reset

 

    }                                       

 

    private void cmdQuitActionPerformed(java.awt.event.ActionEvent evt) {                                       

 

        System.exit(0);//exits the system

 

    }                                      

 

    /**

     * @param args the command line arguments

     */

    public static void main(String args[]) {

        world = new PanelWorld(true);

        world.setVisible(true);

        for (int i = 0; i < 60000; i++) {

            world.run();

        }

    }

    // Variables declaration - do not modify                     

    private javax.swing.JButton cmdQuit;

    private javax.swing.JButton cmdReset;

    // End of variables declaration                  

 

    public void changePanel() {

        if (gameState == 0) {

            pnlWorld.setVisible(true);

        }

        if (gameState == 1) {

            pnlGameWorld.setVisible(true);

        }

        if (gameState == 2){

            pnlInstructions.setVisible(true);

        }

        if (gameState == 3){

            pnlHighScores.setVisible(true);

        }

        if (gameState == 4){

            pnlGamePaused.setVisible(true);

        }

        if (gameState == 5){

            pnlGameOver.setVisible(true);

        }

        if (gameState == 6){

            pnlEnterHighScores.setVisible(true);

        }

    }

 

    public void changeState(int state, int pnlChange) {

        gameState = state;

        visiblePanel(pnlChange);

        changePanel();

    }

 

    public void visiblePanel(int pnlChange) {

        //this will make a panel not visible using the if

        if (pnlChange == 0) {

            pnlWorld.setVisible(false);

        }

        if (pnlChange == 1) {

            pnlGameWorld.setVisible(false);

        }

         if (pnlChange == 2){

            pnlInstructions.setVisible(false);

        }

        if (pnlChange == 3){

            pnlHighScores.setVisible(false);

        }

        if (pnlChange == 4){

            pnlGamePaused.setVisible(false);

        }

        if (pnlChange == 5){

            pnlGameOver.setVisible(false);

        }

        if (pnlChange == 6){

            pnlEnterHighScores.setVisible(false);

        }

 

    }

 

    public void run() {

        world.changePanel();

        moving();

        repaint();

        try {

            Thread.sleep(50);

        } catch (InterruptedException e) {

            System.exit(0);

        }

    }

    @Override

    public void paint(Graphics g){

        super.paint(g);

        Graphics2D g1 = (Graphics2D) g;

        g1.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        if(gameState == 1){

            aBall.paint(g);

        }

        g1.drawImage(null, AffineTransform.getScaleInstance(1, 1), null);

        g1.dispose();

    }

 

    public void moving(){

        if (gameState == 1){

            aBall.move();

        }

    }

 

    public void reset(){

        aBall.moveTo(pnlWidth - 50, pnlHeight - 50);

        aBall.setMotion(0.0, 0.0);

     

    }

 

    public void launch(){

        launch = true;

        aBall.setMotion(0.0, -6.0);

    }

 

 

        public void saveFile() {                                                   //declaration of the method createFile

 

        try {                                                            //try statement with the opening bracket

            output = new ObjectOutputStream(new FileOutputStream(vectorFile));        //assign the value of file to the file output stream as part of a new instance of the input output stream which is the value of a variable output

            int count = 0;                                                      //create a local integer variable called count and set it to zero

            if (vectorFile.exists()) {                                                //if statement to check that the file exists, with the opening bracket of the if statement

                if (vectorFile.isFile()) {                                            //if statement to check that the file is actually a file, with the opening bracket of the if statement

                    while (count < vector.size()) {                             //while loop, while the variable count is less than the size of the vector vector and the opening bracket to the while statement

                        record = vector.get(count);

                        System.out.println(record.getScore());                  //assign the value of vector for a specific index value, count, to the variable record

                        output.writeObject(record);                             //using the variable output write the contents of record to file

                        count++;                                                //increament the variable count by plus one

                    }                                                           //closing brackets for the while statement

                }                                                               //closing bracket for the if statement

            }                                                                   //closing bracket for the if statement

        } catch (IOException e) {                                               //closing bracket for the try statement, a catch of input output exception and the opening bracket for the catch statement

        }                                                                       //closing bracket for the catch statement

    }

 

    public void openData() {                                                    //declaration of the method openData

 

        try {                                                                   //try statement with the opening bracket

            vector.clear();                                                     //clear the vector called vector

            input = new ObjectInputStream(new FileInputStream(vectorFile));           //assign the value of file to the file input stream as part of a new instance of the output input stream

            while (true) {                                                      //until the end of file as a while loop with the opening bracket

                record = (VectorRecord) input.readObject();                     //read the value of a record into the variable record from the file

                vector.add(record);

                 System.out.println(record.getScore() + " read in");//add the vaule of record to the vector called vector

            }                                                                   //closing bracket for the while loop

        } catch (EOFException e) {                                              //closing bracket of the try statement the an end of file exception catch statement with the opening bracket of the cath statement

        } catch (IOException i) {                                               //closing bracket of the catch statement, a catch statement of input output exception with the opening bracket of the catch statement

        } catch (ClassNotFoundException e) {                                    //closing bracket of the catch statement, a catch statement of class not found exception with the opening bracket of the catch statement

        }                                                                       //closing bracket of the catch statement

 

    }

}

VetorRecord.java

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

import java.io.*;

import java.util.*;

import java.lang.*;

 

/**

 *

 * @author 00e5

 */

public class VectorRecord implements Serializable {

 

    private String gamerName;                                                //create the private class string variable gamerName

    private int score;                                                          //create the private class integer variable score

 

    public VectorRecord() {                                                     //Creates a new instance of VectorRecord

        this("", 0);                                                            //this and creates a container in the format one null string and one integer

    }

 

    public VectorRecord(String gName, int hScore) {                              //declaration for the record structure VectorRecord

        setgamerName(gName);                                                 //set the variable gamerName to the value gNmae

        setScore(hScore);                                                            //set the variable BMI to the value of bmi

    }

 

    public void setgamerName(String gName) {                                 //declaration for the set method MembershipNo with the string variable mno and the opening bracket for the method

        gamerName = gName;                                                   //assign the value of memno to the variable MembershipNo

    }                                                                           //closing bracket for the set method

 

    public String getgamerName() {                                           //declaration for the string get method MembershipNo

        return gamerName;                                                    //return the variable MembershipNo

    }                                                                           //closing bracket for the get method

 

 

    public void setScore(int hScore) {                                             //declaration for the set method BMI with the string variable dt and the opening bracket for the method

        score = hScore;                                                              //assign the value of bmi to the variable BMI

    }                                                                           //closing bracket for the set method

    public int getScore() {                                                     //declaration for the string get method BMI

        return score;                                                             //return the variable BMI

    }

 

    public String stringSCORE() {                                                 //declaration for the string method stringBMI

        return Integer.toString(score);                                             //return the value of BMI as a string, parsed from a float

    }

 

    public static class gamerName implements Comparator<VectorRecord> {      //declaration for the the public static class MembershipNo which implements Comparator in the format VectorRecord

 

        public int compare(VectorRecord one, VectorRecord two) {                //create a public integer called compare

            return one.gamerName.compareTo(two.gamerName);                //compare the values of MembershipNo for two different elements of VectorRecord

        }

    }

 

    public static class score implements Comparator<VectorRecord> {               //declaration for the the public static class BMI which implements Comparator in the format VectorRecord

 

        public int compare(VectorRecord one, VectorRecord two) {                //create a public integer called compare

         

            //return one.stringSCORE().valueOf(getScore()).compareTo(two.stringSCORE().valueOf(getScore()));

            return one.stringSCORE().compareTo(two.stringSCORE());                  //compare the values of stringBMI for two different elements of VectorRecord

        }

    }

 

}

VectorSort.java

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

/**

 *

 * @author 00e5

 */

public class VectorSort {

 

    public static void sort() {

 

        for (int i = 1; i < PanelWorld.world.pnlEnterHighScores.vector.size(); i++) {

 

                for (int j = 0; j < PanelWorld.world.pnlEnterHighScores.vector.size() - i; j++) {

 

                    if (PanelWorld.world.pnlEnterHighScores.vector.get(j).getScore() < PanelWorld.world.pnlEnterHighScores.vector.get(j + 1).getScore()) {

 

                        VectorRecord temp1 = PanelWorld.world.pnlEnterHighScores.vector.get(j);

                        VectorRecord temp2 = PanelWorld.world.pnlEnterHighScores.vector.get(j + 1);

 

                       PanelWorld.world.pnlEnterHighScores.vector.set(j, temp2);

                       PanelWorld.world.pnlEnterHighScores.vector.set( j + 1, temp1);

 

                    }

                }

        }

    }

}


Test Plan

Test ID

Test

Expected Result

Actual Result

Comments

001

The application complies and runs

The application runs and the welcome screen is displayed

The welcome screen displays as expected

002

Press start on the welcome screen

The instruction screen is displayed

The instruction screen displays as expected

 

Press High scores on the welcome screen

The High scores screen is displayed and the scores are populated

The high score screen displays as expected

003

Press start on the instructions screen

The game screen is displayed with 5 lives and the ball in the launch position

The game screen displays as expected, the ball is actually there

004

Press Quit on the instructions screen

The game exits

The game exits

The game exits as expected

005

Press High Scores on the instruction screen

The High scores screen is displayed and the scores are populated

The high scores screen displays as expected

006

Press the \ key to move the paddle left

The paddle moves left to the edge of the screen and stops

The paddle moves to the left edge of the screen and stops

007

Press the / key to move the paddle right

The paddle moves right to the edge of the screen and stops

The paddle moves to the right edge of the screen and stops

008

Check that the ball reflects from the sides of the game area

The ball reflects from the boundary edges and re-enters the play area

The ball reflects from all boundary edges successfully into the play area

009

Check that the ball reflects from the three colliders

The ball is reflected back into the play area

The ball successfully rebounds into the play area and the score is increased

010

Check the ball reflects from the paddle

The ball is reflected back into the play area

 

The ball successfully rebounds into the play area and the score is increased

011

Check that the score is incremented when the ball collides with colliders and the paddle

The score is incremented

The score increments successfully

012

Check that lives are lost when the ball reaches the dead zone, and that the ball is reset to the launch position

The number of lives is decreased by 1 until all five lives are lost

Lives are lost when the ball enters the dead zone at the bottom of the screen

013

Check that game over screen appears when all lives are lost

The Game over screen appears at the end of the game

The game over screen appears when all lives are lost

014

Press the Quit button on the game over screen

The game exits

The game quits

The game exits

015

Press the enter user name button on the game over screen

The enter user name screen appears

The enter a user name screen appears as expected

016

Enter nothing into the user name a click ok

A dialog box appears and say that an invalid character has been entered

The dialog box appears as expected

017

Enter numbers into the user name an click ok

A dialog box appears and say that an invalid character has been entered

The dialog box appears as expected

018

Enter a user name into the user name box and click ok

The name is added to the high scores list if applicable and the users high score is displayed on the screen

The high scores screen is displayed and the users highest score is displayed

019

Click the play game button on the High scores screen

The game resets with five lives and the ball in the launch position

The instructions screen is displayed instead of the game screen, this was unexpected

020

Click quit on the High scores screen

The game exits

The game exits

The game exists

021

Check that the start sound plays

The sound plays on start up

The sound plays

The sound plays

022

Check that the boundary collision sound plays

The sound plays on each collision

The sound plays

The sound plays

023

Check that the collider collision sound plays

The sound plays on each collision

The sound plays

The sound plays

024

Check that the paddle collision sound plays

The sound plays on each collision

The sound plays

The sound plays