Exemple #1
0
  private void breed() throws VariableException {

    // マスコットを1個作成
    final Mascot mascot = new Mascot();

    log.log(Level.INFO, "増殖({0},{1},{2})", new Object[] {getMascot(), this, mascot});

    // 範囲外から開始
    if (getMascot().isLookRight()) {
      mascot.setAnchor(
          new Point(
              getMascot().getAnchor().x - getBornX(),
              getMascot().getAnchor().y + getBornY().intValue()));
    } else {
      mascot.setAnchor(
          new Point(
              getMascot().getAnchor().x + getBornX(),
              getMascot().getAnchor().y + getBornY().intValue()));
    }
    mascot.setLookRight(getMascot().isLookRight());

    try {
      mascot.setBehavior(Main.getInstance().getConfiguration().buildBehavior(getBornBehavior()));

      getMascot().getManager().add(mascot);

    } catch (final BehaviorInstantiationException e) {
      log.log(Level.SEVERE, "生まれた時の行動の初期化に失敗しました", e);
      mascot.dispose();
    } catch (final CantBeAliveException e) {
      log.log(Level.SEVERE, "生き続けることが出来ない状況", e);
      mascot.dispose();
    }
  }
  @Override
  public synchronized void init(final Mascot mascot) throws CantBeAliveException {

    this.setMascot(mascot);

    log.log(Level.INFO, "行動開始({0},{1})", new Object[] {this.getMascot(), this});

    try {
      getAction().init(mascot);
      if (!getAction().hasNext()) {
        try {
          mascot.setBehavior(this.getConfiguration().buildBehavior(getName(), mascot));
        } catch (final BehaviorInstantiationException e) {
          throw new CantBeAliveException("次の行動の初期化に失敗しました", e);
        }
      }
    } catch (final VariableException e) {
      throw new CantBeAliveException("変数の評価でエラーが発生しました", e);
    }
  }