import javax.microedition.lcdui.*; public class cv extends Canvas implements Runnable { public static int random(int min,int max){ return min +(int)(Math.random()*((max>min)?(max-min+1): (min-max+1))); } public int x,y,eny,enx,roadx,roady,altx,alty; public int speed,k,rotspeed; public boolean isdie=false; /** * constructor */ public cv() { super(); speed=1; x=getWidth()/2-5; y=92; eny=-40; enx=23; } public void start(){ Thread t=new Thread(this); t.start(); } public void run(){ while(true){ repaint(); try { Thread.sleep(100); } catch(Exception ex){} } } public void paint(Graphics g) { g.setColor(0,0,0); g.fillRect(0,0,getWidth(),getHeight()); if(isdie) { g.setColor(220,20,32); g.drawString("проиграл",2,3,Graphics.TOP); try{ Thread.sleep(1000); } catch(Exception ex){} isdie=false; } else { g.setColor(0,230,60); g.fillRect(x,y,10,30); g.setColor(230,0,0); g.fillRect(enx,eny,10,30); eny+=speed; if(eny>getHeigth()){ eny=-40; enx=random(0,getWidth()); } if(k!=0){ sk(); } } } /** * Called when a key is pressed. */ protected void keyPressed(int key) { k=key; } public void keyReleased(int key){ k=0; } public void sk(){ switch(k){ case KEY_NUM4: x-=2; if(x<0) { x=0; } break; case KEY_NUM6 : x+=2; if(x>getWidth()-10) { x=getWidth()-10; } } } }