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

📄 gamedata.java

📁 j2me
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package mole.Rusfk;

import java.util.Random;

import mole.gmapi.MoleActor;

//玩家游戏逻辑类
public class GameData implements CFINALS
{
		private Random		m_randplay;	//随机数生成器
		
		private GameHigh 	m_gamehigh=null;
		public  MoleActor 	m_actorinfo;								//玩家数据库游戏信息
		
		public  MyCell 		m_cell[] = new MyCell[MAXSTYLE];	    	//单元的各种变形的信息
		public  byte 		bin1[][] = new byte[MAXCENG+2][MAXROWS+2];	//单元相对坐标信息(静态-已落地单元)
		public 	byte		del[]=new byte[7];							//消失的单元 
		
		public 	int  		m_alllines=0;								//当前收的总行数
		public  int 		m_nowscore=0; 								//当前局分
		public  byte    	m_lines=0;									//当前收的行数(各行索引号保存到lineindex中)
		private byte    	m_maxy=0;									//当前单元最高点
		private byte    	m_style=0;									//(由GameHigh随机产生的典型类型绝对索引号),配合boxindex获取典型单元索引,然后在m_cell找到典型单元信息
		public  byte		m_level=0;									//等级
		public  byte 		m_team=0;									//队伍号
		public  byte		m_chair=-1;									//凳子
		public  byte		Playerplace=-1;								//名次
		public  byte		Playerstate=-1;								//玩家状态-1:无人,0:入座,1:举手,2:正常,3:胜利,4:失败
		public  byte		m_nowboxindex=0;							//当前运动单元类型
		public  byte		m_nowcentera=0;								//当前运动单元旋转点方块的屏幕规格坐标
		public  byte		m_nowcenterb=0;
		
		public 	byte 		dj_num = 8;
		public 	byte 		daojubody[] = new byte[dj_num];					//道具号(0:无道具,80:清空,81:加一行,82:加2行,83:加3行,84:加速,85:减一行,86:减两行,87:减三行,88:减速)	
		private byte 		tmpdaoju[]  = new byte[MAXROWS];
		
		
		public GameData(GameHigh gamehigh)
		{
			m_randplay=new Random();
			m_gamehigh=gamehigh;
			for(int i=0;i<MAXSTYLE;i++)
			{
				m_cell[i] = null;
				m_cell[i] = new MyCell();
				for(int j=0;j<tmpbox[i].length;j++)
				{
					if(j<tmpbox[i].length-1)
					{//赋值相对坐标
						int b=(j/2);
						int a=(j%2);
						m_cell[i].ab[b][a]=tmpbox[i][j];
						//System.out.println("i="+i+"  b="+b+"  a="+a+"  ="+m_cell[i].ab[b][a]);
					}
					else
					{//赋值下次变形索引号
						m_cell[i].nextindex=tmpbox[i][j];
					}
				}
			}
			for(byte l=0;l<del.length;l++){
				del[l]=0;
			}
		}
		
		//初始化变量,赋值单元信息和标志数组
		void InitRusHigh()
			{
				m_maxy=MAXCENG;							//当前单元最高点
				m_style=0;								//(由GameHigh随机产生的典型类型绝对索引号),配合boxindex获取典型单元索引,然后在m_cell找到典型单元信息
				m_lines=0;								//当前收的行数(各行索引号保存到lineindex中)
				m_alllines=0;							//当前收的总行数
	
				m_level=0;
				m_nowboxindex=0;						//当前运动单元类型
				m_nowcentera=0;							//当前运动单元旋转点方块的屏幕规格坐标
				m_nowcenterb=0;
				
				for(byte l=0;l<del.length;l++){
					del[l]=0;
				}
				
				ClearDaoju();
				for(byte b=1;b<(MAXCENG+1);b++)
				{
					System.arraycopy(tmpdata[1],0,bin1[b],0,bin1[b].length);
				}
				System.arraycopy(tmpdata[0],0,bin1[0],0,bin1[0].length);
				System.arraycopy(tmpdata[0],0,bin1[MAXCENG+1],0,bin1[MAXCENG+1].length);
			}
		
//		设置GOGO
		public void SetGoData(int num)
		{
			if(num==0){
				for(byte b=0;b<tmpgogo.length;b++)
				{
					System.arraycopy(tmpgogo[b],0,bin1[b+5],1,tmpgogo[0].length);
				}
			}
			else if(num==1){
				for(byte b=0;b<tmp1.length;b++)
				{
					System.arraycopy(tmp1[b],0,bin1[b+5],1,tmp1[0].length);
				}
			}
			else if(num==2){
				for(byte b=0;b<tmp2.length;b++)
				{
					System.arraycopy(tmp2[b],0,bin1[b+5],1,tmp2[0].length);
				}
			}
			else if(num==3){
				for(byte b=0;b<tmp3.length;b++)
				{
					System.arraycopy(tmp3[b],0,bin1[b+5],1,tmp3[0].length);
				}
			}
		}
		//清除GOGO
		public void ClearGoData()
		{
			for(byte b=0;b<tmpgogo.length;b++)
			{
				System.arraycopy(tmpdata[1],0,bin1[b+5],0,bin1[0].length);
			}
		}
		//设置具体玩家信息
		public void CreatPlayer(MoleActor actor,byte ChairIndex)
		{
			InitRusHigh();
			Playerstate=PLAYIN;
			m_actorinfo=actor;
			m_chair=ChairIndex;
		}

		//====================信息========================//
		//获取当前单元最高点
		public byte GetMaxy()
		{
			for(byte y=MAXCENG;y>=1;y--)
			{
				if(bin1[y][1]<=0 && bin1[y][2]<=0 && bin1[y][3]<=0 &&bin1[y][4]<=0 &&bin1[y][5]<=0 && bin1[y][6]<=0 && bin1[y][7]<=0 &&bin1[y][8]<=0 &&bin1[y][9]<=0 &&bin1[y][10]<=0)
				{
					m_maxy=y;
					return m_maxy;
				}
			}
			return MAXCENG;
		}				
		
		//=====================设置=======================//
		public void SetReady(boolean enable) 
		{
			if(Playerstate==PLAYNOT)
				return;
			if(enable==true)
				Playerstate=PLAYREADY;
			else
				Playerstate=PLAYIN;
		}
		public void SetStart() 
		{
			if(Playerstate==PLAYNOT)return;
			m_nowscore=0;
			Playerstate=PLAYNOW;
		}
		public void SetEnd() 
		{
			if(Playerstate==PLAYNOT)return;
			Playerstate=PLAYIN;
		}
		public void SetWin() 
		{
			if(Playerstate==PLAYNOT)return;
			Playerstate=PLAYWIN;
		}
		public void SetLose() 
		{
			if(Playerstate==PLAYNOT)return;
			Playerstate=PLAYLOSE;
		}
		public void QuitGame()
		{
			InitRusHigh();
			Playerstate=PLAYNOT;
		}
		public boolean IsReady()
		{
			return Playerstate==PLAYREADY;
		}
		public boolean IsGameNow()
		{
			return Playerstate==PLAYNOW;
		}
		public boolean IsLosed()
		{
			return Playerstate==PLAYLOSE;
		}
		//设置名次
		void SetPlace(byte place)
		{
			Playerplace=place;
		}
		//设置旋转点信息,初始化单元时,m_nowboxindex取典型值
		void SetCenterinfo(byte b,byte index)
			{
				m_nowcentera=MAXROWS/2;
				m_nowcenterb=b;
				m_nowboxindex=(byte)(boxindex[index%MAXBASESTYLE]%MAXSTYLE);	
			}
		//设置旋转点信息,m_nowboxindex取具体值
		void SetCenterinfo(byte a,byte b,byte index)
			{
				m_nowcentera=a;
				m_nowcenterb=b;
				m_nowboxindex=(byte)(index%MAXSTYLE);			
			}
		//设置当前单元典型号
		void setnowstyle(byte style)
		{
			m_style=style;
			m_style++;
		}
		
		//设置落地单元标志
		void setbindown()
		{
			if(m_nowboxindex<0 || m_nowboxindex>=MAXSTYLE)
				return;
			int tmpx,tmpy;
			for(int i=1;i<5;i++)
			{
				tmpx=(m_nowcentera+m_cell[m_nowboxindex].ab[i][0]);
				tmpy=(m_nowcenterb+m_cell[m_nowboxindex].ab[i][1]);
				if(tmpx>=1 && tmpy>=1 && tmpx<=MAXROWS && tmpy<=MAXCENG)
					bin1[tmpy][tmpx]=m_style;
			}		
		}		
		//下降
		void  SetToDown()
			{
				m_nowcenterb++;
			}
		//左移
		void  SetToLeft()
			{
				m_nowcentera--;
			}
		//右移
		void  SetToRight()
			{
				m_nowcentera++;
			}
		//变形
		void  SetToRound()
			{
				m_nowboxindex=m_cell[m_nowboxindex].nextindex;
			}
		
		//===================各项碰装检测=====================//
		//检测左移
		//返回:TRUE可以左移
		boolean checkleft()
			{
				if(m_nowboxindex<0 || m_nowboxindex>=MAXSTYLE)
					return false;

				boolean ret=true;
				int tmpx,tmpy;
				for(int i=1;i<5;i++)
				{
					tmpx=m_nowcentera+m_cell[m_nowboxindex].ab[i][0];
					tmpy=m_nowcenterb+m_cell[m_nowboxindex].ab[i][1];
					if(tmpx>=1 && tmpy>=1 && tmpx<=MAXROWS && tmpy<=MAXCENG)
					{
						if(bin1[tmpy][tmpx]>0 || bin1[tmpy][tmpx-1]>0)
							{ret=false;break;}
					}
					else
					{
						ret=false;break;
					}
				}		
				return ret;
			}	
		//检测右移
		//返回:TRUE可以右移
		boolean checkright()
			{
				if(m_nowboxindex<0 || m_nowboxindex>=MAXSTYLE)
					return false;

				boolean ret=true;
				int tmpx,tmpy;
				for(int i=1;i<5;i++)
				{
					tmpx=m_nowcentera+m_cell[m_nowboxindex].ab[i][0];
					tmpy=m_nowcenterb+m_cell[m_nowboxindex].ab[i][1];
					if(tmpx>=1 && tmpy>=1 && tmpx<=MAXROWS && tmpy<=MAXCENG)
					{
						if(bin1[tmpy][tmpx]>0 || bin1[tmpy][tmpx+1]>0)
							{ret=false;break;}
					}
					else
					{
						ret=false;break;
					}
				}		
				return ret;
			}
		//检测是否可以下降
		//返回:TRUE可以下降
		boolean checkdown()
			{
				if(m_nowboxindex<0 || m_nowboxindex>=MAXSTYLE)
					return false;
			
				boolean ret=true;
				int tmpx,tmpy;
				for(int i=1;i<5;i++)
					{
						tmpx=m_nowcentera+m_cell[m_nowboxindex].ab[i][0];
						tmpy=m_nowcenterb+m_cell[m_nowboxindex].ab[i][1];
						if(tmpx>=1 && tmpy>=1 && tmpx<=MAXROWS && tmpy<=MAXCENG)
						{
							if(bin1[tmpy][tmpx]>0 || bin1[tmpy+1][tmpx]>0)
								{
									ret=false;
									break;
								}
						}
					}
				return ret;
			}
		//检测是否可以变形
		//返回:TRUE可以变形
		boolean checkround()
			{
				if(m_nowboxindex<0 || m_nowboxindex>=MAXSTYLE)
					return false;
				byte index=m_cell[m_nowboxindex].nextindex;
				if(index<0 || index>MAXSTYLE)
					return false;
				
				boolean ret=true;
				int tmpx,tmpy;
				for(int i=1;i<5;i++)
				{
					tmpx=m_nowcentera+m_cell[index].ab[i][0];
					tmpy=m_nowcenterb+m_cell[index].ab[i][1];
					if(tmpx>=1 && tmpy>=1 && tmpx<=MAXROWS && tmpy<=MAXCENG)
					{
						if(bin1[tmpy][tmpx]>0 || bin1[tmpy+1][tmpx]>0)
							{ret=false;break;}
					}
					else
					{
						ret=false;break;
					}
				}			
				return ret;
			}
		//检测游戏结束
		//返回:TRUE游戏结束
		boolean checkover(int offset)
			{
				boolean ret=false;
				for(int x=1;x<=MAXROWS;x++)
				{
					if(bin1[offset][x]>0)
						{
						ret=true;
						break;
						}
				}			
				return ret;
			}
		
		//返回:	TRUE存在收行,lines收行数
		boolean checkline()
			{
//			if(m_chair==m_gamehigh.MyChair)
//				m_gamehigh.bombindex=0;
			boolean ret=false;
			m_lines=0;
			for(byte i=0;i<4;i++)
			{//因为最大可能是一次收4行,所以要检测4遍

				
				for(byte y=MAXCENG;y>=2;y--)
				{
					if(m_chair==m_gamehigh.MyChair&&i>0){
						if(del[i-1]!=0&&y>=del[i-1]){
							continue;
						}
					}
					
					boolean enable=false;
					for(byte k=1;k<=MAXROWS;k++)
					{
						if(bin1[y][k]<0)
							bin1[y][k]=0;
						if(bin1[y][k]==0)
						{//当前检测行存在一个空位则继续往上寻找
							enable=true;
							break;
						}
					}
					if(enable==true)
						continue;
					else
					{//当前检测行连接成功
//							System.out.println("将要加入方块"+y);
//							ret=true;
//							m_lines++;
//							for(byte y2=y;y2>=2;y2--){
//								System.arraycopy(bin1[y2-1],0,bin1[y2],0,bin1[y2].length);
//							}
							
						if(m_chair==m_gamehigh.MyChair){
							if(del_move_judge(y)){
								ret=true;

⌨️ 快捷键说明

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