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

📄 topscore.java

📁 用J2ME写的手机游戏。“北京浮生记”是您工作学习之余消遣休闲理想的小游戏
💻 JAVA
字号:
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;

public class TopScore
    extends Form
    implements CommandListener {
   Command cmdOK;
   Display display;
   static private RecordStore rsTop = null; //作保存游戏最高分用

   public TopScore(Display display) {
      super("Help");
      this.display = display;
      cmdOK = new Command("OK", Command.OK, 1);
      this.addCommand(cmdOK);
      openRSTopAnyway("TopScore");
      getTop();
      StringItem si = new StringItem("  ", "您最富有的时候曾经有 :" + Base.topScore);
      this.append(si);
      setCommandListener(this);
   }

   public void commandAction(Command command, Displayable displayable) {
      if (Command.OK == command.getCommandType()) {
	 display.setCurrent(new MenuListCanvas(display));
      }

   }

   static public RecordStore openRSTopAnyway(String rsname) {
      //数据仓库的名称大于32个字符就不能够接受
      if (rsname.length() > 32) {
	 return null;
      }
      try {
	 rsTop = RecordStore.openRecordStore(rsname, true);

      }
      catch (Exception e) {
	 //return null;
	 System.out.println("openrsTopFalse " + e);
      }
      return rsTop;
   }

//存储最高分
   static public void saveTop() {
      try{
	 if (rsTop.getNumRecords() == 0) {
	    rsTop.addRecord(RecStore.createByteGroup(Base.topScore), 0,
			    RecStore.createByteGroup(Base.topScore).length);
	 }
	 else if (rsTop.getNumRecords() > 0) {
	    rsTop.setRecord(1, RecStore.createByteGroup(Base.topScore), 0,
			    RecStore.createByteGroup(Base.topScore).length);
	 }
	 rsTop.closeRecordStore();

	 }catch(Exception e) {}



   }

   //取出最高分
   static public void getTop() {
      try{
	 Base.topScore = RecStore.byte2Long(rsTop.getRecord(1));
	 rsTop.closeRecordStore();
      }catch(Exception e){}


   }
}

⌨️ 快捷键说明

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