コード例 #1
0
  @Override
  public void update() {
    if (!transmitting) {
      super.update();

      ArrayList deadMonsters = new ArrayList();

      Monster monster = null;

      try {
        for (String key : monsters.keySet()) {
          monster = (Monster) monsters.get(key);
          if (monster != null) {
            monster.update();
            if (monster.getIsDead()) {
              deadMonsters.add(key);
            }
          }
        }

        if (deadMonsters.size() > 0) {
          for (int i = 0; i < deadMonsters.size(); i++) {
            // EIError.debugMsg((String) deadMonsters.get(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
ファイル: MainThread.java プロジェクト: WhyMeMan/RPGBot
  public void run() {
    while (true) {
      float timePassed = (System.nanoTime() - lastTimeNanos) / 10000000f;
      lastTimeNanos = System.nanoTime();

      if (!rpgBot.isRunning) return;
      for (Manager m : managers) {
        m.update(timePassed);
      }

      try {
        Thread.sleep(50);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }