import javax.microedition.lcdui.*; import java.io.*; import java.util.*; public class Game extends Canvas implements Runnable{ int width; int height; int x; int y; int speed; int color_1; int color_2; int color_3; int scores; boolean up; boolean down; boolean left; boolean right; Random rnd; public Font fo = Font.getFont(32, 1, 8); public Game() { setFullScreenMode(true); width = getWidth();//ширина height = getHeight();//высота x = width/2;//координаты х y = height/2;//координаты у //color_1-color_3 цвет rgb(0-255) speed = 0; //скорость scores =0; rnd= new Random(); color_1=rnd.nextInt(255); color_2=rnd.nextInt(255); color_3=rnd.nextInt(255); try { }catch(Exception ex) {ex.printStackTrace();} new Thread(this).start(); } public void paint(Graphics g) { g.setFont(fo); g.setColor(color_1,color_2,color_3); g.fillArc(x,y,40,40,0,360); g.setColor(0,0,0); g.drawString("Очки: "+scores+" ", 2, 2, 20); } public void update(){ repaint(); System.gc(); } public void keyPressed(int k) { if(k==KEY_NUM4||k==-3){left=true;} if(k==KEY_NUM6||k==-4){right=true;} if(k==KEY_NUM2||k==-1){up=true;} if(k==KEY_NUM8||k==-2){down=true;} } public void keyReleased(int k) { if(k==KEY_NUM4||k==-3){left=false;} if(k==KEY_NUM6||k==-4){right=false;} if(k==KEY_NUM2||k==-1){up=false;} if(k==KEY_NUM8||k==-2){down=false;} } public void run() { while(true) { if(up) { y-=2; } if(down) { y+=2; } if(right) { x+=1; } if(left) { x-=1; } repaint(0,0,width,height); try { Thread.sleep(20); }catch(Exception ex){} }}}