import java.awt.*; public abstract class Roach { final static int MINSIZE = 20, MAXSIZE = 40, MOVEMAX = 10; // instance variables protected int x, y, // initial upper left corner w, h, // width, height dx, dy; // motion vector protected Color color; public Roach(int fieldSize) { x = (int) (Math.random()*(fieldSize - MAXSIZE)) + zapem.XUL; y = (int) (Math.random()*(fieldSize - MAXSIZE)) + zapem.YUL; w = (int) (Math.random()*(MAXSIZE - MINSIZE + 1)) + MINSIZE; h = (int) (Math.random()*(MAXSIZE - MINSIZE + 1)) + MINSIZE; dx = (int) (Math.random()*(2*MOVEMAX + 1)) - MOVEMAX - 1; dy = (int) (Math.random()*(2*MOVEMAX + 1)) - MOVEMAX - 1; color = new Color( (float) Math.random(), (float) Math.random(), (float) Math.random()); } public void setDx(int D) { dx = D; } public void setDy(int D) { dy = D; } public void setColor(Color c) { color = c; } public void move() { x += dx; y += dy; } public boolean in(int X, int Y) { return (x <= X && X <= x + w && y <= Y && Y <= y + h) ? true : false; } public boolean out(int XUL, int YUL, int XLR, int YLR) { return (x <= XUL || XLR <= x + w || y <= YUL || YLR <= y + h) ? true : false; } }