View Single Post
  #1 (permalink)  
Old 02-16-2008, 04:27 PM
joz_12345 joz_12345 is offline
Member
 
Join Date: Dec 2007
Posts: 17
joz_12345 is on a distinguished road
Can someone check my code
I'm making the rush hour game using a 6x6 grid so that cars will snap to each square when being moved. I have 6 images loaded in my photobucket account - a 2 square vertical, 3 square vertical, target vertical, 2 square horizontal, 3 square horizontal and target horizontal. Each of these are called as and when they are needed.

I have 3 classes at the moment - Car, Board and GUI.

Can someone check my code so far so that I know what i'm doing is correct and any pointers/advice would be appreciated as I'm a bit stuck now as to what to do next.
I still need my collision detection, and mouse listeners and a couple of other bits.

Car:
Code:
package rush; import java.awt.Image; import java.awt.Toolkit; public class Car_1{ public static final int HORIZONTALTWOBLOCK = 0; public static final int HORIZONTALTHREEBLOCK = 1; public static final int HORIZONTALTARGET = 2; public static final int VERTICALTWOBLOCK = 3; public static final int VERTICALTHREEBLOCK = 4; public static final int VERTICALTARGET = 5; private int xPos; private int yPos; private int orientandlength; public Car_1(int x, int y, int oandl) { this.xPos = x; this.yPos = y; this.orientandlength = oandl; } public void setX(int x) { this.xPos = x; } public int getX() { return xPos; } public void setY(int y) { this.yPos = y; } public int getY() { return yPos; } public void setOrientandLength(int oandl) { if(orientandlength == HORIZONTALTWOBLOCK) { Image image = Toolkit.getDefaultToolkit().getDefaultToolkit().createImage("http://i126.photobucket.com/albums/p85/geebs2006/2BlockCarHorizontal.jpg"); } else if (orientandlength == HORIZONTALTHREEBLOCK) { Image image = Toolkit.getDefaultToolkit().getDefaultToolkit().createImage("http://i126.photobucket.com/albums/p85/geebs2006/3BlockCarHorizontal.jpg"); } else if (orientandlength == HORIZONTALTARGET) { Image image = Toolkit.getDefaultToolkit().getDefaultToolkit().createImage("http://i126.photobucket.com/albums/p85/geebs2006/CarTargetHorizontal.jpg"); } else if (orientandlength == VERTICALTWOBLOCK) { Image image = Toolkit.getDefaultToolkit().getDefaultToolkit().createImage("http://i126.photobucket.com/albums/p85/geebs2006/2BlockCarVertical.jpg"); } else if (orientandlength == VERTICALTHREEBLOCK) { Image image = Toolkit.getDefaultToolkit().getDefaultToolkit().createImage("http://i126.photobucket.com/albums/p85/geebs2006/3BlockCarVertical.jpg"); } else if (orientandlength == VERTICALTARGET) { Image image = Toolkit.getDefaultToolkit().getDefaultToolkit().createImage("http://i126.photobucket.com/albums/p85/geebs2006/CarTargetVertical.jpg"); } } }
Board
Code:
package rush; import java.awt.Color; /** * * @author Steven Gibbs */ public class Board extends Car_1 { public static final int NOOFROWS = 6; public static final int NOOFCOLS = 6; private int theExit; // Car Object, Name of Object, Row Number, Column Number, Image Required Car_1 targetCar = new Car_1(2, 3, 0); Car_1 car1 = new Car_1(1, 1, 0); Car_1 car2 = new Car_1(1, 2, 1); Car_1 car3 = new Car_1(1, 5, 1); Car_1 car4 = new Car_1(4, 2, 1); Car_1 car5 = new Car_1(3, 6, 0); Car_1 car6 = new Car_1(6, 1, 1); Car_1 car7 = new Car_1(5, 5, 0); /** Creates a new instance of Board */ public Board(int exit, int x, int y, int oandl) { super(x, y, oandl); this.theExit = exit; } public void settheExit(int theExit) { this.theExit = theExit; } public int gettheExit() { return theExit; } }
GUI
Code:
package rush; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JPanel; /** * * @author Steven Gibbs */ public class InteractiveGUI extends Board{ /** Creates a new instance of InteractiveGUI */ public InteractiveGUI(int exit, int x, int y, int oandl) { super (exit, x, y, oandl); JPanel jp = new JPanel(); } }
Reply With Quote
Sponsored Links