import java.awt.*; //--- tile class --- public class tile { final int NORTH=0; final int EAST=1; final int SOUTH=2; final int WEST=3; final int MAXTIME = 1000; boolean showHide=true,drawMe=true; int dir; long animateTime; public void flip(int ndir){ showHide = !showHide; drawMe = true; dir = ndir; animateTime = System.currentTimeMillis(); } public Rectangle showRect(Rectangle r){ return (showHide?shrink(r):grow(r)); } public Rectangle hideRect(Rectangle r){ return (showHide?grow(r):shrink(r)); } public boolean redraw(){return drawMe;} //--- private functions --- Rectangle shrink(Rectangle or){ Rectangle r = new Rectangle(or.x,or.y,or.width,or.height); long time = System.currentTimeMillis() - animateTime; if (time>MAXTIME) { time = MAXTIME; drawMe = false; } int dwide = r.width-r.x; int dhigh = r.height-r.y; int back = MAXTIME - (int)time; switch (dir) { case NORTH: r.y += dhigh * back/MAXTIME; break; case SOUTH: r.height -= dhigh * back/MAXTIME; break; case WEST: r.x += dwide * back/MAXTIME; break; case EAST: r.width -= dwide * back/MAXTIME; break; } return r; } Rectangle grow(Rectangle or){ Rectangle r = new Rectangle(or.x,or.y,or.width,or.height); long time = System.currentTimeMillis() - animateTime; if (time>MAXTIME) { time = MAXTIME; drawMe = false; } int dwide = r.width-r.x; int dhigh = r.height-r.y; switch (dir) { case NORTH: r.height -= dhigh * time/MAXTIME; break; case SOUTH: r.y += dhigh * time/MAXTIME; break; case WEST: r.width -= dwide * time/MAXTIME; break; case EAST: r.x += dwide * time/MAXTIME; break; } return r; } }