gamedatasimple.java

来自「手机射击游戏源代码,nokia s60模拟器开发包,eclipse工具开发.不可」· Java 代码 · 共 629 行 · 第 1/2 页

JAVA
629
字号
		return NPCData;
	}

	public String[] getMissionProperties() {
		return null;
	}

	public int[] getPlayerInfo() {
		return null;
	}

	public int[] getPlayerNumProp() {
		return null;
	}

	public String[] getPlayerStrProp() {
		return null;
	}

	public int[] getResolvingPower() {
		return null;
	}

	public int getTileHeight() {
		return 0;
	}

	public short[][] getTilesIndex() {
		return null;
	}

	public int getTileWidth() {
		return 0;
	}

	public int getTotalColor() {
		return 0;
	}

	public int getTotalMission() {
		return 5;
	}

	protected void loadCurrentMission() {

	}

	//数据读取 GameTools.java
	// ///////////////////////////////////////////////////////////////////////
	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) {
		Array_1 = readFromFile("gamedata.c", index);

	}

	//二维数组
	public void createArray_2(int index) {
		int data[];

		data = readFromFile("gamedata.c", index);

		for (int i = 0; i < data.length; i++) {
			int column = i / length_1;
			int row = i % length_2;
			Array_2[column][row] = data[i];
		}

	}

	//三维数组
	public void createArray_3(int index) {
		int data[];
		data = readFromFile("gamedata.c", index);
		for (int i = 0; i < data.length; i++) {
			int column = (i / length_2) / length_3;
			int row = (i / length_2) % 2;
			int line = i / length_1;
			Array_3[column][row][line] = data[i];
		}
	}

	////////////////////////////
	public int[] GetArray_1(int index) {
		createArray_1(index);
		return Array_1;

	}

	public int[][] GetArray_2(int index) {
		createArray_2(index);
		return Array_2;
	}

	public int[][][] GetArray_3(int index) {
		createArray_3(index);
		return Array_3;

	}

	////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////
	//从文件读取一维数组
	//index 数组编号
	////////////////////////
	public int[] readFromFile(String fileName, int index) {
		String returnString = null;
		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;
			length_1 = 1;
			length_2 = 1;
			length_3 = 1;
			do {

				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);

				}
				System.out.println("33");
			} while (index-- != 1);
			int k = length_1 * length_2 * length_3;
			int[] data = new int[k];
			System.out.println(k);
			for (int i = 0; i < k; i++) {

				a = dis.readByte();

				if (a == -1) {

					b = dis.readByte();

					switch (b) {
					case 1://相同的shortInt数据

						break;

					case 2://shortInt数据
						c = dis.readByte();

						for (int j = 1; j <= c; j++) {

							a = dis.readByte();
							b = dis.readByte();
							ch = (b << 8) | (a & 0xff);
							i++;
						}
						i--;
						break;

					case 3://相同的byte数据

						c = dis.readByte();
						b = dis.readByte();
						for (int j = 1; j <= c; j++) {

							data[i] = b;

							if (i == k - 1)
								continue;
							i++;
						}

						i--;
						break;

					}
				} else {

					data[i] = a;
				}

				if (i == k - 2)
					break;
			}

			return data;

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				dis.close();

			} catch (IOException e1) {
				// TODO 自动生成 catch 块
				e1.printStackTrace();
			}
		}
		return null;

	}

	////////////////////////////////////////////////////////////////////////////////////////////

	/**
	 * 
	 * @param Image[]
	 *            img 存放的图片数组
	 * @param String
	 *            imgname 读取资源图片名称
	 * @param int
	 *            Image_ID 图片读取的ID,一般为零
	 * @param int
	 *            Image_Num 图片读取的数目
	 */
	public void createImage(Image[] img, String imgname, int ID,

	int Image_Num, Object o) {

		short AllImage = 0;
		int start = 1;
		try {

			input = o.getClass().getResourceAsStream("/res/" + imgname);
			DataInputStream datainputstream = new DataInputStream(input);
			AllImage = datainputstream.readByte();
			//			System.out.println("GameTools "+AllImage);

			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 < Image_Num; i++) {
				byteArray = null;
				byteArray = new byte[image_size[i]];
				datainputstream.read(byteArray);
				img[i] = Image.createImage(byteArray, 0, byteArray.length);
				datainputstream.readByte();
				start += image_size[i] + 1;
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

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