J2ME 拼图游戏 快速开发 全过程 之代码祥解(3 )——拼图的方格类、个人信息类、选择背景拼图的列表类
来源:互联网 发布:淘宝福建拍卖 编辑:程序博客网 时间:2024/04/30 00:59
拼图的方格类,代码:
package cn.edu.xtu.tilepuzzle.model;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class ClassPiece {
Image img;
boolean addString=false;//是否在每个方格上添加图片的原始位置
int cellWidth;//方格的宽
int cellHeight;//方格的高
int serial; // serial number for ordering
//方格的初始化位置
int ix; // initial location in grid coordinates
int iy; // initial location in grid coordinates
//方格的当前位置
public int x; // current location in grid coordinates
public int y; // current location in grid coordinates
ClassPiece(Image img_,int ser, int nx, int ny,int cellWidth,int cellHeight) {
img=img_;
serial = ser;
x = ix = nx;
y = iy = ny;
this.cellHeight=cellHeight;
this.cellWidth=cellWidth;
}
void setImg(Image img_){
img=img_;
}
void setLocation(int nx, int ny) {
this.x = nx;
this.y = ny;
}
// assumes background is white
public void paint(Graphics g) {
int px = y * cellWidth; //行坐标
int py = x * cellHeight; //列坐标
g.drawImage(img, px, py, Graphics.LEFT | Graphics.TOP);
if(addString){
String str=(1+this.ix)+" , "+(1+this.iy);
g.setColor(100, 100, 245);
g.setFont(Font.getDefaultFont());
g.drawString(str, px+(img.getWidth() - Font.getDefaultFont().stringWidth(str)) / 2,py+(img.getHeight()-Font.getDefaultFont().getHeight())/2, Graphics.LEFT | Graphics.TOP);
}
}
boolean isHome() {
return (x == ix) && (y == iy);
}
public void goHome() {
this.x=ix;
this.y=iy;
}
public int getCellWidth() {
return cellWidth;
}
public void setCellWidth(int cellWidth) {
this.cellWidth = cellWidth;
}
public int getCellHeight() {
return cellHeight;
}
public void setCellHeight(int cellHeight) {
this.cellHeight = cellHeight;
}
}
个人信息类,代码:
package cn.edu.xtu.tilepuzzle.model;
import javax.microedition.lcdui.Image;
public class ClassPeopleInfo {
/**
name;flag;time
*/
public String name="";
public String flag="3x4";// 表示 是 3列4行 4x5
public long time=0;
public String strTime="";
public Image showImage;
public Image getShowImage() {
return showImage;
}
public void setShowImage(Image showImage) {
this.showImage = showImage;
}
public ClassPeopleInfo(){
}
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
//System.out.println("设置类型:"+flag);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
//System.out.println("设置名字:"+name);
}
public long getTime() {
return time;
}
public void setTime(long time) {
//System.out.println("设置时间:"+time);
this.time = time;
String space="";
if(time>=1000&&time<10000)space="";
else if(time>=100)space=" ";
else if(time>=10)space=" ";
else {
space=" ";
}
this.strTime=String.valueOf(time)+space+"秒";//BoardModel.getTimeString(time);
}
public String getStrTime() {
return strTime;
}
}
选择背景拼图的列表类,代码:
package cn.edu.xtu.tilepuzzle.model;
import cn.edu.xtu.tilepuzzle.GameDB;
public class ClassListItem {
public String imageDefalut_1 = GameDB.imageDefalut_1Path;
public String imageDefalut_2 = GameDB.imageDefalut_2Path;
/**
* 原图地址
* */
public String photoString="";
public String getPhotoString() {
return photoString;
}
public void setPhotoString(String photoString) {
this.photoString = photoString;
}
/**
* 预览图地址
* */
public String iconString="";
/**
* 默认图片
*/
private String defaultImagePath = "";
/**
* 组
*/
public static int GROUP = 1;
/**
* 记录
*/
public static int ITEM = 0;
/**
* 是否选中
*/
private boolean ifselected = false;
/**
* 显示Label
*/
private String label;
/**
* 类型:组,记录
*/
/**
* 存储的对象
*/
private Object content;
public int indexInItemList=0;
public int getIndexInItemList() {
return indexInItemList;
}
public void setIndexInItemList(int indexInItemList) {
this.indexInItemList = indexInItemList;
}
private int type;
public ClassListItem(Object content,String photoString,String iconString, String Label, int type,boolean isSelect,int indexInItemList) {
this.iconString = iconString;
this.photoString=photoString;
//System.out.println("22222222");
//System.out.println(iconString);
this.label = Label;
this.type = type;
this.content=content;
this.indexInItemList=indexInItemList;
this.setIfselected(isSelect);
}
public void setIconString(String iconString) {
this.iconString=iconString;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public boolean Ifselected() {
return ifselected;
}
public void setIfselected(boolean ifselected) {
this.ifselected = ifselected;
if (this.type == ClassListItem.GROUP) {
if (!ifselected)
this.defaultImagePath = imageDefalut_1;
else
this.defaultImagePath = imageDefalut_2;
}else
System.out.println(iconString);;
}
public String toString() {
return this.label + " ";
}
public String getDefaultImagePath() {
return defaultImagePath;
}
public void setDefaultImagePath(int flag) {
if (flag == 1)
this.defaultImagePath = imageDefalut_1;
else if (flag == 2)
this.defaultImagePath = imageDefalut_2;
else
;
}
public Object getContent() {
return content;
}
public void setContent(Object content) {
this.content = content;
}
}
- J2ME 拼图游戏 快速开发 全过程 之代码祥解(3 )——拼图的方格类、个人信息类、选择背景拼图的列表类
- J2ME 拼图游戏 快速开发 全过程 之代码祥解(5 )——记录集操作类、序列的奇偶性检查类
- J2ME 拼图游戏 快速开发 全过程 之代码祥解(4 )——图片操作类、图片预览后处理类
- J2ME 拼图游戏 快速开发 全过程 之代码祥解(6 )——欢迎界面、游戏结束后的等待界面与增加用户名字界面
- J2ME 拼图游戏 快速开发 全过程 之代码祥解(1 )——程序入口与控制器开发
- J2ME 拼图游戏 快速开发 全过程 之代码祥解(2 )——游戏数据库与游戏模型开发
- J2ME 拼图游戏 快速开发 全过程 (七)——设置图片后的图片预览界面
- 魔力小孩拼图:寓教于乐的简单拼图游戏
- J2ME 拼图游戏 快速开发 全过程 (一)——开发环境及游戏菜单
- J2ME 拼图游戏 快速开发 全过程 (二)——游戏开始界面设计
- J2ME 拼图游戏 快速开发 全过程 (三)——新游戏界面
- J2ME 拼图游戏 快速开发 全过程 (一)——最佳成绩显示界面
- J2ME 拼图游戏 快速开发 全过程 (四)——游戏选项设置界面
- J2ME 拼图游戏 快速开发 全过程 (五)——游戏帮助界面
- J2ME 拼图游戏 快速开发 全过程 (六)——图片设置界面设计
- 拼图小游戏”ST--拼图“开发篇之主要功能的实现(二)
- 拼图小游戏“ST--拼图”开发篇之主要功能的实现(三)
- ios拼图游戏(四)之触摸交换拼图
- 用shell写俄罗斯方块
- x86中的页表结构和页表项格式
- poj2251 - Dungeon Master
- python 如何获取文件夹下所有的目录。
- Linux fork与vfork的区别
- J2ME 拼图游戏 快速开发 全过程 之代码祥解(3 )——拼图的方格类、个人信息类、选择背景拼图的列表类
- C++里,在类中使用指向类成员函数的指针
- C#之I/O系统(三)
- Android游戏源码合集(主要是AndEngine和Libgdx的)
- Android应用开发之使用Socket进行大文件断点上传续传
- struts2 入门
- J2ME 拼图游戏 快速开发 全过程 之代码祥解(4 )——图片操作类、图片预览后处理类
- XML操作类
- poj1426 - Find The Multiple