home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 64 / CDPRO64.iso / JUEGOS / java / airforcex / airforcex.jar / AirForceX.class (.txt) < prev    next >
Encoding:
Java Class File  |  2003-07-29  |  6.2 KB  |  236 lines

  1. import java.io.ByteArrayInputStream;
  2. import java.io.ByteArrayOutputStream;
  3. import java.io.DataInputStream;
  4. import java.io.DataOutputStream;
  5. import javax.microedition.lcdui.Alert;
  6. import javax.microedition.lcdui.AlertType;
  7. import javax.microedition.lcdui.Command;
  8. import javax.microedition.lcdui.CommandListener;
  9. import javax.microedition.lcdui.Display;
  10. import javax.microedition.lcdui.Displayable;
  11. import javax.microedition.lcdui.Form;
  12. import javax.microedition.lcdui.Image;
  13. import javax.microedition.lcdui.ImageItem;
  14. import javax.microedition.midlet.MIDlet;
  15. import javax.microedition.rms.RecordStore;
  16.  
  17. public class AirForceX extends MIDlet implements CommandListener {
  18.    private Display display = Display.getDisplay(this);
  19.    private Form fmMain = new Form("AirForceX ");
  20.    private Command cmExit = new Command("Exit", 7, 1);
  21.    private Command cmStart = new Command("Start", 1, 1);
  22.    private Command cmBack;
  23.    private AFAnimationCanvas canvas = new AFAnimationCanvas(this);
  24.    private RecordStore AF_rs = null;
  25.    static final String REC_STORE = "AirForceXScores";
  26.    private int[] scoreArray;
  27.    private int[] TheScore;
  28.    private int bestScore;
  29.    private int lastScore;
  30.    private int presentScore;
  31.    private int Turns;
  32.    private Alert alAlert;
  33.    private boolean storeExits = true;
  34.    int gameCounter = 0;
  35.    // $FF: renamed from: im javax.microedition.lcdui.Image
  36.    Image field_0 = null;
  37.  
  38.    public AirForceX() {
  39.       try {
  40.          this.field_0 = Image.createImage("/smallLogo2.png");
  41.          this.fmMain.append(new ImageItem((String)null, this.field_0, 3, (String)null));
  42.       } catch (Exception var2) {
  43.          System.out.println("error with image load: " + var2);
  44.       }
  45.  
  46.       this.fmMain.append("\nAir ForceX.\nCopyright JAR Developments 2003.\n**Instructions**\n4-Left\n6-Right\n2-Up\n8-Down\n5-Fire\n");
  47.       this.fmMain.addCommand(this.cmStart);
  48.       this.fmMain.addCommand(this.cmExit);
  49.       this.fmMain.setCommandListener(this);
  50.       this.scoreArray = new int[3];
  51.       this.TheScore = new int[3];
  52.    }
  53.  
  54.    public void startApp() {
  55.       this.display.setCurrent(this.fmMain);
  56.    }
  57.  
  58.    public void CloseApp() {
  59.       this.display.setCurrent(this.fmMain);
  60.    }
  61.  
  62.    public void pauseApp() {
  63.    }
  64.  
  65.    public void destroyApp(boolean var1) {
  66.    }
  67.  
  68.    public void commandAction(Command var1, Displayable var2) {
  69.       if (var1 == this.cmExit) {
  70.          this.destroyApp(false);
  71.          ((MIDlet)this).notifyDestroyed();
  72.       } else if (var1 == this.cmStart) {
  73.          this.display.setCurrent(this.canvas);
  74.          this.canvas.repaint();
  75.          this.openRecStore();
  76.          if (this.storeExits) {
  77.             this.closeRecStore();
  78.          } else {
  79.             for(int var3 = 0; var3 < 3; ++var3) {
  80.                this.TheScore[var3] = 1;
  81.             }
  82.  
  83.             this.openRecStoreCreate();
  84.             this.writeFirstData(this.TheScore);
  85.             this.closeRecStore();
  86.          }
  87.  
  88.          if (this.gameCounter == 0) {
  89.             this.fmMain.delete(1);
  90.             this.fmMain.delete(0);
  91.             this.fmMain.append("www.phonegames4u.com presents Air ForceX. Copyright JAR Developments 2003");
  92.             this.field_0 = null;
  93.          }
  94.  
  95.          ++this.gameCounter;
  96.          if (this.gameCounter > 1) {
  97.             this.canvas.reStartSA();
  98.             this.canvas.showNotify();
  99.          }
  100.       }
  101.  
  102.    }
  103.  
  104.    public void displayScore() {
  105.       this.alAlert = new Alert("Score", "\nScore:\n" + this.Turns + "\nLast Score:\n" + this.lastScore + "\nBest Score\n" + this.TheScore[2], (Image)null, (AlertType)null);
  106.       this.alAlert.setTimeout(-2);
  107.       this.display.setCurrent(this.alAlert, this.fmMain);
  108.    }
  109.  
  110.    public void openRecStoreCreate() {
  111.       try {
  112.          this.AF_rs = RecordStore.openRecordStore("AirForceXScores", true);
  113.          this.storeExits = true;
  114.       } catch (Exception var2) {
  115.          this.storeExits = false;
  116.          System.out.println(" there is an error in openRecStoreCreate:  " + var2);
  117.       }
  118.  
  119.    }
  120.  
  121.    public void writeFirstData(int[] var1) {
  122.       try {
  123.          ByteArrayOutputStream var2 = new ByteArrayOutputStream();
  124.          DataOutputStream var3 = new DataOutputStream(var2);
  125.          boolean var5 = true;
  126.  
  127.          for(int var6 = 0; var6 < var1.length; ++var6) {
  128.             var3.writeInt(var1[var6]);
  129.             var3.flush();
  130.             byte[] var4 = var2.toByteArray();
  131.             this.AF_rs.addRecord(var4, 0, var4.length);
  132.             var2.reset();
  133.          }
  134.  
  135.          var2.close();
  136.          var3.close();
  137.       } catch (Exception var7) {
  138.          System.out.println(" there is an error in write streams1:  " + var7);
  139.       }
  140.  
  141.    }
  142.  
  143.    public void RRScore(int var1) {
  144.       this.Turns = var1;
  145.    }
  146.  
  147.    public void RMSScore() {
  148.       this.openRecStore();
  149.       this.readSream();
  150.       this.calculateScore();
  151.       this.writeScores();
  152.       this.closeRecStore();
  153.       this.displayScore();
  154.    }
  155.  
  156.    public void openRecStore() {
  157.       try {
  158.          this.AF_rs = RecordStore.openRecordStore("AirForceXScores", false);
  159.       } catch (Exception var2) {
  160.          this.storeExits = false;
  161.       }
  162.  
  163.    }
  164.  
  165.    public void closeRecStore() {
  166.       try {
  167.          this.AF_rs.closeRecordStore();
  168.       } catch (Exception var2) {
  169.          System.out.println(" there is an error closing  the RMS:  " + var2);
  170.       }
  171.  
  172.    }
  173.  
  174.    public void writeScores() {
  175.       this.TheScore[0] = this.Turns;
  176.    }
  177.  
  178.    public void writeStream(int[] var1) {
  179.       try {
  180.          ByteArrayOutputStream var2 = new ByteArrayOutputStream();
  181.          DataOutputStream var3 = new DataOutputStream(var2);
  182.          boolean var5 = true;
  183.  
  184.          for(int var6 = 0; var6 < var1.length; ++var6) {
  185.             var3.writeInt(var1[var6]);
  186.             var3.flush();
  187.             byte[] var4 = var2.toByteArray();
  188.             this.AF_rs.setRecord(var6 + 1, var4, 0, var4.length);
  189.             var2.reset();
  190.          }
  191.  
  192.          var2.close();
  193.          var3.close();
  194.       } catch (Exception var7) {
  195.          System.out.println(" there is an error in write streams:  " + var7);
  196.       }
  197.  
  198.    }
  199.  
  200.    public void readSream() {
  201.       try {
  202.          byte[] var1 = new byte[50];
  203.          ByteArrayInputStream var2 = new ByteArrayInputStream(var1);
  204.          DataInputStream var3 = new DataInputStream(var2);
  205.  
  206.          for(int var4 = 1; var4 <= this.AF_rs.getNumRecords(); ++var4) {
  207.             this.AF_rs.getRecord(var4, var1, 0);
  208.             this.scoreArray[var4 - 1] = var3.readInt();
  209.             var2.reset();
  210.          }
  211.  
  212.          this.presentScore = this.scoreArray[0];
  213.          this.lastScore = this.scoreArray[1];
  214.          this.bestScore = this.scoreArray[2];
  215.          var2.close();
  216.          var3.close();
  217.       } catch (Exception var5) {
  218.          System.out.println(" there is an error in read streams1:  " + var5);
  219.       }
  220.  
  221.    }
  222.  
  223.    public void calculateScore() {
  224.       this.presentScore = this.Turns;
  225.       this.TheScore[0] = this.Turns;
  226.       this.TheScore[1] = this.Turns;
  227.       if (this.Turns > this.bestScore) {
  228.          this.TheScore[2] = this.Turns;
  229.       } else {
  230.          this.TheScore[2] = this.bestScore;
  231.       }
  232.  
  233.       this.writeStream(this.TheScore);
  234.    }
  235. }
  236.