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

📄 gametools.java

📁 有一些还没做好请谅解不支持midp1.0
💻 JAVA
字号:
import java.io.DataInputStream;
import java.io.IOException;
import java.io.EOFException;
import java.io.InputStream;
import javax.microedition.lcdui.Image;
public class GameTools {
	byte type;
	int length_1;
	int length_2;
	int length_3;
	int Array_1[];
	int Array_2[][];
	int Array_3[][][];

	  private static byte byteArray[];

	  private  static InputStream input;
	
	  public int image_size[] ;
	 
public void createArray_1(int index, String FileName){
	Array_1=readFromFile(FileName,index);	
}

public void createArray_2(int index, String FileName){
	int data[];
	data=readFromFile(FileName,index);
	Array_2=new int[length_1][length_2];
	
	for (int i = 0; i < data.length; i++) 
	{
		int column = i / length_2;
		int row = i % length_2;
		Array_2[column][row] =data[i];
	}
}

public void createArray_3(int index, String FileName){
	int data[];
	data=readFromFile(FileName,index);
	
	int dataindex=0;
	Array_3=new int[length_1][ length_2][length_3];
	for (int i = 0; i <length_1;i++) {	
		for (int j=0;j<length_2;j++){
			for (int k=0;k<length_3;k++)
			{				
				Array_3[i][j][k] =data[dataindex];
				dataindex++;		
			}
		}
	}	
}

public int [] GetArray_1(int index, String filename){
	createArray_1(index, filename);
	return Array_1;
}
public int [][] GetArray_2(int index, String filename){
	createArray_2(index, filename);
	return Array_2;
}
public int [][][] GetArray_3(int index, String filename){
	createArray_3(index, filename);
	return Array_3;
}

	public int [] readFromFile(String fileName,int index) {	
		DataInputStream dis = new DataInputStream (getClass().getResourceAsStream(fileName));
		try {
				int ch = 0;
				byte a=0;
				byte b=0;
				byte c=0;
				int skip =0;
				 type=0;
					do
					{
						 length_1=1;
						 length_2=1;
						 length_3=1;
						type=dis.readByte();
						
					 
						switch(type)
						{
						case 1:
							a = dis.readByte();
							b = dis.readByte();
							length_1=(b << 8) | (a & 0xff);
							a = dis.readByte();
							b = dis.readByte();
							skip=(b << 8) | (a & 0xff);
						
							break;
						case 2:
							a = dis.readByte();
							b = dis.readByte();
							length_1=(b << 8) | (a & 0xff);
							a = dis.readByte();
							b = dis.readByte();
							length_2=(b << 8) | (a & 0xff);
							a = dis.readByte();
							b = dis.readByte();
							skip=(b << 8) | (a & 0xff);
							break;
						case 3:
							a = dis.readByte();
							b = dis.readByte();
							length_1=(b << 8) | (a & 0xff);
							a = dis.readByte();
							b = dis.readByte();
							length_2=(b << 8) | (a & 0xff);
							a = dis.readByte();
							b = dis.readByte();
							length_3=(b << 8) | (a & 0xff);
                            a = dis.readByte();
							b = dis.readByte();
							skip=(b << 8) | (a & 0xff);
							break;
						default :						
						}
						
						if(index!=1) {									
							dis.skipBytes(skip);	
						}
					} while(index--!=1);
			         int k=length_1*length_2*length_3; 
					int[] data=new int[k];					
					for (int i=0;i<k;i++ ) 
						{						
							a = dis.readByte();
							if(a==-128)
							 {
								b = dis.readByte();
								switch(b)
								{
								 case 1:
									break;		
								 case 2:
								 	c = dis.readByte();
									for(int j=1;j<=c;j++)
									{		
										a = dis.readByte();
										b = dis.readByte();			
										ch=(b << 8) | (a & 0xff);
										data[i]=ch;
										i++;		
									}
									i--;
									break;		
								 case 3:
									c = dis.readByte();
									b = dis.readByte();
									for(int j=1;j<=c;j++)
									{
										data[i]=b;										
										i++;
									}					
										i--;	
									break;					
								}	
							 }
							else{	
							data[i]=a;
								}	
						}
					return data;	
			
			} catch(EOFException e)
			{
				}catch (IOException e) {
				e.printStackTrace();
			}
			finally{
				try {
					dis.close();	
				} catch (IOException e1) {
					e1.printStackTrace();
				}
				}
			return null;		
		}
	
	  public void createImage(Image[] img, String imgname,int ID,
	                           
	                           int Image_Num) {


	    int AllImage=0;
	    int start=1;
	  	
	    
	    try {
	     
	      input = this.getClass().getResourceAsStream(""+imgname);
	      DataInputStream datainputstream = new DataInputStream(input);
	      AllImage=datainputstream.readUnsignedByte();
     
	      image_size=new int [AllImage];
	      
	       for (int i = 0; i <AllImage ; i++) {
	       	byte a=datainputstream.readByte();
	       	byte b=datainputstream.readByte();
	      	image_size[i] =  (b << 8) | (a & 0xff);
	      	if(i<=Image_Num)
	      	{
	      		start+=2;
	      	}
	      }

	       for(int i=0;i<ID;i++)
    {
	       datainputstream.skip(image_size[i]+1);

	       }
	
	      for (int i = 0; i < Image_Num; i++) {
	            byteArray = null;
	            byteArray = new byte[image_size[ID+i]];

	            datainputstream.read(byteArray);
	            
	          img[i] = Image.createImage(byteArray, 0, byteArray.length );
	         
	        datainputstream.readByte();   
	        start += image_size[ID+i]+1;
	       
	      }
	    }
	    catch (Exception ex) {
	      ex.printStackTrace();
	    }
	  }
}


⌨️ 快捷键说明

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