import java.util.Vector; import java.awt.*; public class Icobj implements Runnable { public final static byte Right=0, Left=1, Up=2, Down=3; public int radius = 10, step = 30; protected String name; public Color color = Color.blue; public double x,y; protected Thread myThread; protected boolean painted = false; protected IcobjWorkspace workspace = null; protected static int rand(int n){ return (int)(Math.random()*1000)%n; } public Icobj(String n,int x, int y){ name = n; this.x = x; this.y = y; } public Icobj(String n){ this(n,rand(300),rand(300)); } public String toString(){ return name+"("+x+","+y+")"; } public void setWorkspace(IcobjWorkspace w){ workspace = w; } public void behavior(){ painted = false; } // moving public void translate(double dx,double dy){ x+=dx; y+=dy; } public void unprotMoveRight(){ x+=step; } public void unprotMoveLeft(){ x-=step; } public void unprotMoveDown(){ y+=step; } public void unprotMoveUp(){ y-=step; } public void moveRight(){ if(xstep+radius) x-=step; } public void moveDown(){ if(ystep+radius) y-=step; } public void moveRandom(){ switch(rand(4)){ case Right: moveRight(); return; case Left: moveLeft(); return; case Up: moveUp(); return; default: moveDown(); } } // detect protected double dist(Icobj i){ double dx=x-i.x, dy=y-i.y; return Math.sqrt(dx*dx+dy*dy); } protected Icobj closest(int dim, Color color){ double min = 100000; Icobj target = null; Vector icobjs = workspace.icobjsInInfluence(this,dim); for(int i=0;i