cardsprite.java

来自「J2ME编程的50个例子,适合掌上系统的编程」· Java 代码 · 共 46 行

JAVA
46
字号
package demo;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;


public class CardSprite extends Sprite{
	public static final int CARD_BLACK	= 0;	//黑桃
	public static final int CARD_RED		= 1;	//红桃
	public static final int CARD_SQUARE	= 2;	//方块
	public static final int CARD_CLUB		= 3;	//梅花
	public static final int CARD_TYPE_NUM	 = 4;	
	private int m_nType = -1;						//牌的种类
	private int m_nValue = -1;						//牌的面值
	
	public CardSprite( Image image, int frameWidth, int frameHeight){
		super(image, frameWidth, frameHeight);		
		defineReferencePixel(frameWidth / 2, frameHeight / 2);
		setVisible(false);
	}

	//根据类型和面值设置纸牌的帧编号
	//参数type是纸牌的类型,value是纸牌的面值
	public void setCard( int type, int value ){
		if( type < 0 || type >= CARD_TYPE_NUM )
			return;
		if( value < 1 || value > 13 )
			return;
		m_nValue = value;
		m_nType = type;
		setFrame( type * 13 + value - 1 );
		setVisible(true);
	}
	//获取牌的种类
	public int getType(){
		return m_nType;
	}
	//获取牌的面值
	public int getValue(){
		return m_nValue;
	}
	//获取纸牌对应的分数
	public int getScore(){
		return m_nValue;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?