/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author turing */ import javax.microedition.lcdui.*; import javax.microedition.rms.*; import java.io.*; public class KaardiLouend extends Canvas{ int x, y; RecordStore rs; RecordEnumeration re; public KaardiLouend(){ try{ rs=RecordStore.openRecordStore("kohad", true); re=rs.enumerateRecords(null, null, true); }catch(Exception e){System.out.println(e.getMessage());} } protected void paint(Graphics g){ g.setColor(255, 255, 255); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(0, 0, 0); g.drawRect(x-5, y-5, 10, 10); re.rebuild(); try{ while(re.hasNextElement()){ byte[] b=re.nextRecord(); DataInputStream dis=new DataInputStream(new ByteArrayInputStream(b)); int ux=dis.readInt(); int uy=dis.readInt(); g.fillRect(ux-5, uy-5, 10, 10); } }catch(Exception ex){ ex.printStackTrace(); } } protected void keyPressed(int kood){ if(getGameAction(kood)==Canvas.LEFT){x--;} if(getGameAction(kood)==Canvas.RIGHT){x++;} if(getGameAction(kood)==Canvas.UP){y--;} if(getGameAction(kood)==Canvas.DOWN){y++;} if(getGameAction(kood)==Canvas.FIRE){ lisaKirje(); } repaint(); } void lisaKirje(){ byte[] bm=leiaBaidiMassiiv(); try{ rs.addRecord(bm, 0, bm.length); }catch(Exception e){ System.out.println(e.getMessage()); } } byte[] leiaBaidiMassiiv(){ ByteArrayOutputStream bos=new ByteArrayOutputStream(); DataOutputStream dos=new DataOutputStream(bos); try{ dos.writeInt(x); dos.writeInt(y); }catch(Exception e){System.out.println(e.getMessage());} return bos.toByteArray(); } public void showNotify(){ x=getWidth()/2; y=getHeight()/2; } }