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

📄 prop.java

📁 J2me手机游戏捉鬼源代码
💻 JAVA
字号:
//Prop.java
//道具类
//Download by http://www.codefans.net
import java.lang.*;
import java.util.*;
import javax.microedition.lcdui.*;
public class Prop{
	public static String[] imgPng={"/res/p0.png","/res/p1.png","/res/p2.png","/res/p3.png","/res/p4.png","/res/p5.png"};	
	public static Image[] imgs=new Image[6];
	public int useKindProp=0;
	public int useBadProp=0;
	public static int[][] propMap=null;//地图鬼魂表
	public static Random random=new Random();
	public static int w,h;//本关格子数
	public static int totalKindProp,totalBadProp;//本关出现的道具总数
	
	public Prop(){
	}
	public void gateInit(){
		w=TollGate.gateWidth[TollGate.curTollGate];
		h=TollGate.gateHeight[TollGate.curTollGate];
		propMap=new int[w][h];
		//
		for(int i=0;i<w;i++){
			for(int j=0;j<h;j++){
				propMap[i][j]=-1;
			}
		}
		//
		int p,t;
		totalKindProp=TollGate.kindPropNum[TollGate.curTollGate];
		totalBadProp=TollGate.badPropNum[TollGate.curTollGate];	
		for(int i=0;i<totalKindProp;i++){
			p=Math.abs(random.nextInt())%3+3; //3--5
			t=findPaceXY();
			propMap[t%w][t/w]=p;
			if (imgs[p]==null){
				try{
					imgs[p]=Image.createImage(imgPng[p]);
				}
				catch(Exception e){
				}
			}
		}
		for(int i=0;i<totalBadProp;i++){
			p=Math.abs(random.nextInt())%3; //0--2
			t=findPaceXY(); 
			propMap[t%w][t/w]=p;
			if (imgs[p]==null){
				try{
					imgs[p]=Image.createImage(imgPng[p]);
				}
				catch(Exception e){
				}
			}
		}
	}
	public void gateEnd(){
		for(int i=0;i<imgPng.length;i++){
			imgs[i]=null;
		}
	}
	public int findPaceXY()
	{
		int rnd=Math.abs(random.nextInt())%(w*h);
		int t1=Math.abs(rnd%w-Man.curX);
		int t2=Math.abs(rnd/w-Man.curY);
		while(TollGate.gateMap[rnd%w][rnd/w]!=0 || (t1<3 && t2<3) || propMap[rnd%w][rnd/w]!=-1){
			rnd++;
			if (rnd>w*h-1){
				rnd=Math.abs(random.nextInt())%(w*h);
			}
			t1=Math.abs(rnd%w-Man.curX);
			t2=Math.abs(rnd/w-Man.curY);
		}
		return rnd;
	}
	public void drawProp(Graphics g){
		for (int i=0;i<w;i++){
			for(int j=0;j<h;j++){
				if (propMap[i][j]!=-1){
					g.drawImage(imgs[propMap[i][j]],TollGate.bgX+i*TollGate.gridH,TollGate.bgY+j*TollGate.gridH,20);
					if (j<6 && TollGate.gateMap[i][j+1]!=0 && i%2!=0){
						g.drawImage(TollGate.mapImg[TollGate.gateMap[i][j+1]],TollGate.bgX+i*TollGate.gridW,TollGate.bgY+(j+1)*TollGate.gridH-10,20);					
					}					
				}

			}
		}
	}
}

⌨️ 快捷键说明

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