6
This commit is contained in:
parent
fa4a7c2968
commit
a7ba25d928
@ -22,6 +22,7 @@ public class Main extends MIDlet implements PlayerListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void startApp() {
|
public void startApp() {
|
||||||
|
Rms.restoreOptions();
|
||||||
mn = new Menu();
|
mn = new Menu();
|
||||||
dsp.setCurrent(mn);
|
dsp.setCurrent(mn);
|
||||||
}
|
}
|
||||||
@ -30,6 +31,7 @@ public class Main extends MIDlet implements PlayerListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void destroyApp(boolean un) {
|
public void destroyApp(boolean un) {
|
||||||
|
Rms.saveOptions();
|
||||||
notifyDestroyed();
|
notifyDestroyed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ public class RayCanvas extends Canvas {// implements Runnable {
|
|||||||
private double posX, posY; //x and y start position
|
private double posX, posY; //x and y start position
|
||||||
private double dirX, dirY; //initial direction vector
|
private double dirX, dirY; //initial direction vector
|
||||||
private double planeX, planeY; //the 2d raycaster version of camera plane
|
private double planeX, planeY; //the 2d raycaster version of camera plane
|
||||||
private int w,h;
|
private int w,h, fh;
|
||||||
private long lastTime;
|
private long lastTime;
|
||||||
private boolean showUI, end;
|
private boolean showUI, end;
|
||||||
private int size = 4;
|
private int size = 4;
|
||||||
@ -29,6 +29,7 @@ public class RayCanvas extends Canvas {// implements Runnable {
|
|||||||
setFullScreenMode(true);
|
setFullScreenMode(true);
|
||||||
w = getWidth();
|
w = getWidth();
|
||||||
h = getHeight();
|
h = getHeight();
|
||||||
|
fh = Font.getDefaultFont().getHeight()+2;
|
||||||
glukstep = new int[colors.length];
|
glukstep = new int[colors.length];
|
||||||
glukmode = new byte[colors.length];
|
glukmode = new byte[colors.length];
|
||||||
restart(true);
|
restart(true);
|
||||||
@ -227,10 +228,7 @@ public class RayCanvas extends Canvas {// implements Runnable {
|
|||||||
|
|
||||||
g.drawImage(pr, w / 2, h / 2, 3);
|
g.drawImage(pr, w / 2, h / 2, 3);
|
||||||
if(showUI) showLabirinth(g, (int)posX, (int)posY);
|
if(showUI) showLabirinth(g, (int)posX, (int)posY);
|
||||||
if (end) {
|
if (end) drawStats(g);
|
||||||
g.setColor(0xFF6159);
|
|
||||||
g.drawString("Âû âûèãðàëè", w/2, h/2, 33);
|
|
||||||
}
|
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,9 +255,11 @@ public class RayCanvas extends Canvas {// implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void restart(boolean newsize) {
|
private void restart(boolean newsize) {
|
||||||
|
if(end) Rms.vict++;
|
||||||
if(newsize) grid = new Grid(25);
|
if(newsize) grid = new Grid(25);
|
||||||
grid.newMaze();
|
grid.newMaze();
|
||||||
end = false;
|
end = false;
|
||||||
|
Rms.games++;
|
||||||
posX = 1;
|
posX = 1;
|
||||||
posY = 1.1;
|
posY = 1.1;
|
||||||
for(int i=0; i<glukmode.length; i++) {
|
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);
|
if(x<w3 && (y>h3 && y<(h-h3))) keyReleased(LEFT);
|
||||||
else if(x>(w-w3) && (y>h3 && y<(h-h3))) keyReleased(RIGHT);
|
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