home *** CD-ROM | disk | FTP | other *** search
- import java.io.ByteArrayInputStream;
- import java.io.ByteArrayOutputStream;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import javax.microedition.lcdui.Alert;
- import javax.microedition.lcdui.AlertType;
- import javax.microedition.lcdui.Command;
- import javax.microedition.lcdui.CommandListener;
- import javax.microedition.lcdui.Display;
- import javax.microedition.lcdui.Displayable;
- import javax.microedition.lcdui.Form;
- import javax.microedition.lcdui.Image;
- import javax.microedition.lcdui.ImageItem;
- import javax.microedition.midlet.MIDlet;
- import javax.microedition.rms.RecordStore;
-
- public class AirForceX extends MIDlet implements CommandListener {
- private Display display = Display.getDisplay(this);
- private Form fmMain = new Form("AirForceX ");
- private Command cmExit = new Command("Exit", 7, 1);
- private Command cmStart = new Command("Start", 1, 1);
- private Command cmBack;
- private AFAnimationCanvas canvas = new AFAnimationCanvas(this);
- private RecordStore AF_rs = null;
- static final String REC_STORE = "AirForceXScores";
- private int[] scoreArray;
- private int[] TheScore;
- private int bestScore;
- private int lastScore;
- private int presentScore;
- private int Turns;
- private Alert alAlert;
- private boolean storeExits = true;
- int gameCounter = 0;
- // $FF: renamed from: im javax.microedition.lcdui.Image
- Image field_0 = null;
-
- public AirForceX() {
- try {
- this.field_0 = Image.createImage("/smallLogo2.png");
- this.fmMain.append(new ImageItem((String)null, this.field_0, 3, (String)null));
- } catch (Exception var2) {
- System.out.println("error with image load: " + var2);
- }
-
- this.fmMain.append("\nAir ForceX.\nCopyright JAR Developments 2003.\n**Instructions**\n4-Left\n6-Right\n2-Up\n8-Down\n5-Fire\n");
- this.fmMain.addCommand(this.cmStart);
- this.fmMain.addCommand(this.cmExit);
- this.fmMain.setCommandListener(this);
- this.scoreArray = new int[3];
- this.TheScore = new int[3];
- }
-
- public void startApp() {
- this.display.setCurrent(this.fmMain);
- }
-
- public void CloseApp() {
- this.display.setCurrent(this.fmMain);
- }
-
- public void pauseApp() {
- }
-
- public void destroyApp(boolean var1) {
- }
-
- public void commandAction(Command var1, Displayable var2) {
- if (var1 == this.cmExit) {
- this.destroyApp(false);
- ((MIDlet)this).notifyDestroyed();
- } else if (var1 == this.cmStart) {
- this.display.setCurrent(this.canvas);
- this.canvas.repaint();
- this.openRecStore();
- if (this.storeExits) {
- this.closeRecStore();
- } else {
- for(int var3 = 0; var3 < 3; ++var3) {
- this.TheScore[var3] = 1;
- }
-
- this.openRecStoreCreate();
- this.writeFirstData(this.TheScore);
- this.closeRecStore();
- }
-
- if (this.gameCounter == 0) {
- this.fmMain.delete(1);
- this.fmMain.delete(0);
- this.fmMain.append("www.phonegames4u.com presents Air ForceX. Copyright JAR Developments 2003");
- this.field_0 = null;
- }
-
- ++this.gameCounter;
- if (this.gameCounter > 1) {
- this.canvas.reStartSA();
- this.canvas.showNotify();
- }
- }
-
- }
-
- public void displayScore() {
- this.alAlert = new Alert("Score", "\nScore:\n" + this.Turns + "\nLast Score:\n" + this.lastScore + "\nBest Score\n" + this.TheScore[2], (Image)null, (AlertType)null);
- this.alAlert.setTimeout(-2);
- this.display.setCurrent(this.alAlert, this.fmMain);
- }
-
- public void openRecStoreCreate() {
- try {
- this.AF_rs = RecordStore.openRecordStore("AirForceXScores", true);
- this.storeExits = true;
- } catch (Exception var2) {
- this.storeExits = false;
- System.out.println(" there is an error in openRecStoreCreate: " + var2);
- }
-
- }
-
- public void writeFirstData(int[] var1) {
- try {
- ByteArrayOutputStream var2 = new ByteArrayOutputStream();
- DataOutputStream var3 = new DataOutputStream(var2);
- boolean var5 = true;
-
- for(int var6 = 0; var6 < var1.length; ++var6) {
- var3.writeInt(var1[var6]);
- var3.flush();
- byte[] var4 = var2.toByteArray();
- this.AF_rs.addRecord(var4, 0, var4.length);
- var2.reset();
- }
-
- var2.close();
- var3.close();
- } catch (Exception var7) {
- System.out.println(" there is an error in write streams1: " + var7);
- }
-
- }
-
- public void RRScore(int var1) {
- this.Turns = var1;
- }
-
- public void RMSScore() {
- this.openRecStore();
- this.readSream();
- this.calculateScore();
- this.writeScores();
- this.closeRecStore();
- this.displayScore();
- }
-
- public void openRecStore() {
- try {
- this.AF_rs = RecordStore.openRecordStore("AirForceXScores", false);
- } catch (Exception var2) {
- this.storeExits = false;
- }
-
- }
-
- public void closeRecStore() {
- try {
- this.AF_rs.closeRecordStore();
- } catch (Exception var2) {
- System.out.println(" there is an error closing the RMS: " + var2);
- }
-
- }
-
- public void writeScores() {
- this.TheScore[0] = this.Turns;
- }
-
- public void writeStream(int[] var1) {
- try {
- ByteArrayOutputStream var2 = new ByteArrayOutputStream();
- DataOutputStream var3 = new DataOutputStream(var2);
- boolean var5 = true;
-
- for(int var6 = 0; var6 < var1.length; ++var6) {
- var3.writeInt(var1[var6]);
- var3.flush();
- byte[] var4 = var2.toByteArray();
- this.AF_rs.setRecord(var6 + 1, var4, 0, var4.length);
- var2.reset();
- }
-
- var2.close();
- var3.close();
- } catch (Exception var7) {
- System.out.println(" there is an error in write streams: " + var7);
- }
-
- }
-
- public void readSream() {
- try {
- byte[] var1 = new byte[50];
- ByteArrayInputStream var2 = new ByteArrayInputStream(var1);
- DataInputStream var3 = new DataInputStream(var2);
-
- for(int var4 = 1; var4 <= this.AF_rs.getNumRecords(); ++var4) {
- this.AF_rs.getRecord(var4, var1, 0);
- this.scoreArray[var4 - 1] = var3.readInt();
- var2.reset();
- }
-
- this.presentScore = this.scoreArray[0];
- this.lastScore = this.scoreArray[1];
- this.bestScore = this.scoreArray[2];
- var2.close();
- var3.close();
- } catch (Exception var5) {
- System.out.println(" there is an error in read streams1: " + var5);
- }
-
- }
-
- public void calculateScore() {
- this.presentScore = this.Turns;
- this.TheScore[0] = this.Turns;
- this.TheScore[1] = this.Turns;
- if (this.Turns > this.bestScore) {
- this.TheScore[2] = this.Turns;
- } else {
- this.TheScore[2] = this.bestScore;
- }
-
- this.writeStream(this.TheScore);
- }
- }
-