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

📄 buildingblock.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                return data; //hand back the goods...    }                    /** Clears the <CODE>rawData</CODE> Vector and inserts a default comment and <I>BlockVersion</I>     * information.     * @return Returns true on success.     */        public boolean createNewBlock() {                     rawData.clear();                        this.writeBlockComment("building block data file"); //$NON-NLS-1$        rawData.add(new String("")); //blank line.. //$NON-NLS-1$            this.writeBlockData("BlockVersion", ""+BuildingBlock.version); //$NON-NLS-1$ //$NON-NLS-2$                return true;    }        //to make life easier...        /**     * @see writeBlockData (String, Vector)     */        public boolean writeBlockData(String blockName, String blockData) {             String [] temp = new String[1];        temp[0] = blockData;                return writeBlockData(blockName, this.makeVector(temp));             }        /**     * @see writeBlockData (String, Vector)     */        public boolean writeBlockData(String blockName, int blockData) {             String [] temp = new String[1];        temp[0] = ""+blockData; //$NON-NLS-1$        return writeBlockData(blockName, this.makeVector(temp));             }    /**     * @see writeBlockData (String, Vector)     */        public boolean writeBlockData(String blockName, int [] blockData) {             String [] temp = new String[blockData.length];                        for (int c = 0; c < blockData.length; c++) {                             temp[c] = ""+blockData[c]; //$NON-NLS-1$                            }        return writeBlockData(blockName, this.makeVector(temp));                }        /**     * @see writeBlockData (String, Vector)     */        public boolean writeBlockData(String blockName, float blockData) {             String [] temp = new String[1];        temp[0] = ""+blockData; //$NON-NLS-1$        return writeBlockData(blockName, this.makeVector(temp));             }            /**     * @see writeBlockData (String, Vector)     */        public boolean writeBlockData(String blockName, float [] blockData) {             String [] temp = new String[blockData.length];                                for (int c = 0; c < blockData.length; c++) {                             temp[c] = ""+blockData[c]; //$NON-NLS-1$                            }                    return writeBlockData(blockName, this.makeVector(temp));            }        /**     * @see writeBlockData (String, Vector)     */        public boolean writeBlockData(String blockName, String [] blockData) {                return writeBlockData(blockName, this.makeVector(blockData));           }    /**      * Writes a data block to the <CODE>rawData</CODE> vector.     * @param blockName Name of the block to be created.     * @param blockData Data to be written inside the block.     * @return Returns true on success.     */        public boolean writeBlockData(String blockName, Vector blockData) {            rawData.add(new String("<"+blockName+">")); //$NON-NLS-1$ //$NON-NLS-2$                for (int c = 0; c < blockData.size(); c++) {                    //            rawData.add(new String(blockData.get(c).toString().trim()));                }                rawData.add(new String("</"+blockName+">")); //$NON-NLS-1$ //$NON-NLS-2$        rawData.add(new String("")); //$NON-NLS-1$                return true;            }    /** Writes a comment.     * @param theComment The comment to be written.     * @return Returns true on success.     */        public boolean writeBlockComment(String theComment) {             rawData.add(BuildingBlock.comment+theComment);        return true;            }            /** Writes the buildingBlock data to a file.     * @param fileName File to write.  Overwrites existing files.     * @return Returns true on success.     */        public boolean writeBlockFile(String fileName) {             File file = new File(fileName);                if (file.exists()) {            if (!file.delete()) {                             System.err.println("Unable to delete file...(so I could re-write it)"); //$NON-NLS-1$                return false;            }        }                try {            //        file.createNewFile();                        BufferedWriter out = new BufferedWriter(new FileWriter(file));                                    for (int c = 0; c < rawData.size(); c++) {                                                             out.write(rawData.get(c).toString());                out.newLine();                                            }                            out.flush();            out.close();        } catch (IOException e) {                     System.err.println("Unable to save block file "+fileName); //$NON-NLS-1$            return false;        }                return true;    }            /** Clears the <CODE>rawData</CODE> Vector.     */        public void clearData() {             rawData.clear();            }        /**      * Gets the size of the <CODE>rawData</CODE> Vector.     * @return Returns <CODE>rawData.size()</CODE>     */        public int dataSize() {                     return rawData.size();            }        /**      * Converts a String array into a Vector.     * @param stringArray The String array to convert.     * @return Returns the Vector created by the String[]     */        public Vector makeVector(String [] stringArray) {             Vector newVect = new Vector();        int c=0;                try {                     for (c = 0; c < stringArray.length; c++) {                        //this should throw an expection when we hit the end                stringArray[c] = stringArray[c].trim();                                newVect.add(stringArray[c]);                            }                    } catch(ArrayIndexOutOfBoundsException e) {                     //we're done...return the vector            return newVect;                    }                return newVect; //just to make sure ; -?            }        /**      * Useful if you want to copy one buildingBlock into another.     * @return Returns the <CODE>rawData</CODE> Vector.     */        public Vector getVector() {             return this.rawData;            }        /**      * Gets all the data inside the <CODE>rawData</CODE> Vector.     * @return Returns the data as a String array     */        public String[] getAllDataAsString() {                String[] theData = new String[this.rawData.size()];                for (int c = 0; c < this.rawData.size(); c++ ) {                     theData[c] = this.rawData.get(c).toString();                    }                return theData;            }        /**      * Just about the same as the <CODE>getVector()</CODE> command.     * @see getVector ()     * @return Returns the <CODE>rawData</CODE> Vector.     */        public Vector getAllDataAsVector() {                Vector theData = this.rawData; //can I jsut return this?                return theData;            }            /**      * Tells you the size of an array this thing returned by giving you the number in the     * [0] position.     * @param array The array to get the size of.     * @return Returns the number in the [0] position.     */        public int getReturnedArraySize(String []array) {                        try {                    return Integer.parseInt(array[0]);                }catch( NumberFormatException e) {                     //couldn't parse it...            System.err.println("Couldn't find array size at [0]...is this an array I returned...?"); //$NON-NLS-1$            System.err.println("Trying to find size anyway..."); //$NON-NLS-1$            return this.countArray(array);        }                    }    //for those of us who like doing things indirectly ; -?        /**     * @see getReturnedArraySize (String[])     */        public int getReturnedArraySize(int []array) {        return array[0];    }    /**     * @see getReturnedArraySize (String[])     * @return Returns <CODE>array.size()</CODE>     */        public int getReturnedArraySize(Vector array) {        return array.size();    }        /**     * @see getReturnedArraySize (String[])     */        public int getReturnedArraySize(float []array) {                try{            return Integer.parseInt(""+array[0]); //$NON-NLS-1$        } catch(NumberFormatException e) {                        System.err.println("Couldn't find array size at [0]...is this an array I returned...?"); //$NON-NLS-1$            System.err.println("Trying to find size anyway..."); //$NON-NLS-1$            return this.countArray(array);        }              }    /**      * Counts the size of an array.     * @param array The array to count.     * @return Returns the array's size.     */        public int countArray(String[] array) {                return array.length;        }            /**     * @see countArray( String[] )     */        public int countArray(float[] array) {                return array.length;    }        /**     * @see countArray( String[] )     */        public int countArray(int[] array) {                    return array.length;    }    /**     *Checks to see if a block exists...returns true or false     */    public boolean exists(String blockName) {               if (this.findStartIndex(blockName) == -1) return false;        if (this.findEndIndex(blockName) == -1) return false;                return true;    }}

⌨️ 快捷键说明

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