您的位置:首页 > 编程语言

J2ME 拼图游戏 快速开发 全过程 之代码祥解(3 )——拼图的方格类、个人信息类、选择背景拼图的列表类

2012-04-14 14:01 369 查看
拼图的方格类,代码:

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;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐