Examples of Infantry


Examples of megamek.common.Infantry

     * @throws <code>IllegalArgumentException</code> if the entity is
     *             <code>null</code>.
     * @throws <code>IOException</code> if there's any error on write.
     */
    public static void encode(Entity entity, Writer out) throws IOException {
        Infantry inf = (Infantry) entity;
        int value;

        // First, validate our input.
        if (null == entity) {
            throw new IllegalArgumentException("The entity is null.");
        }
        if (null == out) {
            throw new IllegalArgumentException("The writer is null.");
        }

        // Our EntityEncoder already gave us our root element.
        out.write("<shootingStrength value=\"");
        value = inf.getShootingStrength();
        out.write(String.valueOf(value));
        out.write("\" />");
    }
View Full Code Here

Examples of megamek.common.Infantry

     *             <code>null</code>.
     * @throws <code>IllegalStateException</code> if the node does not contain
     *             a valid <code>Entity</code>.
     */
    public static Entity decode(ParsedXML node, IGame game) {
        Infantry entity = null;
        String attrStr;
        int attrVal;

        // Did we get a null node?
        if (null == node) {
            throw new IllegalArgumentException("The Infantry node is null.");
        }

        // Make sure that the node is for an Infantry unit.
        attrStr = node.getAttribute("name");
        if (!node.getName().equals("class") || null == attrStr
                || !attrStr.equals("Infantry")) {
            throw new IllegalStateException("Not passed an Infantry node.");
        }

        // TODO : perform version checking.

        // Create the entity.
        entity = new Infantry();

        // Walk the board node's children.
        Enumeration<?> children = node.elements();
        while (children.hasMoreElements()) {
            ParsedXML child = (ParsedXML) children.nextElement();
            String childName = child.getName();

            // Handle null child names.
            if (null == childName) {

                // No-op.
            }

            // Did we find the shootingStrength node?
            else if (childName.equals("shootingStrength")) {

                // Get the number of men shooting.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the shootingStrength for an Infantry unit.");
                }

                // Try to pull the number from the attribute string
                try {
                    attrVal = Integer.parseInt(attrStr);
                } catch (NumberFormatException exp) {
                    throw new IllegalStateException(
                            "Couldn't get an integer from " + attrStr);
                }

                // Shooting strength is set... oddly.
                entity.setInternal(Infantry.LOC_INFANTRY, attrVal);
                entity.applyDamage();
            }

        } // Handle the next element.

        // Return the entity.
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.