import javax.microedition.lcdui.*; import java.util.*; public class canvas extends Canvas implements Runnable{ public Thread t; public int pole[]; public int x,y; public int xTarget,yTarget,kx,ky; public int wasAI; public canvas() { super(); x=1; y=1; pole=new int[]{1,1,1,1,1,1,1,1,1,1, 1,0,0,0,0,0,0,0,0,1, 1,1,1,1,0,1,1,0,1,1, 1,0,0,0,0,0,0,0,0,1, 1,0,1,0,1,1,1,0,0,1, 1,0,1,0,0,0,0,0,0,1, 1,0,1,1,1,0,1,1,1,1, 1,0,0,0,0,0,1,1,1,1, 2,0,0,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1 }; t=new Thread(this); t.start(); } public void run(){ while(true){ repaint(); ai(); try{ t.sleep(2500); } catch(Exception e){} } } public void paint(Graphics g) { g.setColor(0,0,0); g.fillRect(0,0,getHeight(),getWidth()); int i=0; while(i<100){ switch(pole[i]){ case 0: g.setColor(0,0,0); break; case 1: g.setColor(200,200,200); break; case 2: g.setColor(230,0,0); break; } g.fillRect(kx+i%10*16,ky+i/10*16,16,16); i++; } g.setColor(200,0,0); g.fillRect(kx+x*16,ky+y*16,16,16); } public int getCell(int x,int y){ int cellNumber=y*10+x; return pole[cellNumber]; } public void search(){ for(int i=0;iy&&wasAI!=1){ int flag=getCell(x,y++); switch(flag){ case 0: y++; wasAI=1; break; case 1: int flag2lvl=getCell(x++,y); if(flag2lvl==0)x++; else x--; wasAI=1; break; } } if(xTargetx&&wasAI!=1){ int flag=getCell(x++,y); switch(flag){ case 0: x++; wasAI=1; break; case 1: int flag2lvl=getCell(x,y++); if(flag2lvl==0)y++; else y--; wasAI=1; break; } } wasAI=0; } }