?? groundforce.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 + -