示例#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();
    }
  }
  /*
   * getWall() - Environment check. Checks both the currently active windows
   * and the sides of the screen. Returns the border if on one. Controls the
   * current Wall attribute of each mascot.
   */
  public Border getWall(boolean ignoreSeparator) {
    // Don't let the mascot hold onto window walls when within 64px of
    // the top of the screen.
    if (mascot.getAnchor().getY() <= getWorkArea().getTop() + 64) {
      Point p = mascot.getAnchor();
      if (mascot.onBorder()) {
        p.setLocation(p.getX() + 1, p.getY());
        mascot.setAnchor(p);
      }
      return NotOnBorder.INSTANCE;
    }
    if (mascot.isLookRight()) {
      if (getIE().onLeft(mascot.getAnchor())) {
        Wall w = getIE().getLeft(mascot.getAnchor());
        if (!checkLayering(w.getArea())) {
          mascot.setCurW(null);
          return NotOnVisibleBorder.INSTANCE;
        }
        mascot.setCurW(w);
        return w;
      }

      if (getWorkArea().getRightBorder().isOn(mascot.getAnchor())) {
        // if ( !ignoreSeparator || isScreenLeftRight() ) {
        if (isScreenLeftRight(ignoreSeparator)) {
          mascot.setCurW(null);
          return getWorkArea().getRightBorder();
        }
      }

    } else {
      if (getIE().onRight(mascot.getAnchor())) {
        Wall w = getIE().getRight(mascot.getAnchor());
        if (!checkLayering(w.getArea())) {
          mascot.setCurW(null);
          return NotOnVisibleBorder.INSTANCE;
        }
        mascot.setCurW(w);
        return w;
      }

      if (getWorkArea().getLeftBorder().isOn(mascot.getAnchor())) {
        // if ( !ignoreSeparator ||isScreenLeftRight() ) {
        if (isScreenLeftRight(ignoreSeparator)) {
          mascot.setCurW(null);
          return getWorkArea().getLeftBorder();
        }
      }
    }
    mascot.setCurW(null);
    return NotOnBorder.INSTANCE;
  }