import javax.microedition.lcdui.*; import javax.microedition.lcdui.game.Sprite; import java.io.*; public class Unit extends Sprite implements Runnable{ public int x,y; //точка перемещения public boolean selected; //выбран ли юнит public Thread thread; public Unit(Image image,int x,int y){ super(image); setPosition(x,y); this.x=x; this.y=y; selected=false; thread=new Thread(this); } public void paint(Graphics g){ if (selected){ paint(g); g.setColor(255, 255, 255); g.drawRect(this.getX(), this.getY(), this.getWidth(), this.getHeight()); }else paint(g); } 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 (getX()x){move(-1,0);} else if (getY()y){move(0,-1);} try{thread.sleep(50);}catch(Exception e){} } } }