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

📄 ghost.java

📁 J2me手机游戏捉鬼源代码
💻 JAVA
字号:
//Ghost.java
//Download by http://www.codefans.net
import java.lang.*;
import java.util.*;
import javax.microedition.lcdui.*;
public class Ghost{
	public static int[] ghosts={0,0,0,0,0,0,0,0,0};
	public static String[] imgPng={"/res/g0.png","/res/g1.png","/res/g2.png","/res/g3.png","/res/g4.png","/res/g5.png","/res/g6.png","/res/g7.png","/res/g8.png"};	
	public static Image[] imgs=new Image[9];
	public static int[][] ghostMap=null;//地图鬼魂表
	public static Random random=new Random();
	public static int w,h;
        public static int i,j;
	public static void gateInit(){
		w=TollGate.gateWidth[TollGate.curTollGate];
		h=TollGate.gateHeight[TollGate.curTollGate];
		ghostMap=new int[w][h];	
		for(i=0;i<w;i++){
			for(j=0;j<h;j++){
				ghostMap[i][j]=0;
			}
		}				
		if (imgs[0]==null){
			try{
				 imgs[0]=Image.createImage(imgPng[0]);
			}catch(Exception e){}			
		}
		for (i=0;i<9;i++){
			ghosts[i]=0;
		}
		for (i=0;i<TollGate.ghostNum[TollGate.curTollGate];i++){
			//随机找到一种鬼
			int g=findNewGhost();
			//将相应标记修改
			ghosts[g]=1;
			//填入地图(成对填入)
			int t=findHouseXY();
			ghostMap[t%w][t/w]=g;
			t=findHouseXY();
			ghostMap[t%w][t/w]=g;
		}
	}		
	public static void gateEnd(){
		for (i=0;i<9;i++){
			imgs[i]=null;
		}
	}
	public static int findHouseXY(){//随机找一个房子的位置
		int rnd=Math.abs(random.nextInt())%(w*h);
		while(TollGate.gateMap[rnd%w][rnd/w]!=2 || ghostMap[rnd%w][rnd/w]!=0){
			rnd++;
			if (rnd>w*h-1){
				rnd=0;
			}	
		}
		return rnd;
	}
	public static int findNewGhost(){
		int rnd=Math.abs(random.nextInt())%8+1; //1--8
		while(ghosts[rnd]==1){
			rnd++;
			if (rnd>8) rnd=1;
		}
		return rnd;
	}
}

⌨️ 快捷键说明

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