⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 groundforce.java

📁 坦克大战
💻 JAVA
字号:
/*    北方交通大学16204宿舍专用Java反编译器 Java204 版本:0.2    *//*            <<<使用前务必请仔细阅读随附警告信息>>>            */// Copyright RainForest 2001.  All rights reserved.import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.rms.RecordStore;

public class GroundForce extends MIDlet
     implements CommandListener
{// 类成员变量定义域开始

     private Display display;
     private Form fmMain;
     private Command cmExit;
     private Command cmStart;
     private Command cmBack;
     private GFAnimationCanvas canvas;
     private RecordStore GF_rs;
     static final String REC_STORE = "GroundForceScores";
     private int scoreArray[];
     private int TheScore[];
     private int bestScore;
     private int lastScore;
     private int presentScore;
     private int Turns;
     private Alert alAlert;
     private boolean storeExits;
     int gameCounter;
     Image im;
// 类成员变量定义域结束      < 初始化过程祥见构造方法 >

     public GroundForce()  // 构造方法 (如有必要,请手工调整该方法)
     {
          GF_rs = null;
          storeExits = true;
          gameCounter = 0;
          im = null;
          display = Display.getDisplay(this);
          canvas = new GFAnimationCanvas(this);
          fmMain = new Form("Ground Force ");
          cmStart = new Command("Start", 1, 1);
          cmExit = new Command("Exit", 7, 1);
          try
          {
               im = Image.createImage("/smallLogo2.png");
               fmMain.append(new ImageItem(null, im, 3, null));
          }//构造方法结束 
          catch(Exception exception)
          {
               System.out.println("error with image load: " + exception);
          }
          fmMain.append("\nGround Force.\nCopyright JAR Developments 2003.\n**Instructions**\n4-Left\n6-Right\n2-Up\n8-Down\n5-Fire\n");
          fmMain.addCommand(cmStart);
          fmMain.addCommand(cmExit);
          fmMain.setCommandListener(this);
          scoreArray = new int[3];
          TheScore = new int[3];
     }// GroundForce 结束

     public void startApp()
     {
          display.setCurrent(fmMain);
     }

     public void CloseApp()
     {
          display.setCurrent(fmMain);
     }

     public void pauseApp()
     {
     }

     public void destroyApp(boolean flag)
     {
     }

     public void commandAction(Command command, Displayable displayable)
     {
          if(command == cmExit)
          {
               destroyApp(false);
               notifyDestroyed();
          }
          else
          if(command == cmStart)
          {
               display.setCurrent(canvas);
               canvas.repaint();
               openRecStore();
               if(!storeExits)
               {
                    for(int i = 0; i < 3; i++)
                         TheScore[i] = 1;

                    openRecStoreCreate();
                    writeFirstData(TheScore);
                    closeRecStore();
               }
               else
               {
                    closeRecStore();
               }
               if(gameCounter == 0)
               {
                    fmMain.delete(1);
                    fmMain.delete(0);
                    fmMain.append("www.phonegames4u.com presents Ground Force. Copyright JAR Developments 2003");
                    im = null;
               }
               gameCounter = gameCounter + 1;
               if(gameCounter > 1)
               {
                    canvas.reStartSA();
                    canvas.showNotify();
               }
          }// if 结束
     }//  commandAction 结束

     public void displayScore()
     {
          alAlert = new Alert("Score", "\nScore:\n" + Turns + "\nLast Score:\n" + lastScore + "\nBest Score\n" + TheScore[2], null, null);
          alAlert.setTimeout(-2);
          display.setCurrent(alAlert, fmMain);
     }

     public void openRecStoreCreate()
     {
          try
          {
               GF_rs = RecordStore.openRecordStore("GroundForceScores", true);
               storeExits = true;
          }
          catch(Exception exception)
          {
               storeExits = false;
               System.out.println(" there is an error in openRecStoreCreate:  " + exception);
          }
     }

     public void writeFirstData(int ai[])
     {
          try
          {
               ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
               DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
               boolean flag = true;
               for(int i = 0; i < ai.length; i++)
               {
                    dataoutputstream.writeInt(ai[i]);
                    dataoutputstream.flush();
                    byte abyte0[] = bytearrayoutputstream.toByteArray();
                    GF_rs.addRecord(abyte0, 0, abyte0.length);
                    bytearrayoutputstream.reset();
               }

               bytearrayoutputstream.close();
               dataoutputstream.close();
          }
          catch(Exception exception)
          {
               System.out.println(" there is an error in write streams1:  " + exception);
          }
     }//  writeFirstData 结束

     public void RRScore(int i)
     {
          Turns = i;
     }

     public void RMSScore()
     {
          openRecStore();
          readSream();
          calculateScore();
          writeScores();
          closeRecStore();
          displayScore();
     }

     public void openRecStore()
     {
          try
          {
               GF_rs = RecordStore.openRecordStore("GroundForceScores", false);
          }
          catch(Exception exception)
          {
               storeExits = false;
          }
     }

     public void closeRecStore()
     {
          try
          {
               GF_rs.closeRecordStore();
          }
          catch(Exception exception)
          {
               System.out.println(" there is an error closing  the RMS:  " + exception);
          }
     }

     public void writeScores()
     {
          TheScore[0] = Turns;
     }

     public void writeStream(int ai[])
     {
          try
          {
               ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
               DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
               boolean flag = true;
               for(int i = 0; i < ai.length; i++)
               {
                    dataoutputstream.writeInt(ai[i]);
                    dataoutputstream.flush();
                    byte abyte0[] = bytearrayoutputstream.toByteArray();
                    GF_rs.setRecord(i + 1, abyte0, 0, abyte0.length);
                    bytearrayoutputstream.reset();
               }

               bytearrayoutputstream.close();
               dataoutputstream.close();
          }
          catch(Exception exception)
          {
               System.out.println(" there is an error in write streams:  " + exception);
          }
     }//  writeStream 结束

     public void readSream()
     {
          try
          {
               byte abyte0[] = new byte[50];
               ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(abyte0);
               DataInputStream datainputstream = new DataInputStream(bytearrayinputstream);
               for(int i = 1; i <= GF_rs.getNumRecords(); i++)
               {
                    GF_rs.getRecord(i, abyte0, 0);
                    scoreArray[i - 1] = datainputstream.readInt();
                    bytearrayinputstream.reset();
               }

               presentScore = scoreArray[0];
               lastScore = scoreArray[1];
               bestScore = scoreArray[2];
               bytearrayinputstream.close();
               datainputstream.close();
          }
          catch(Exception exception)
          {
               System.out.println(" there is an error in read streams1:  " + exception);
          }
     }//  readSream 结束

     public void calculateScore()
     {
          presentScore = Turns;
          TheScore[0] = Turns;
          TheScore[1] = Turns;
          if(Turns > bestScore)
               TheScore[2] = Turns;
          else
               TheScore[2] = bestScore;
          writeStream(TheScore);
     }  // Java 204 代码风格版本 : 6.0   < 类Fox Lin C++ 风格 >}//  implements CommandListener 结束// 主类结束
/*********提高国人Java水平,从你做起,从我做起,我看不如从Java204做起....*********//*联系我们 :    地址 : 北京市北方交通大学电气99-2班  29号信箱    邮编 : 100044    电话 : 010-63223904 或 13641045686    RFB  : 冯霖    补充 : 我在16204宿舍住 :) *//*谢谢选择RainForest的产品,请多支持我们,我们会把更多更强的BOSS级工具奉献给用户*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -