import java.awt.*; public class Car { private Color color = Color.BLUE; private int xpos = 0; private int ypos = 0; private int fuel = 2000; public Car() { } /* public Car (Color c, int x, int y, int f) { color = c; xpos = x; ypos = y; fuel = f; } */ public Car (Color c, int x, int y, int f) { setColor (c); setXPos (x); setYPos (y); setFuel (f); } public void setXPos (int x) { fuel -= Math.abs(getXPos()-x); xpos = x; } public void setYPos (int y) { fuel -= Math.abs(getYPos()-y); ypos = y; } public void setPos (int x, int y) { setXPos(x); setYPos(y); } public void setColor (Color c) { color = c; } public void setFuel (int f) { fuel = f; } public int getFuel() { return fuel; } public int getXPos() { return xpos; } public int getYPos() { return ypos; } public Color getColor() { return color; } private final int CAR_WIDTH = 100; private final int CAR_HEIGHT = 200; private final int TIRE_WIDTH = 20; private final int TIRE_HEIGHT = 40; private final int TIRE_OFFSET = 20; public void paint (Graphics g) { if ( fuel < 0 ) { color = Color.RED; } g.setColor (color); g.fillRect (getXPos()-CAR_WIDTH/2, getYPos()-CAR_HEIGHT/2, CAR_WIDTH, CAR_HEIGHT); // Draw the tires g.setColor (Color.BLACK); g.fillRect (getXPos()-(CAR_WIDTH/2+TIRE_WIDTH), getYPos()-(CAR_HEIGHT/2-TIRE_OFFSET), TIRE_WIDTH, TIRE_HEIGHT); g.fillRect (getXPos()-(CAR_WIDTH/2+TIRE_WIDTH), getYPos()+(CAR_HEIGHT/2-TIRE_OFFSET-TIRE_HEIGHT), TIRE_WIDTH, TIRE_HEIGHT); g.fillRect (getXPos()+(CAR_WIDTH/2), getYPos()+(CAR_HEIGHT/2-TIRE_OFFSET-TIRE_HEIGHT), TIRE_WIDTH, TIRE_HEIGHT); g.fillRect (getXPos()+(CAR_WIDTH/2), getYPos()-(CAR_HEIGHT/2-TIRE_OFFSET), TIRE_WIDTH, TIRE_HEIGHT); } }