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

📄 air_gunner.java

📁 j2me的手机游戏
💻 JAVA
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 

import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.rms.RecordStore;

public class Air_Gunner extends MIDlet
    implements CommandListener
{

    private Display display;
    private Form fmMain;
    private Command cmExit;
    private Command cmStart;
    private Command cmBack;
    private AGAnimationCanvas canvas;
    private RecordStore AG_rs;
    static final String REC_STORE = "AirGunnerUserScores";
    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;

    public Air_Gunner()
    {
        AG_rs = null;
        storeExits = true;
        gameCounter = 0;
        display = Display.getDisplay(this);
        canvas = new AGAnimationCanvas(this);
        fmMain = new Form("");
        cmStart = new Command("Start", 1, 1);
        cmExit = new Command("Exit", 7, 1);
        try
        {
            Image image = Image.createImage("/cover_page.png");
            fmMain.append(new ImageItem(null, image, 3, null));
        }
        catch(Exception exception)
        {
            System.out.println("error with image load: " + exception);
        }
        fmMain.append("Using the radar locate and shoot down the enemy spaceships before they destroy you. (Version 1.0) \251 Saranjeet Raj");
        fmMain.addCommand(cmStart);
        fmMain.addCommand(cmExit);
        fmMain.setCommandListener(this);
        scoreArray = new int[3];
        TheScore = new int[3];
    }

    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();
            }
            gameCounter = gameCounter + 1;
            if(gameCounter > 1)
                canvas.reStartAG();
        }
    }

    public void displayScore()
    {
        alAlert = new Alert("Score", "Present Score    " + Turns + " Last Score         " + lastScore + " Best Score         " + TheScore[2], null, null);
        alAlert.setTimeout(-2);
        display.setCurrent(alAlert, fmMain);
    }

    public void openRecStoreCreate()
    {
        try
        {
            AG_rs = RecordStore.openRecordStore("AirGunnerUserScores", true);
        }
        catch(Exception exception)
        {
            storeExits = true;
        }
    }

    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();
                AG_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);
        }
    }

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

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

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

    public void closeRecStore()
    {
        try
        {
            AG_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();
                AG_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);
        }
    }

    public void readSream()
    {
        try
        {
            byte abyte0[] = new byte[50];
            ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(abyte0);
            DataInputStream datainputstream = new DataInputStream(bytearrayinputstream);
            for(int i = 1; i <= AG_rs.getNumRecords(); i++)
            {
                AG_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 streams:  " + exception);
        }
    }

    public void calculateScore()
    {
        presentScore = Turns;
        TheScore[0] = Turns;
        TheScore[1] = Turns;
        if(Turns > bestScore)
            TheScore[2] = Turns;
        else
            TheScore[2] = bestScore;
        writeStream(TheScore);
    }
}

⌨️ 快捷键说明

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