Thread: help
View Single Post
  #12 (permalink)  
Old 12-13-2007, 11:03 PM
joz_12345 joz_12345 is offline
Member
 
Join Date: Dec 2007
Posts: 17
joz_12345 is on a distinguished road
Ok after a meeting with my supervisor we have decided it would be better to code it so that it uses a grid ie. the 6x6 grid with the rows numbered 1-6 or 0-5 and same with the columns ON A 300X300 JPANEL (each square therefore would be 50). Cars will then be placed on the board in the format (1,2) or 4,3) etc instead of having to use coordinates of 0-300.

I believe that its not too much work to convert what I have (similar to post 2 of this thread with a few changes here and there) to this format. I have started to convert my Car class first of all to get that set up. Could someone look over it and see if i'm on the right path (The orientation bits further down the class I am not sure about). My plan after is to use an arraylist to store the cars.

My Car class:

Code:
import java.awt.Color; import java.awt.Graphics; import java.awt.Point; import java.awt.Rectangle; class Car extends Rectangle{ private int xPos; private int yPos; private int width; private int height; private int orientation; Color color; public static final int HORIZONTAL = 0; public static final int VERTICAL = 1; Car(int x, int y, int w, int h, int o, Color color) { this.xPos = x; this.yPos = y; this.width = w; this.height = h; this.orientation = o; this.color = color; } public void setX(int xPos){ this.xPos = xPos; } public int getIntX(){ return xPos; } public void setY(int yPos){ this.yPos = yPos; } public int getIntY(){ return yPos; } public int getIntWidth(){ return width; } public int getIntHeight(){ return height; } public void SetOrientation(int orientation){ this.orientation = orientation; } public int getOrientation(){ return orientation; } public boolean contains(Point p) { return new Rectangle(xPos, yPos, width, height).contains(p); } public void paintCar(Graphics g){ g.setColor(color); g.fillRect(xPos,yPos,width,height); g.setColor(Color.BLACK); g.drawRect(xPos,yPos,width,height); } }
Reply With Quote