Ejemplo n.º 1
0
  @Override
  public void run() {
    Lecture lect = this.game.getCurrentLesson().getCurrentExercise();
    if (!(lect instanceof Exercise)) return;
    Exercise exo = (Exercise) lect;

    boolean stepModeWasActivated = this.game.stepModeEnabled();

    try {
      game.setState(Game.GameState.DEMO_STARTED);

      this.game.disableStepMode();

      exo.runDemo(runners);

      Iterator<Thread> it = runners.iterator();
      while (it.hasNext()) {
        Thread t = it.next();
        if (!t.equals(this)) {
          /* do not wait for myself */
          t.join();
          it.remove();
        }
      }
    } catch (InterruptedException e) {
      game.getOutputWriter().log(e);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (stepModeWasActivated) {
        this.game.enableStepMode();
      }
      game.setState(Game.GameState.DEMO_ENDED);
    }

    runners.remove(this);
  }