コード例 #1
0
  @Override
  public boolean checkMobParticleHit(Particle p) {
    if (gameController.multiplayerMode != gameController.multiplayerMode.CLIENT) {
      Monster monster = null;

      try {
        for (String key : monsters.keySet()) {
          monster = (Monster) monsters.get(key);
          if (monster.getPerimeter().intersects(p.getRect())) {
            monster.applyDamage(p.getDamage(), p.getSource(), p.isFromPlaceable(), false);
            return true;
          }
        }
      } 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
      }
    }

    return false;
  }
コード例 #2
0
  public void removeAllMonsters(Rectangle area) {
    Monster monster = null;

    ArrayList deadMonsters = new ArrayList();

    try {
      for (String key : monsters.keySet()) {
        monster = (Monster) monsters.get(key);
        if (monster != null) {
          if (!monster.getName().equals("Pig")
              && !monster.getName().equals("BlueThorn")
              && !monster.getName().equals("VineThorn")
              && monster.getPerimeter().intersects(area)) {
            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
    }
  }