예제 #1
0
  public void removeAllMonsters() {
    Monster monster = null;

    ArrayList deadMonsters = new ArrayList();

    try {
      for (String key : monsters.keySet()) {
        monster = (Monster) monsters.get(key);
        if (!monster.getName().equals("Pig")
            && !monster.getName().equals("BlueThorn")
            && !monster.getName().equals("VineThorn")) {
          deadMonsters.add(key);
          if (gameController.multiplayerMode == gameController.multiplayerMode.SERVER
              && registry.getNetworkThread() != null) {
            if (registry.getNetworkThread().readyForUpdates()) {
              UpdateMonster um = new UpdateMonster(monster.getId());
              um.mapX = monster.getMapX();
              um.mapY = monster.getMapY();
              um.action = "Die";
              registry.getNetworkThread().sendData(um);
            }
          }
        }
      }

      if (deadMonsters.size() > 0) {
        for (int i = 0; i < deadMonsters.size(); i++) {
          monsters.remove((String) deadMonsters.get(i));
        }
      }
    } catch (ConcurrentModificationException concEx) {
      // another thread was trying to modify monsters while iterating
      // we'll continue and the new item can be grabbed on the next update
    }
  }
예제 #2
0
 public void registerMonster(Monster m) {
   if (!monsters.containsKey(m.getId())) {
     monsters.put(m.getId(), m);
   }
 }