?? bone.java
字號:
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;
public class Bone {
//定義牌面符號種類值
public static final int WORD_WAN = 0; //萬
public static final int WORD_TONG = 1; //筒
public static final int WORD_TIAO = 2; //條
public static final int WORD_ZI = 3; //字
public static final int WORD_TYPE_NUM = 4; //字的類型總數(shù)
private int m_nWord = WORD_WAN;
//定義牌面面值的值
public static final int VALUE_1 = 0; //1
public static final int VALUE_2 = 1; //2
public static final int VALUE_3 = 2; //3
public static final int VALUE_4 = 3; //4
public static final int VALUE_5 = 4; //5
public static final int VALUE_6 = 5; //6
public static final int VALUE_7 = 6; //7
public static final int VALUE_8 = 7; //8
public static final int VALUE_9 = 8; //9
public static final int VALUE_EAST = 0; //東風
public static final int VALUE_SOUTH = 1; //南風
public static final int VALUE_WEST = 2; //西風
public static final int VALUE_NORTH = 3; //北風
public static final int VALUE_ZHONG = 4; //紅中
public static final int VALUE_FA = 5; //發(fā)財
public static final int VALUE_BAI = 6; //白板
private int m_nValue = VALUE_1;
//定義牌的狀態(tài)值
public static final int BASE_FRONT = 0; //正面朝向屏幕立著
public static final int BASE_BACK = 1; //背面朝向屏幕立著
public static final int BASE_FALL_F = 2; //正面朝上倒著
public static final int BASE_FALL_B = 3; //背面朝上倒著
public static final int BASE_STATE_NUM = 4; //牌底的狀態(tài)總數(shù)
private int m_nBase = BASE_FRONT;
private Sprite m_WordSp; //牌字圖像對象
private Sprite m_BaseSp; //牌底圖像對象
//構(gòu)造方法,參數(shù)wordImg為牌字圖像,參數(shù)baseImage為牌底圖像
public Bone( Image wordImg, Image baseImg ){
try{
m_WordSp = new Sprite(wordImg, 11, 13 );
m_WordSp.defineReferencePixel(5, 6);
m_BaseSp = new Sprite(baseImg, 13, 18 );
m_BaseSp.defineReferencePixel(6, 9);
}
catch(Exception exception){}
}
//設(shè)置牌的位置
public void setRefPixelPosition( int x, int y ){
m_BaseSp.setRefPixelPosition(x, y);
//根據(jù)牌的狀態(tài),設(shè)置文字的位置
switch( m_nBase ){
case BASE_FRONT:
m_WordSp.setRefPixelPosition(x-1, y+1);
break;
case BASE_FALL_F:
m_WordSp.setRefPixelPosition(x, y-1);
break;
}
}
public int getBase(){
return m_nBase;
}
public int getWord(){
return m_nWord;
}
public int getValue(){
return m_nValue;
}
//設(shè)置牌的狀態(tài)
public void setState( int state ){
//檢測base的合法性
if( state < 0 || state >= BASE_STATE_NUM )
return;
m_nBase = state;
int x = m_BaseSp.getRefPixelX();
int y = m_BaseSp.getRefPixelY();
m_BaseSp.setFrame(m_nBase);
//根據(jù)牌的狀態(tài),設(shè)置文字的位置
switch( m_nBase ){
case BASE_FRONT:
m_WordSp.setRefPixelPosition(x, y+1);
break;
case BASE_FALL_F:
m_WordSp.setRefPixelPosition(x, y-1);
break;
}
}
//設(shè)置牌的類型
//參數(shù)base為牌的狀態(tài),word為文字類型,value為面值
public void setType( int word, int value ){
//檢測word,value的合法性
if( word < 0 || word >= WORD_TYPE_NUM )
return;
if( word == WORD_ZI ){
if( value < VALUE_EAST || value > VALUE_BAI )
return;
}
else if( value < VALUE_1 || value > VALUE_9 )
return;
//設(shè)置數(shù)值
m_nWord = word;
m_nValue = value;
m_WordSp.setFrame(m_nWord * 9 + m_nValue);
}
//顯示圖像,參數(shù)g對應(yīng)手機屏幕
public void Paint(Graphics g){
m_BaseSp.paint(g);
switch( m_nBase ){
case BASE_FRONT:
case BASE_FALL_F:
//只有正面朝上或朝前的牌才顯示文字
m_WordSp.paint(g);
break;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -