import javax.microedition.lcdui.*; public class canv extends Canvas implements Runnable{ public int screenw,screenh,i,speed,nap; public static int screenl,n; public int botX[],botY[],botS[]; public boolean firstRun=true; public boolean fire=false; /** * constructor */ public canv() { screenw=getWidth(); screenh=getHeight(); if(screenhscreenw) screenl=screenh; speed=1; nap=1; i=1; } public void paint(Graphics g) { if(firstRun!=false){ first(); } g.setColor(200,0,200); g.drawString(""+Integer.toString(botX[0]),0,0,1); g.setColor(0,0,0); g.fillRect(0,0,screenw+1,screenh+1); g.setColor(0,200,210); g.fillRect(botX[0],botY[0],17,17); g.setColor(0,200,0); for(i=1;i<4;i++){ g.fillRect(botX[i],botX[i],20,20); botai(); } } } public void start(){ Thread t=new Thread(this); t.start(); } public void run() { repaint(); try { Thread.sleep(20); } catch(Exception ex){ } } public void first(){ firstRun=false; botX[0]=screenw/2; botY[0]=screenh/2; while(i<4){ botS[i]=0; botint(); i++; } } /** * Called when a key is pressed. */ protected void keyPressed(int keyCode) { if(keyCode==KEY_NUM5) repaint(); } public void botint(){ if(i>0&&i<4){ botS[i]=1; n=rnd.intscpart(); switch(n){ case 1: botX[i]=-25; botY[i]=rnd.intsc(screenl); break; case 2: botY[i]=screenw+25; botX[i]=rnd.intsc(screenl); break; case 3: botX[i]=screenh+25; botY[i]=rnd.intsc(screenl); break; case 4: botY[i]=-25; botX[i]=rnd.intsc(screenl); break; } } } public void botai() { if(botX[i]>botX[0]&&botX[i]botY[0]) botS[i]=0; } if(botX[i]botX[0]){ if(botS[i]==2)botX[i]-=speed; if(fire!=false&&nap==3&&botY[i]>botY[0]) botS[i]=0; if(fire!=false&&nap==1&&botY[i]botY[0]){ if(botS[i]==2)botY[i]-=speed; if(fire!=false&&nap==4&&botX[i]>botX[0]) botS[i]=0; if(fire!=false&&nap==2&&botX[i]botY[0]&&botY[i]+20botX[0]) botS[i]=0; if(fire!=false&&nap==2&&botX[i]0) botX[i]-=speed; if(botS[i]==1&&botY[i]-botY[0]<0) botY[i]+=speed; if(botS[i]==1&&botY[i]-botY[0]>0) botY[i]-=speed; if(botS[i]==0) botint(); } }