📄 savegame.java
字号:
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
class SaveGame
{
static RecordStore myGame;
static boolean gameHaveBeenInit = false;
static String gameData;
private static void initialize()
{
ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
DataOutputStream localDataOutputStream = new DataOutputStream(localByteArrayOutputStream);
try
{
byte[] arrayOfByte;
try
{
localDataOutputStream.writeUTF("A@0/B*0~C^0(D)0!E#0%F&0");
arrayOfByte = localByteArrayOutputStream.toByteArray();
localDataOutputStream.close();
}
catch (IOException localIOException)
{
System.out.println(localIOException);
throw new RecordStoreException();
}
myGame.addRecord(arrayOfByte, 0, arrayOfByte.length);
}
catch (RecordStoreException localRecordStoreException)
{
close();
System.out.println(localRecordStoreException);
}
}
static void open()
{
try
{
myGame = RecordStore.openRecordStore("topscore", true);
if (gameHaveBeenInit)
return;
if (myGame.getNumRecords() == 0)
{
initialize();
}
else
{
byte[] arrayOfByte = myGame.getRecord(1);
if (arrayOfByte != null)
try
{
ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream(arrayOfByte);
DataInputStream localDataInputStream = new DataInputStream(localByteArrayInputStream);
gameData = localDataInputStream.readUTF();
localDataInputStream.close();
if (gameData.equals(""))
{
gameData = "A@0/B*0~C^0(D)0!E#0%F&0";
saveGame(gameData);
}
}
catch (IOException localIOException)
{
}
}
gameHaveBeenInit = true;
}
catch (RecordStoreException localRecordStoreException)
{
System.out.println(localRecordStoreException);
}
}
static void close()
{
if (myGame != null)
{
try
{
myGame.closeRecordStore();
}
catch (RecordStoreException localRecordStoreException)
{
}
myGame = null;
}
}
static void saveGame(String paramString)
{
ByteArrayOutputStream localByteArrayOutputStream;
byte[] arrayOfByte;
try
{
try
{
localByteArrayOutputStream = new ByteArrayOutputStream();
DataOutputStream localDataOutputStream = new DataOutputStream(localByteArrayOutputStream);
localDataOutputStream.writeUTF(paramString);
arrayOfByte = localByteArrayOutputStream.toByteArray();
localDataOutputStream.close();
}
catch (IOException localIOException)
{
throw new RecordStoreException();
}
if (myGame == null)
{
open();
myGame.setRecord(1, arrayOfByte, 0, arrayOfByte.length);
close();
}
else
{
myGame.setRecord(1, arrayOfByte, 0, arrayOfByte.length);
}
}
catch (RecordStoreException localRecordStoreException)
{
}
gameData = paramString;
}
static String getGameData()
{
if (!(gameHaveBeenInit))
{
open();
close();
}
return gameData;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -