6
This commit is contained in:
parent
fa4a7c2968
commit
a7ba25d928
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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; i<glukmode.length; i++) {
|
||||
@ -304,4 +304,12 @@ public class RayCanvas extends Canvas {// implements Runnable {
|
||||
if(x<w3 && (y>h3 && 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);
|
||||
}
|
||||
}
|
||||
|
69
src/Rms.java
Normal file
69
src/Rms.java
Normal file
@ -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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user