baiseda 发表于 2013-1-30 01:06:25

Android学习笔记(10)-开始做一个数独游戏[中]

继续,今天讨论的是记录文件的读写。因为原来在Brew平台上实现的数独将题库是一个二进制文件,所以在Android就直接拿那个文件来用了。

计划实现两个函数,先是LoadTiList(),加载题库,先装题库文件放在资源里,然后从资源里加载它作为一个DataInputStream即可。代码也没几行,如下:
<div style="">http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifpublicstaticbooleanLoadTiList(MainActivityme)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifDataInputStreamin=null;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.giftry
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifin=newDataInputStream(me.getResources().openRawResource(R.raw.ti));
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifbyte[]bufC4=newbyte[4];
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifbyte[]bufC81=newbyte[81];
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif//总个数
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifin.read(bufC4,0,4);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifintlen=((int)bufC4[3]<<24)+((int)bufC4[2]<<16)+((int)bufC4[1]<<8)+(int)bufC4[0];
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.giffor(inti=0;i<len;i++)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifQuestionti=newQuestion();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif//代码
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifin.read(bufC4,0,4);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifti.code=(long)(((long)bufC4[3]<<24)+((long)bufC4[2]<<16)+((long)bufC4[1]<<8)+(long)bufC4[0]);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif//时间
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifin.read(bufC4,0,4);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifSharedPreferencessp=me.getPreferences(Context.MODE_WORLD_READABLE);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifti.time=sp.getLong(Long.toString(ti.code),0);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif//数据
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifin.read(bufC81,0,81);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.giffor(intj=0;j<81;j++)ti.data=bufC81;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifme.tiList.add(ti);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif}
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifin.close();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif}
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gifcatch(Exceptionex)...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifreturnfalse;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif}
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.giffinally...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.giftry...{in.close();}catch(Exceptione)...{}
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif}
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gifreturntrue;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif}
页: [1]
查看完整版本: Android学习笔记(10)-开始做一个数独游戏[中]