diff --git a/src/Main.java b/src/Main.java index c2efae7..3c3063e 100644 --- a/src/Main.java +++ b/src/Main.java @@ -22,6 +22,7 @@ public class Main extends MIDlet implements PlayerListener { } public void startApp() { + Rms.restoreOptions(); mn = new Menu(); dsp.setCurrent(mn); } @@ -30,6 +31,7 @@ public class Main extends MIDlet implements PlayerListener { } public void destroyApp(boolean un) { + Rms.saveOptions(); notifyDestroyed(); } diff --git a/src/RayCanvas.java b/src/RayCanvas.java index 46b2c96..2290816 100644 --- a/src/RayCanvas.java +++ b/src/RayCanvas.java @@ -20,7 +20,7 @@ public class RayCanvas extends Canvas {// implements Runnable { private double posX, posY; //x and y start position private double dirX, dirY; //initial direction vector private double planeX, planeY; //the 2d raycaster version of camera plane - private int w,h; + private int w,h, fh; private long lastTime; private boolean showUI, end; private int size = 4; @@ -29,6 +29,7 @@ public class RayCanvas extends Canvas {// implements Runnable { setFullScreenMode(true); w = getWidth(); h = getHeight(); + fh = Font.getDefaultFont().getHeight()+2; glukstep = new int[colors.length]; glukmode = new byte[colors.length]; restart(true); @@ -227,10 +228,7 @@ public class RayCanvas extends Canvas {// implements Runnable { g.drawImage(pr, w / 2, h / 2, 3); if(showUI) showLabirinth(g, (int)posX, (int)posY); - if (end) { - g.setColor(0xFF6159); - g.drawString("Âû âûèãðàëè", w/2, h/2, 33); - } + if (end) drawStats(g); repaint(); } @@ -257,9 +255,11 @@ public class RayCanvas extends Canvas {// implements Runnable { } private void restart(boolean newsize) { + if(end) Rms.vict++; if(newsize) grid = new Grid(25); grid.newMaze(); end = false; + Rms.games++; posX = 1; posY = 1.1; for(int i=0; ih3 && y<(h-h3))) keyReleased(LEFT); else if(x>(w-w3) && (y>h3 && y<(h-h3))) keyReleased(RIGHT); } + + private void drawStats(Graphics g) { + g.setColor(0xFF6159); + g.drawString("Âû âûèãðàëè", w/2, h/2, 33); + g.drawString("Èãð: "+Rms.games, w/2, h/2+2, 17); + g.drawString("Ïîáåä: "+(Rms.vict+1), w/2, h/2+fh+2, 17); + g.drawString("% ïîáåä: "+((Rms.vict+1)*100/Rms.games), w/2, h/2+fh*2+2, 17); + } } diff --git a/src/Rms.java b/src/Rms.java new file mode 100644 index 0000000..ffd9a7e --- /dev/null +++ b/src/Rms.java @@ -0,0 +1,69 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +import java.io.*; +import javax.microedition.rms.*; + +/** + * + * @author aNNiMON + */ +public class Rms { + + private static final String rmsName = "RayCanvas"; + private static RecordStore rmsStore; + public static int games = 0; //количеÑтво игр + public static int vict = 0; //количеÑтво побед + + /** + * Сохранение наÑтроек + */ + public static void saveOptions() { + if (rmsStore != null) { + byte[] options = null; + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + dos.writeInt(games); + dos.writeInt(vict); + dos.flush(); + options = baos.toByteArray(); + dos.close(); + rmsStore.setRecord(1, options, 0, options.length); + } catch (InvalidRecordIDException ridex) { + try { + rmsStore.addRecord(options, 0, options.length); + } catch (RecordStoreException ex) {} + } catch (Exception ex) {} + } + if (rmsStore != null) { + try { + rmsStore.closeRecordStore(); + rmsStore = null; + } catch (RecordStoreException ex) {} + } + } + + /** + * ВоÑÑтановить наÑтройки + */ + public static void restoreOptions() { + try { + rmsStore = RecordStore.openRecordStore(rmsName, true); + } catch (RecordStoreException ex) { + rmsStore = null; + } + if (rmsStore != null) { + try { + DataInputStream dis = new DataInputStream(new ByteArrayInputStream(rmsStore.getRecord(1))); + games = dis.readInt(); + vict = dis.readInt(); + dis.close(); + } catch (Exception ex) { + } + } + } +} +