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

📄 datatool.java

📁 a java game code for java
💻 JAVA
字号:
package eatbean.util;/** * Title: * Description: * Copyright:    Copyright (c) 2002 * Company: * @author * @version 1.0 */import eatbean.*;import eatbean.conf.SysParam;//import java.util.*;import java.io.*;/** 处理地图数据 */public class DataTool {    public DataTool() {    }	public static void main(String[] args) {		DataTool dataTool = new DataTool();		dataTool.getMapData("map2.txt");	}	public int[][] getMapData(String fileName) {		int[][] result = null;		/*		result = new int[][] {					    {107, 102, 102, 102, 110},						{112,  23,  21,  21, 112},						{112,  21,  21,  21, 112},						{112,  24,  21,  21, 112},						{106, 102, 102, 102, 109},					};		*/		//String fileName = "map2.txt";		String fullFileName = SysParam.DATA_PATH + fileName;		BufferedReader brIn = null;		try {			brIn = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream(fullFileName)));		} catch(Exception ex) {}		if(brIn == null)			Debug.println("找不到数据文件: " + fullFileName);		else			try {			    result = parseText(brIn);			} catch(Exception ex) {			    Debug.println(ex.toString());				ex.printStackTrace();			}		return result;	}	private int[][] parseText(BufferedReader brIn) throws Exception {		int result[][] = null;		String lineString = null;		try {			Vector data = new Vector();			int x, y;			while((lineString = brIn.readLine()) != null) {				//if(Debug.ON) Debug.println(lineString);				StringTokenizer st = new StringTokenizer(lineString);				Integer[] lineData = new Integer[st.countTokens()];				int i = 0;				for(i = 0; st.hasMoreTokens(); i++) {					String element = st.nextToken();				    //if(Debug.ON) Debug.println(element);					int value = getElementCode(element);					lineData[i] = new Integer(value);				}				if(i > 0) data.add(lineData);			}			y = data.size();			if(y <= 0) throw new Exception("数据文件为空");			x = ((Integer[])(data.elementAt(0))).length;			System.out.println("x: " + x + " y: " + y);			result = new int[y][x];			for(int yy = 0; yy < y; yy++) {				Integer[] lineData = (Integer[])data.elementAt(yy);			    for(int xx = 0; xx < x; xx++) {					result[yy][xx] = lineData[xx].intValue();				}			}		} catch(Exception ex) {		    throw ex;		}		return result;	}	private int getElementCode(String element) throws Exception {		int value = 0;		if("B2".equals(element)) {			value = Wall.STYLE_B_2;		} else if("H2".equals(element)) {			value = Wall.STYLE_H_2;		} else if("HB3".equals(element)) {			value = Wall.STYLE_H_B_3;		} else if("HT3".equals(element)) {			value = Wall.STYLE_H_T_3;		} else if("L2".equals(element)) {			value = Wall.STYLE_L_2;		} else if("LB2".equals(element)) {			value = Wall.STYLE_L_B_2;		} else if("LT2".equals(element)) {			value = Wall.STYLE_L_T_2;		} else if("R2".equals(element)) {			value = Wall.STYLE_R_2;		} else if("RB2".equals(element)) {			value = Wall.STYLE_R_B_2;		} else if("RT2".equals(element)) {			value = Wall.STYLE_R_T_2;		} else if("T2".equals(element)) {			value = Wall.STYLE_T_2;		} else if("V2".equals(element)) {			value = Wall.STYLE_V_2;		} else if("VL3".equals(element)) {			value = Wall.STYLE_V_L_3;		} else if("VR3".equals(element)) {			value = Wall.STYLE_V_R_3;		} else if("C1".equals(element)) {			value = Wall.STYLE_C_1;		} else if("RD".equals(element)) {			value = Room.STYLE_DEFAULT;		} else if("RE".equals(element)) {			value = Room.STYLE_EMPTY;		} else if("RS".equals(element)) {			value = Room.STYLE_SPRITE_BORN;		} else if("RF".equals(element)) {			value = Room.STYLE_FAIRY_BORN;		} else			throw new Exception("文本文件分析失败: 无法识别的字串: " + element);		return value;	}}

⌨️ 快捷键说明

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