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

📄 gameappbase.java

📁 J2ME游戏引擎,直接在JBUILDER2006下运行,不包含需要的SDK和虚拟机
💻 JAVA
字号:
package GoGoGo;import javax.microedition.midlet.MIDlet;import javax.microedition.lcdui.Form;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.CommandListener;import javax.microedition.lcdui.Display;import javax.microedition.lcdui.Displayable;import javax.microedition.rms.RecordStore;import javax.microedition.rms.RecordStoreException;import java.io.*;/** * <p>Title: GameAppBase</p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * <p>修改记录:</p> * <p><b>Ver 1.0.0  /  Date: 2004-03-30</b><br> * 1.试用次数限制<br> * 增加试用次数限制,在Jad描述中增加DigitalRed-Define-2和DigitalRed-Define-3两项。 * DigitalRed-Define-2标明试用次数,大于零时有效,否则表示无试用次数限制。 * DigitalRed-Define-3的内容为试用次数用完后,显示给用户的提示信息<br> * </p> * @author not attributable * @version 1.0.0 */public class GameAppBase extends MIDlet implements CommandListener{    public GameViewBase m_GameViewBase; //View of Game    private short EVALUATE_TIME_LIMIT = 0;    private String STR_EVALUATE_UP = null;    private short m_i_EvaluateTimeLeft = 0;    public GameAppBase()    {    }    protected void pauseApp()    {    }    protected void startApp() throws javax.microedition.midlet.MIDletStateChangeException    {        //Init the diplay component and set the first view        Displayable current = Display.getDisplay(this).getCurrent();        if (current == null)        {            // 获取游戏的试用次数限制            try            {                EVALUATE_TIME_LIMIT = Short.parseShort(this.getAppProperty("DigitalRed-Define-2"));            }            catch (Exception e)            {                EVALUATE_TIME_LIMIT = 0;            }            // 如果有试用次数限制,判断用户是否已经用完试用次数            if(EVALUATE_TIME_LIMIT > 0)            {                m_i_EvaluateTimeLeft = ReadEvaluateTimeLeft();                // 试用次数已经用完                if(m_i_EvaluateTimeLeft == 0)                {                    try                    {                        STR_EVALUATE_UP = this.getAppProperty("DigitalRed-Define-3");                    }                    catch (Exception e)                    {                        STR_EVALUATE_UP = null;                    }                    if (STR_EVALUATE_UP == null)                    {                        STR_EVALUATE_UP = "Time out";                    }                    Form alert = new Form(null);//(null, STR_EVALUATE_UP, null, AlertType.WARNING);                    alert.append(STR_EVALUATE_UP);                    Command cmd = new Command("Exit", Command.EXIT, 1);                    alert.addCommand(cmd);                    alert.setCommandListener(this);                    Display.getDisplay(this).setCurrent(alert);                    return;                }                else                {                    m_i_EvaluateTimeLeft --;                    WriteEvaluateTimeLeft(m_i_EvaluateTimeLeft);                }            }            // 如果用户试用次数未用完,或无试用次数限制            m_GameViewBase = new GameViewBase(this);            Display.getDisplay(this).setCurrent(m_GameViewBase);            m_GameViewBase.StartFlip();        }        else        {            Display.getDisplay(this).setCurrent(current);        }    }    public void commandAction(Command c, Displayable d)    {        notifyDestroyed();    }    protected void destroyApp(boolean parm1) throws javax.microedition.midlet.        MIDletStateChangeException    {        m_GameViewBase = null;    }    private final String EVARMS = "DIGIRED_EVA_LIMIT1";    private short ReadEvaluateTimeLeft()    {        RecordStore rs ;        byte[] record ;        short iEvaluateTime = 0;        try        {            rs = RecordStore.openRecordStore(EVARMS, false) ;            if ( rs.getNumRecords() == 0 )            {                WriteEvaluateTimeLeft(EVALUATE_TIME_LIMIT);                return EVALUATE_TIME_LIMIT;            }            record = rs.getRecord(1) ;            rs.closeRecordStore();        }        catch (RecordStoreException rse)        {            WriteEvaluateTimeLeft(EVALUATE_TIME_LIMIT);            return EVALUATE_TIME_LIMIT;        }        ByteArrayInputStream bais = new ByteArrayInputStream(record);        DataInputStream is = new DataInputStream(bais) ;        try        {            iEvaluateTime = is.readShort();        }        catch (IOException e)        {            WriteEvaluateTimeLeft(EVALUATE_TIME_LIMIT);            return EVALUATE_TIME_LIMIT;        }        rs            = null;        record        = null;        bais          = null ;        is            = null ;        return iEvaluateTime;    }    private void WriteEvaluateTimeLeft(short iTimeLeft)    {        ByteArrayOutputStream baos = new ByteArrayOutputStream() ;        DataOutputStream os = new DataOutputStream(baos) ;        try        {            os.writeShort(iTimeLeft);        }        catch (IOException e)        {            return;        }        byte[] record = baos.toByteArray() ;        RecordStore rs ;        try        {            RecordStore.deleteRecordStore(EVARMS) ;        }        catch (RecordStoreException ignore)        {        }        try        {            rs = RecordStore.openRecordStore(EVARMS, true) ;            rs.addRecord(record, 0, record.length);            rs.closeRecordStore();        }        catch (RecordStoreException rse)        {            return;        }        rs = null;        record = null;        baos = null ;        os   = null ;    }}

⌨️ 快捷键说明

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