private boolean checkLayering(Area b) {
   ArrayList<Number> id = getVisible();
   Vector<Rectangle> rects = new Vector<Rectangle>(id.size());
   for (Number n : id) {
     rects.add(getIE().get(n).toRectangle());
   }
   Rectangle r = b.toRectangle();
   int index = 0;
   for (Rectangle rect : rects) {
     if (r.equals(rect)) {
       index = rects.indexOf(rect) + 1;
     }
   }
   for (int i = index; i < rects.size(); i++) {
     Rectangle rect = rects.get(i);
     if (r.intersects(rect)) {
       Rectangle isect = r.intersection(rect);
       isect.setRect(isect.x, isect.y, isect.getWidth() + 1, isect.getHeight() + 2);
       if (isect.contains(mascot.getAnchor())) {
         return false;
       }
     }
   }
   return true;
 }
Beispiel #2
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();
    }
  }
Beispiel #3
0
  @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);
    }
  }
 public Border getCeiling(boolean ignoreSeparator) {
   if (getIE().onBottom(mascot.getAnchor())) {
     FloorCeiling fc = getIE().getBottom(mascot.getAnchor());
     if (!checkLayering(fc.getArea())) {
       mascot.setCurFC(null);
       return NotOnVisibleBorder.INSTANCE;
     }
     mascot.setCurFC(fc);
     return fc;
   }
   if (getWorkArea().getTopBorder().isOn(mascot.getAnchor())) {
     if (!ignoreSeparator || isScreenTopBottom()) {
       mascot.setCurFC(null);
       return getWorkArea().getTopBorder();
     }
   }
   mascot.setCurFC(null);
   return NotOnBorder.INSTANCE;
 }
 /*
  * getFloor() - Environment check. Checks both the currently active windows
  * and the bottom of the screen. Returns the border if on one. Controls the
  * current Floor/Ceiling attribute of each mascot.
  */
 public Border getFloor(boolean ignoreSeparator) {
   if (getIE().onTop(mascot.getAnchor())) {
     FloorCeiling fc = getIE().getTop(mascot.getAnchor());
     if (!checkLayering(fc.getArea())) {
       mascot.setCurFC(null);
       return NotOnVisibleBorder.INSTANCE;
     }
     if (currentWorkArea == null) currentWorkArea = impl.getWorkArea();
     // Don't let the mascot get footing on any window ceiling within 64px
     // of the top of the screen.
     if (fc.getY() >= currentWorkArea.getTop() + 64) {
       mascot.setCurFC(fc);
       return getIE().getTop(mascot.getAnchor());
     }
   }
   if (getWorkArea().getBottomBorder().isOn(mascot.getAnchor())) {
     if (!ignoreSeparator || isScreenTopBottom()) {
       mascot.setCurFC(null);
       return getWorkArea().getBottomBorder();
     }
   }
   mascot.setCurFC(null);
   return NotOnBorder.INSTANCE;
 }
  /**
   * マスコットを含むスクリーンを取得する
   *
   * @return
   */
  public Area getWorkArea() {
    if (numScreens == 1) {
      if (currentWorkArea == null) {
        currentWorkArea = impl.getWorkArea();
      }
      return currentWorkArea;
    }

    // if ( currentWorkArea!=null ) {
    // NOTE Windows マルチモニタ対応 Windowsのワークエリアはメインのスクリーンより小さい。
    // 現在のスクリーンがワークエリアを含んでおり、かつマスコットがワークエリアに含まれているならばワークエリアを優先する。
    // if ( currentWorkArea!=impl.getWorkArea() &&
    // currentWorkArea.toRectangle().contains(impl.getWorkArea().toRectangle()) ) {
    // if (impl.getWorkArea().contains(mascot.getAnchor().x, mascot.getAnchor().y)) {
    // currentWorkArea = impl.getWorkArea();
    // return currentWorkArea;
    // }
    // }

    // NOTE マルチモニタ対応 マスコットが複数のモニタに同時に含まれる場合があるが、
    // その場合は現在のモニタを優先する
    // if ( currentWorkArea.contains(mascot.getAnchor().x, mascot.getAnchor().y) ) {
    // return currentWorkArea;
    // }
    // }

    // まずワークエリアに含まれているか調べる
    // if (impl.getWorkArea().contains(mascot.getAnchor().x, mascot.getAnchor().y)) {
    // currentWorkArea = impl.getWorkArea();
    // return currentWorkArea;
    // }

    // 各モニタに含まれているか調べる
    if (currentWorkArea != null) {
      if (currentWorkArea.getTopBorder().isOn(mascot.getAnchor())) {
        return currentWorkArea;
      }
    }
    int cnt = 0;
    Area a = new Area();
    for (Area area : impl.getScreens()) {
      if (area.contains(mascot.getAnchor().x, mascot.getAnchor().y)) {
        cnt++;
        a = area;
      }
    }
    if (cnt == 1) {
      currentWorkArea = a;
      return currentWorkArea;
    } else if (cnt == 2) {
      Iterator<Area> iter = impl.getScreens().iterator();
      Area temp = iter.next();
      if (!mascot.isLookRight()) {
        currentWorkArea = temp;
        return currentWorkArea;
      } else {
        currentWorkArea = iter.next();
        return currentWorkArea;
      }
    }

    if (impl.getScreens().iterator().hasNext()) {
      currentWorkArea = impl.getScreens().iterator().next();
      return currentWorkArea;
    }

    currentWorkArea = impl.getWorkArea();
    return currentWorkArea;
  }
 private boolean isScreenLeftRight(boolean b) {
   return impl.isScreenLeftRight(mascot.getAnchor(), b);
 }
 private boolean isScreenTopBottom() {
   return impl.isScreenTopBottom(mascot.getAnchor());
 }
  /*
   * 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;
  }