⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tablebones.java

📁 移动平台游戏开发
💻 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 + -