Examples of Tank


Examples of megamek.common.Tank

     *             <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) {
        Tank entity = null;
        String attrStr;
        int attrVal;

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

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

        // TODO : perform version checking.

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

        // 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 stunnedTurns node?
            else if (childName.equals("stunnedTurns")) {

                // Get the Tank's stunned turns.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the stunnedTurns for a Tank 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);
                }
                entity.setStunnedTurns(attrVal);
            }

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

                // See if the Tank has a no turret.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode hasNoTurret for a Tank unit.");
                }

                // If the value is "true", the Tank has a no turret.
                if (attrStr.equals("true")) {
                    entity.setHasNoTurret(true);
                } else {
                    entity.setHasNoTurret(false);
                }
            }

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

                // See if the Tank has a move hit.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode moveHit for a Tank unit.");
                }

                // If the value is "true", the Tank move a hit pending.
                if (attrStr.equals("true")) {
                    entity.immobilize();
                    entity.applyDamage();
                }
            }

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

                // See if the Tank has a move hit pending.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode moveHitPending for a Tank unit.");
                }

                // If the value is "true", the Tank move a hit pending.
                if (attrStr.equals("true")) {
                    entity.immobilize();
                }
            }

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

                // Get the Tank's facing.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the facing for a Tank 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);
                }
                entity.setFacing(attrVal);
            }

            // Did we find the turret's secondaryFacing node?
            else if (childName.equals("turretFacing")) {

                // Get the Tank's turret's facing.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the turret's secondaryFacing for a Tank 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);
                }
                entity.setSecondaryFacing(attrVal);
            }

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

                // See if the Tank move a hit pending.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode turretLocked for a Tank unit.");
                }

                // If the value is "true", the Tank move a hit pending.
                if (attrStr.equals("true")) {
                    entity.lockTurret();
                }
            }

        } // Handle the next element.

View Full Code Here

Examples of org.jgroups.demo.tankwar.model.Tank

  public JMXRegisterTest() {
  }
 
  public static void main(String[] args) throws Exception {
   
    Tank tank = new Tank("myTank", true, true, 100, 100, 100, Direction.LU, Direction.LU, null);
   
    MBeanServer server = JMXUtil.getMBeanServer();

//    JMXUtil.registerTank(tank, server, "TankWar:type=View,name=tank");
   
View Full Code Here

Examples of org.jgroups.demo.tankwar.model.Tank

    }
   
    Session session = (Session) msg.getObject();
    TankView view = session.tankView();
    if(view.isLive()){
      Tank tank = tankMap.get(view.getId());
      if(null == tank) {
        tankMap.put(view.getId(), new Tank(view));
      } else {
        tank.updateTank(view);
      }
    } else {
      tankMap.remove(view.getId());
    }
   
View Full Code Here

Examples of org.jgroups.demo.tankwar.model.Tank

    String id = comm.getName();
   
    int x = getRandom(GAME_WIDTH - 100);
    int y = getRandom(GAME_HEIGHT - 100);
   
    myTank = new Tank(id, isGood, true, 100, x, y, Direction.STOP, Direction.D, this);
   
    comm.put(id, myTank);   
    comm.replicateTank(myTank.getView());
  }
View Full Code Here

Examples of org.nutz.dao.test.meta.Tank

  @Test
  public void delete_links() {
    TableName.run(platoon, new Atom() {
      public void run() {
        Tank t = dao.fetchLinks(dao.fetch(Tank.class, "M1-A1"), "motorman");
        dao.deleteLinks(t, "motorman");
        assertEquals(4, dao.count(Soldier.class));
        assertEquals(2, dao.count(Tank.class));
      }
    });
View Full Code Here

Examples of org.nutz.dao.test.meta.Tank

  @Test
  public void delete_with() {
    TableName.run(platoon, new Atom() {
      public void run() {
        Tank t = dao.fetchLinks(dao.fetch(Tank.class, "M1-A1"), "motorman");
        dao.deleteWith(t, "motorman");
        assertEquals(4, dao.count(Soldier.class));
        assertEquals(1, dao.count(Tank.class));
      }
    });
View Full Code Here

Examples of org.nutz.dao.test.meta.Tank

  @Test
  public void clear_links() {
    TableName.run(platoon, new Atom() {
      public void run() {
        Tank t = dao.fetch(Tank.class, "M1-A1");
        dao.clearLinks(t, "motorman");
        assertEquals(4, dao.count(Soldier.class));
        assertEquals(2, dao.count(Tank.class));
      }
    });
View Full Code Here

Examples of org.nutz.dao.test.meta.Tank

  @Test
  public void update_links() {
    TableName.run(platoon, new Atom() {
      public void run() {
        Tank t = dao.fetchLinks(dao.fetch(Tank.class, "M1-A1"), "motorman");
        t.getMotorman().setAge(32);
        dao.updateLinks(t, "motorman");
        Soldier s = dao.fetch(Soldier.class, t.getMotorName());
        assertEquals(32, s.getAge());
      }
    });
  }
View Full Code Here

Examples of org.nutz.dao.test.meta.Tank

  @Test
  public void update_with() {
    TableName.run(platoon, new Atom() {
      public void run() {
        Tank t = dao.fetchLinks(dao.fetch(Tank.class, "M1-A1"), "motorman");
        t.getMotorman().setAge(32);
        t.setWeight(50);
        dao.updateWith(t, "motorman");
        Soldier s = dao.fetch(Soldier.class, t.getMotorName());
        assertEquals(32, s.getAge());
        t = dao.fetch(Tank.class, t.getId());
        assertEquals(50, t.getWeight());
      }
    });
  }
View Full Code Here

Examples of org.nutz.dao.test.meta.Tank

  @Test
  public void delete_links() {
    TableName.run(platoon, new Atom() {
      public void run() {
        Tank t = dao.fetchLinks(dao.fetch(Tank.class, "T92"), "members");
        assertEquals(3, t.getMembers().size());
        dao.deleteLinks(t, "members");
        assertEquals(2, dao.count(Soldier.class));
        assertEquals(2, dao.count("dao_d_m_soldier_tank_" + platoon.getId()));
      }
    });
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.