?? tablebones.java
字號:
import java.util.Random;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class TableBones {
private int m_aAllWord[]; //所有牌的類型
private int m_aAllValue[]; //所有牌的面值
private Bone m_aBone[]; //總共使用的牌
private Bone m_aTableBone[]; //桌面上的牌
private int m_nRemainBones; //尚未翻開的牌的數量
private int m_nTableBones; //桌面上牌的數量
private Random m_Random;
public TableBones(){
try{
Image imgBase = Image.createImage("/demo/base.png");
Image imgWord = Image.createImage("/demo/word.png");
int total = 14 * 3 + 26 + 1;
m_aBone = new Bone[total];
for( int n = 0; n < total; n ++ ){
m_aBone[n] = new Bone(imgWord, imgBase);
}
m_aTableBone = new Bone[total];
total = 136;//9*4*3+7*4;
m_aAllWord = new int[total];
m_aAllValue = new int[total];
for( int n = 0; n < total; n ++ ){
int word = n / 36;
int value = n % 9;
if( word >= 3 )
value = n % 7;
m_aAllWord[n] = word;
m_aAllValue[n] = value;
}
m_Random = new Random();
}
catch(Exception exception){}
}
public void Reset(){
//進行70次洗牌
int times = 70;
for( int n = 0; n < times; n ++ ){
int i = m_Random.nextInt() % m_aAllWord.length;
i = Math.abs(i);
int j = m_Random.nextInt() % m_aAllWord.length;
j = Math.abs(j);
int temp = m_aAllWord[i];
m_aAllWord[i] = m_aAllWord[j];
m_aAllWord[j] = temp;
temp = m_aAllValue[i];
m_aAllValue[i] = m_aAllValue[j];
m_aAllValue[j] = temp;
}
//取前面的牌做為使用的牌
for( int n = 0; n < m_aBone.length; n ++ ){
m_aBone[n].setState(Bone.BASE_FALL_B);
m_aBone[n].setType(m_aAllWord[n], m_aAllValue[n]);
}
m_nRemainBones = m_aBone.length;
m_nTableBones = 0;
}
//翻開一張牌
public Bone getBone(){
if( m_nRemainBones <= 0 )
return null;
m_nRemainBones --;
return m_aBone[m_nRemainBones];
}
//將牌打倒桌面上
public void AddTableBone( Bone bone ){
if( bone == null ){
System.out.print("AddTableBone");
}
if( m_nTableBones >= m_aTableBone.length ){
System.out.print("AddTableBone");
}
if( m_nTableBones < 0 ){
System.out.print("AddTableBone");
}
m_aTableBone[m_nTableBones] = bone;
m_nTableBones ++;
}
//獲取桌面上最后一張牌
public Bone getLastTableBone(){
if( m_nTableBones >= m_aTableBone.length ){
System.out.print("getLastTableBone");
}
if( m_nTableBones <= 0 )
return null;
return m_aTableBone[m_nTableBones-1];
}
//顯示扣著的牌和桌面上的牌
public void Paint(Graphics g, int scrWidth, int scrHeight){
int x = scrWidth - 13;
int y = 50;
int n = m_nRemainBones - 1;
while( n >= 0 ){
m_aBone[n].setRefPixelPosition(x, y);
m_aBone[n].Paint(g);
n --;
if( n < 0 )
break;
m_aBone[n].setRefPixelPosition(x, y - 5);
m_aBone[n].Paint(g);
x = x - 13;
if( x <= 13 ){
x = scrWidth - 12;
y = y + 18;
}
n --;
}
x = 13;
y = 90;
for( n = 0; n < m_nTableBones; n ++ ){
m_aTableBone[n].setRefPixelPosition(x, y);
m_aTableBone[n].setState(Bone.BASE_FALL_F);
m_aTableBone[n].Paint(g);
x = x + 13;
if( x >= scrWidth - 13 ){
x = 13;
y = y + 18;
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -