记录集操作类,代码:
package cn.edu.xtu.tilepuzzle.model;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import javax.microedition.rms.InvalidRecordIDException;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreFullException;
import javax.microedition.rms.RecordStoreNotFoundException;
import javax.microedition.rms.RecordStoreNotOpenException;
import cn.edu.xtu.tilepuzzle.GameDB;
public class RecordStoreOperations {
/*
public static void getRecordStoreInfo(String recordStoreString){
RecordStore rStore = getRecord(recordStoreString);
if(rStore!=null){
try {
System.out.println("这里是getRecordStoreInfo:"+rStore.getNumRecords());
} catch (RecordStoreNotOpenException e1) {
e1.printStackTrace();
}
}
}
public static void getRecordStoreList(String recordStoreString) {
RecordStore rStore = getRecord(recordStoreString);
if(rStore!=null){
int num=0;
try {
num = rStore.getNumRecords();
for(int i=1;i<=num;i++){
try {
System.out.println("这里是getRecordStoreList:"+byteToStr(rStore.getRecord(i)));
} catch (RecordStoreException e) {
e.printStackTrace();
}
}
} catch (RecordStoreNotOpenException e1) {
e1.printStackTrace();
}
}
}
*/
public static boolean deleteRecordStroe(String recordStoreString){
try {
RecordStore.deleteRecordStore(recordStoreString);
System.out.println("成功删除记录集:"+recordStoreString);
return true;
} catch (RecordStoreNotFoundException e) {
System.out.println("没有找到你要删除的记录集。");
} catch (RecordStoreException e) {
System.out.println("删除记录集出错。");
}
return false;
}
public static boolean changeRecordStroe(String recordStoreString,String str,int flag){
RecordStore rStore = getRecord(recordStoreString);
// 创建ByteArrayOutputStream对象
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// 创建与baos关联的DataOutputStream对象
DataOutputStream dos = new DataOutputStream(baos);
// 调用dos的writeUTF()方法将字符串写入dos对象中,自动传递给关联的baos对象,转换成ByteArrayOutputStream对象
try {
dos.writeUTF(str);
// 关闭数据流
dos.close();
} catch (IOException e) {
e.printStackTrace();
}
// 调用baos的toByteArray()方法,将str字符串转换成字节数组类型
byte b[] = baos.toByteArray();
try {
rStore.setRecord(flag, b, 0, b.length);
return true;
} catch (RecordStoreNotOpenException e) {
e.printStackTrace();
} catch (InvalidRecordIDException e) {
e.printStackTrace();
} catch (RecordStoreFullException e) {
e.printStackTrace();
} catch (RecordStoreException e) {
System.out.println("更改记录时出错!!!");
e.printStackTrace();
}finally{
try {
rStore.closeRecordStore();
} catch (RecordStoreNotOpenException e) {
e.printStackTrace();
} catch (RecordStoreException e) {
e.printStackTrace();
}
}
return false;
}
public static ClassPeopleInfo[] ReaderRecordStores(String recordStoreString) {
RecordStore rStore = getRecord(recordStoreString);
if (rStore != null) {
try {
int num = rStore.getNumRecords();
String tempString, str[];
ClassPeopleInfo[] peopleInfo = new ClassPeopleInfo[num];
//System.out.println("人物信息的数量:"+peopleInfo.length);
for (int i = 1; i <= num; i++) {
tempString = byteToStr(rStore.getRecord(i));
// System.out.println("这里是ReaderRecordStores:"+tempString);
str = splitToStr(tempString, ";",3);
//System.out.println("下面进行peopleInfo的设置 :" + i );
peopleInfo[i-1]=new ClassPeopleInfo();
peopleInfo[i-1].setName(str[0]);
peopleInfo[i-1].setFlag(str[1]);
//System.out.println(Long.parseLong(str[2]));
peopleInfo[i-1].setTime(Long.parseLong(str[2]));
//System.out.println("设置 " + i + "完成。");
}
return peopleInfo;
} catch (RecordStoreException e) {
e.printStackTrace();
}
}
return null;
}
public static boolean addStrToRecordStroe(String str,String recordStoreString) {
RecordStore rStore = getRecord(recordStoreString);
// 创建ByteArrayOutputStream对象
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// 创建与baos关联的DataOutputStream对象
DataOutputStream dos = new DataOutputStream(baos);
// 调用dos的writeUTF()方法将字符串写入dos对象中,自动传递给关联的baos对象,转换成ByteArrayOutputStream对象
try {
dos.writeUTF(str);
// 关闭数据流
dos.close();
} catch (IOException e) {
e.printStackTrace();
}
// 调用baos的toByteArray()方法,将str字符串转换成字节数组类型
byte b[] = baos.toByteArray();
// 将已经转换成字节数组类型的数据写入记录存储系统中
try {
//int id=
rStore.addRecord(b, 0, b.length);
//System.out.println("ID:"+id);
//System.out.println(str+":添加成功");
return true;
} catch (RecordStoreNotOpenException e) {
e.printStackTrace();
} catch (RecordStoreFullException e) {
e.printStackTrace();
} catch (RecordStoreException e) {
e.printStackTrace();
}finally{
try {
rStore.closeRecordStore();
} catch (RecordStoreNotOpenException e) {
e.printStackTrace();
} catch (RecordStoreException e) {
e.printStackTrace();
}
}
return false;
}
public static RecordStore getRecord(String recordStoreString) {
try {
return RecordStore.openRecordStore(recordStoreString, true);
} catch (RecordStoreFullException e) {
e.printStackTrace();
} catch (RecordStoreNotFoundException e) {
System.out.println("记录集不存在");
e.printStackTrace();
} catch (RecordStoreException e) {
e.printStackTrace();
}
return null;
}
public static boolean checkIfRecord(String recordStoreString) {
try {
RecordStore.openRecordStore(recordStoreString, false);
System.out.println("记录集正常");
return true;
} catch (RecordStoreFullException e) {
System.out.println("记录集满");
return false;
} catch (RecordStoreNotFoundException e) {
System.out.println("记录集不存在");
return false;
} catch (RecordStoreException e) {
System.out.println("记录集异常");
return false;
}
}
public static String byteToStr(byte[] b) {
String tempString = "";
// 建立与记录内容数组关联的ByteArrayInputStream对象 bs
ByteArrayInputStream bis = new ByteArrayInputStream(b);
// 建立与bs关联的DataInputStream对象ds
DataInputStream dis = new DataInputStream(bis);
// 将读取的记录内容转换成UTF字符串
try {
tempString = dis.readUTF();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return tempString;
}
private static String[] splitToStr(String original, String regex,int num) {
String s = original;
//System.out.println("这里是进入splitToPeopleInfo:"+s);
String[] str = new String[num];
int i = 0;
while (s.indexOf(regex) != -1 && i<num) {
str[i] = s.substring(0, s.indexOf(regex));
//System.out.println("分割中-前面:"+str[i]);
i++;
s = s.substring(s.indexOf(regex) + regex.length());
//System.out.println("分割中-剩下:"+s);
}
//System.out.println(i+","+s);
str[i]=s;
//System.out.println("这里是离开splitToPeopleInfo:"+original);
return str;
}
/*
* str[0]:orgImageString 图片路径默认
* str[1]:反向
boolean true 反向 false
* str[2]:趣味洗牌
boolean true 是 false
* str[3]:标记方格
boolean true 标记 true
* str[4]:困难/简单boolean true 困难
true
* */
public static String[] getGameSetData(String recordStoreGameSetData){
System.out.println("开始获取游戏数据。。。。。。");
//System.out.println("=1 :"+recordStoreGameSetData);
RecordStore rStore = getRecord(recordStoreGameSetData);
if (rStore != null) {
try {
//int num = rStore.getNumRecords();
//System.out.println("共有记录数:"+num);
String tempString="", str[];
//System.out.println("人物信息的数量:"+peopleInfo.length);
tempString = byteToStr(rStore.getRecord(GameDB.GameSetDataFlag));
//for (int i = 1; i <= num; i++)tempString = byteToStr(rStore.getRecord(i));
//System.out.println("记录内容:"+tempString);
str = splitToStr(tempString, ";",GameDB.GameSetDataNum);///***
//System.out.println("=2"+tempString);
return str;
} catch (RecordStoreException e) {
e.printStackTrace();
}
System.out.println("获取游戏数据成功");
}else {
System.out.println("记录为空!!!!");
}
return null;
}
}
序列的奇偶性检查类类,代码:
/*
* SerialCheck.java
*
* Created on 2012年3月21日, 下午6:32
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package cn.edu.xtu.tilepuzzle.model;
/**
*
* @author Administrator
*/
public class SerialCheck {
public static boolean isEven(ClassPiece all[]){
int len=all.length;
//System.out.println(len);
int sum=0;
for(int i=0;i<len-1;i++){
for(int j=i+1;j<len;j++){
//System.out.println(all[i].serial+","+all[j].serial);
if(all[i].serial>all[j].serial){
sum++;
// System.out.println(all[i].serial+","+all[j].serial);
}
}
}
if(sum%2==0){
return true;
}
else{
return false;
}
}
/*
public static boolean isEven2(int all[]){
int len=all.length;
int sum=0;
for(int i=0;i<all.length;i++){
for(int j=i+1;j<all.length;j++){
if(all[i]>all[j])
sum++;
}
}
if(sum%2==0)
return true;
else
return false;
}
*/
}
分享到:
相关推荐
本游戏实现了拼图游戏的基本功能,另外有计时,计步,暂停,重新开始,RMS持久存储,支持图像的动态切分。。。。。
J2ME 拼图游戏源码 J2ME 拼图游戏源码 J2ME 拼图游戏源码
java毕业设计——java基于J2ME的手机游戏开发设计与实现(论文+源代码).zip java毕业设计——java基于J2ME的手机游戏开发设计与实现(论文+源代码).zip java毕业设计——java基于J2ME的手机游戏开发设计与实现(论文+源...
j2me Picpuzzle 拼图游戏 可选择自己喜欢的背景图片 操作简单
J2ME游戏开发 J2ME游戏开发 J2ME游戏开发
J2ME开发 J2ME开发 J2ME开发 J2ME开发
实现了J2me拼图小游戏,可以选择图片,难度,分别有3x3,4x4,5x5,游戏中进行了计时,计步数。根据时间,步数进行评分,给出最后得分并根据不同等级显示不同的图片
j2me拼图游戏+游戏动画.。
JAVA基于J2ME的手机游戏开发(论文+源代码)JAVA基于J2ME的手机游戏开发(论文+源代码)JAVA基于J2ME的手机游戏开发(论文+源代码)JAVA基于J2ME的手机游戏开发(论文+源代码)JAVA基于J2ME的手机游戏开发(论文+源代码)JAVA...
j2ME游戏开发详解j2ME游戏开发详解j2ME游戏开发详解j2ME游戏开发详解j2ME游戏开发详解j2ME游戏开发详解j2ME游戏开发详解j2ME游戏开发详解j2ME游戏开发详解
JAVA基于J2ME的手机游戏开发(LW+源代码)JAVA基于J2ME的手机游戏开发(LW+源代码)JAVA基于J2ME的手机游戏开发(LW+源代码)JAVA基于J2ME的手机游戏开发(LW+源代码)JAVA基于J2ME的手机游戏开发(LW+源代码)JAVA基于J2ME的...
JAVA基于J2ME的手机游戏开发(论文+源代码) JAVA基于J2ME的手机游戏开发(论文+源代码) JAVA基于J2ME的手机游戏开发(论文+源代码) JAVA基于J2ME的手机游戏开发(论文+源代码) JAVA基于J2ME的手机游戏开发(论文+源代码) ...
j2me游戏开发j2me游戏开发j2me游戏开发j2me游戏开发j2me游戏开发j2me游戏开发j2me游戏开发
JAVA基于J2ME的手机游戏开发(lw+源代码).rarJAVA基于J2ME的手机游戏开发(lw+源代码).rarJAVA基于J2ME的手机游戏开发(lw+源代码).rarJAVA基于J2ME的手机游戏开发(lw+源代码).rarJAVA基于J2ME的手机游戏开发(lw+源代码...
JAVA基于J2ME的手机游戏开发(Word论文+源代码) JAVA基于J2ME的手机游戏开发(Word论文+源代码) JAVA基于J2ME的手机游戏开发(Word论文+源代码) JAVA基于J2ME的手机游戏开发(Word论文+源代码) JAVA基于J2ME的手机游戏...
分享:J2ME游戏代码 分享:J2ME游戏代码 分享:J2ME游戏代码分享:J2ME游戏代码 分享:J2ME游戏代码 分享:J2ME游戏代码分享:J2ME游戏代码 分享:J2ME游戏代码 分享:J2ME游戏代码分享:J2ME游戏代码 分享:J2ME...
j2me手机游戏开发j2me手机游戏开发技术详解
j2me 开发教程全集 提供一些常用的初级代码 注意事项
Java写的j2me拼图游戏源码,代码中的注释非常多,学习来说比较有用,两种方法编辑本拼图游戏源代码: 用eclipse打开:在eclipse左侧包资源管理器中右键选择导入,然后选择现有项目到工作空间中,点下一步,在选择...