import javax.microedition.lcdui.*; import javax.microedition.lcdui.game.*; import java.io.*; public class Unit extends Layer implements Runnable{ public Sprite sprite; //спрайт юнита public int x,y; //точка перемещения public boolean selected; //выбран ли юнит public Thread thread; public Unit(Image image,int x,int y){ sprite=new Sprite(image); sprite.setPosition(x,y); this.x=x; this.y=y; selected=false; thread=new Thread(this); } public void paint(Graphics g){ if (selected){ sprite.paint(g); g.setColor(255, 255, 255); g.drawRect(sprite.getX(), sprite.getY(), sprite.getWidth(), sprite.getHeight()); }else paint(g); } public boolean collidesWith(Sprite sprite,boolean pixelLevel){ boolean b=false; if (sprite.collidesWith(sprite, pixelLevel)) b=true; return b; } public void select(){ selected=true; } public void deselect(){ selected=false; } public void startMove(int x,int y){ this.x=x; this.y=y; thread.start(); } public void run(){ while(true){ if (sprite.getX()x){sprite.move(-1,0);} else if (sprite.getY()y){sprite.move(0,-1);} try{thread.sleep(50);}catch(Exception e){} } } }