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

📄 gameoptions.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        addOption(ruleBreakers,"armed_mechwarriors", false); //$NON-NLS-1$        addOption(ruleBreakers,"auto_abandon_unit", false); //$NON-NLS-1$        addOption(ruleBreakers,"no_ignite_clear", false); //$NON-NLS-1$        addOption(ruleBreakers,"falls_end_movement", false); //$NON-NLS-1$    }    public Vector loadOptions() {        return loadOptions(new File(GAME_OPTIONS_FILE_NAME));    }        public Vector loadOptions(File file) {        ParsedXML root = null;        InputStream is = null;        Vector changedOptions = new Vector();        try {            is = new FileInputStream(file);        } catch (FileNotFoundException e) {            return changedOptions;        }        try {            root = TinyParser.parseXML(is);        } catch (ParseException e) {            System.out.println("Error parsing game options xml file.");  //$NON-NLS-1$            e.printStackTrace(System.out);        }        Enumeration rootChildren = root.elements();        ParsedXML optionsNode = (ParsedXML)rootChildren.nextElement();              if ( optionsNode.getName().equals("options") ) { //$NON-NLS-1$            Enumeration children = optionsNode.elements();                    while (children.hasMoreElements()) {                IOption option = parseOptionNode((ParsedXML)children.nextElement());                          if ( null != option )                    changedOptions.addElement(option);            }                    return changedOptions;        }		System.out.println("Root node of game options file is incorrectly named. Name should be 'options' but name is '" + optionsNode.getName() + "'"); //$NON-NLS-1$ //$NON-NLS-2$		return changedOptions;    }        private IOption parseOptionNode(ParsedXML node) {        IOption option = null;              if ( node.getName().equals("gameoption") ) { //$NON-NLS-1$            Enumeration children = node.elements();            String name = null;            Object value = null;                    while (children.hasMoreElements()) {                ParsedXML child = (ParsedXML)children.nextElement();                          if ( child.getName().equals("optionname") ) { //$NON-NLS-1$                    name = ((ParsedXML)child.elements().nextElement()).getContent();                } else if ( child.getName().equals("optionvalue") ) { //$NON-NLS-1$                    value = ((ParsedXML)child.elements().nextElement()).getContent();                }            }                    if ( (null != name) && (null != value) ) {                IOption tempOption = this.getOption(name);                          if ( null != tempOption ) {                    if ( !tempOption.getValue().toString().equals(value.toString()) ) {                        try {                            switch ( tempOption.getType() ) {                            case IOption.STRING:                                tempOption.setValue((String)value);                                break;                                                case IOption.BOOLEAN:                                tempOption.setValue(new Boolean(value.toString()));                                break;                                                case IOption.INTEGER:                                tempOption.setValue(new Integer(value.toString()));                                break;                                                case IOption.FLOAT:                                tempOption.setValue(new Float(value.toString()));                                break;                            }                                            System.out.println("Set option '" + name + "' to '" + value + "'."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$                                            option = tempOption;                        } catch ( IllegalArgumentException iaEx ) {                            System.out.println("Error trying to load option '" + name + "' with a value of '" + value + "'."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$                        }                    }                } else {                    System.out.println("Invalid option '" + name + "' when trying to load options file."); //$NON-NLS-1$ //$NON-NLS-2$                }            }        }              return option;    }        /**     * Saves the given <code>Vector</code> of <code>IBasicOption</code>     * @param options <code>Vector</code> of <code>IBasicOption</code>     */    public static void saveOptions( Vector options ) {        try {            Writer output = new BufferedWriter( new OutputStreamWriter ( new FileOutputStream(new File(GAME_OPTIONS_FILE_NAME)) ) );            // Output the doctype and header stuff.            output.write( "<?xml version=\"1.0\"?>" ); //$NON-NLS-1$            output.write( CommonConstants.NL );            output.write( "<options>" ); //$NON-NLS-1$            output.write( CommonConstants.NL );              // Now the options themselves            for ( int i = 0; i < options.size(); i++ ) {                final IBasicOption option = (IBasicOption) options.elementAt(i);                  output.write( "   <gameoption>" ); //$NON-NLS-1$                output.write( CommonConstants.NL );                output.write( "      <optionname>" ); //$NON-NLS-1$                output.write( option.getName() );                output.write( "</optionname>" ); //$NON-NLS-1$                output.write( CommonConstants.NL );                output.write( "      <optionvalue>" ); //$NON-NLS-1$                output.write( option.getValue().toString() );                output.write( "</optionvalue>" ); //$NON-NLS-1$                output.write( CommonConstants.NL );                  output.write( "   </gameoption>" ); //$NON-NLS-1$                output.write( CommonConstants.NL );            }              // Finish writing.            output.write( "</options>" ); //$NON-NLS-1$            output.write( CommonConstants.NL );            output.flush();            output.close();        } catch (IOException e) {}    }            /* (non-Javadoc)     * @see megamek.common.options.AbstractOptions#getOptionsInfoImp()     */    protected AbstractOptionsInfo getOptionsInfoImp() {        return GameOptionsInfo.getInstance();    }    private static class GameOptionsInfo extends AbstractOptionsInfo {        private static AbstractOptionsInfo instance = new GameOptionsInfo();         protected GameOptionsInfo() {            super("GameOptionsInfo"); //$NON-NLS-1$        }        public static AbstractOptionsInfo getInstance() {            return instance;        }    }}

⌨️ 快捷键说明

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