Kenny_Liu 的个人资料入乡随俗照片日志列表更多 ![]() | 帮助 |
|
2005/7/12 单独存bSound第一步:添加以下两个函数:
void loadSetting() { RecordStore rs=null; try { //打开纪录 bHide=true; rs=RecordStore.openRecordStore(strRec,true); if(rs.getNumRecords() <= 0) { this.saveSetting(); } else { byte data[] = rs.getRecord(1);
if (data == null)return; ByteArrayInputStream baos = new ByteArrayInputStream(data, 0, data.length); DataInputStream dos = new DataInputStream(baos); try { bSound = dos.readBoolean(); nSetID = dos.readByte(); nContextID = dos.readByte(); }
catch (Exception e) {} }
}catch(Exception e)
{ e.printStackTrace(); } return ; }
int nSetID = 1;//记录设置用的序号
int nContextID = -1;//记录内容用的序号 boolean saveSetting() { boolean bOK=false; RecordStore rs=null; //打开纪录 ByteArrayOutputStream baos=new ByteArrayOutputStream(); DataOutputStream dos=new DataOutputStream(baos); try { //写入数据信息 try{ dos.writeBoolean(bSound); dos.write(nSetID); dos.write(nContextID); }catch(Exception e){ dos.close(); } dos.close(); //写入到纪录 byte[] data=baos.toByteArray(); rs=RecordStore.openRecordStore(strRec,true); int a= rs.getNumRecords(); // int b = rs.getSizeAvailable(); // rs.getSizeAvailable(); if(a <= 0)
{ nSetID = rs.addRecord(data, 0, data.length); }
else { rs.setRecord(nSetID, data, 0, data.length); } rs.closeRecordStore(); bOK=true;
}catch(Exception e) { } return bOK;
}
第二步:在Games的构造函数中调用loadSetting,在quitGame()中调用saveSetting();
第三步:把saveGame() { try { ... }catch() {} ... dos.close(); //写入到纪录 byte[] data=baos.toByteArray(); rs=RecordStore.openRecordStore(strRec,true); rs.addRecord(data,0,data.length); rs.closeRecordStore(); }修改为 { try { ... }catch() {} ... dos.close(); //写入到纪录 byte[] data=baos.toByteArray(); rs=RecordStore.openRecordStore(strRec,true); if(nContextID < 0) nContextID = rs.addRecord(data,0,data.length); else rs.setRecord(nContextID, data, 0, data.length); rs.closeRecordStore();
} 第四步:把loadGame()中 { ... for(int i=1;i<rs.getNextRecordID();i++) { //查询所有的纪录 if(rs.getRecordSize(i)<=0) continue; //读取数据 byte data[]=rs.getRecord(i); if(data==null) continue; ByteArrayInputStream baos=new ByteArrayInputStream(data,0,data.length); DataInputStream dos=new DataInputStream(baos); try { ... } }修改为 { ... if(nContextID < 0)return false; byte data[]=rs.getRecord(nContextID); if(data==null) return false; ByteArrayInputStream baos=new ByteArrayInputStream(data,0,data.length); DataInputStream dos=new DataInputStream(baos); try { ... } } 第五步:将原saveGame和loadGame中有关bSound的部分去掉。 曹珺
上海岩浆数码技术有限公司
上海市青海路118号云海苑17层(200041) 电话:021 52280720/1/2/3-203 传真:021 62181045 手机:13817066976 邮箱:cao.jun@magma-digital.com 引用通告此日志的引用通告 URL 是: http://killerliu.spaces.live.com/blog/cns!6EF2055BD4ADB55E!210.trak 引用此项的网络日志
|
|
|