这是一款横版益智类游戏

源代码在线查看: prop.java

软件大小: 207 K
上传用户: huajunun
关键词:
下载地址: 免注册下载 普通下载 VIP

相关代码

				//Prop.java
				//道具类
				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							for(int j=0;j								propMap[i][j]=-1;
							}
						}
						//
						int p,t;
						totalKindProp=TollGate.kindPropNum[TollGate.curTollGate];
						totalBadProp=TollGate.badPropNum[TollGate.curTollGate];	
						for(int i=0;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							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							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							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							for(int j=0;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										g.drawImage(TollGate.mapImg[TollGate.gateMap[i][j+1]],TollGate.bgX+i*TollGate.gridW,TollGate.bgY+(j+1)*TollGate.gridH-10,20);					
									}					
								}
				
							}
						}
					}
				}
							

相关资源