예제 #1
0
 @SuppressWarnings("unchecked")
 public Grid<Container> getGreatParent() {
   AWTGrid rv = this;
   synchronized (mutex) {
     while (!rv.isGreatParentImpl()) {
       rv = (AWTGrid) rv.getPeers().getOwner();
     }
     return rv;
   }
 }
예제 #2
0
 @SuppressWarnings("unchecked")
 void doHierarchial(Consumer<? super AWTGrid> consumer) {
   consumer.accept(this);
   if (hasStateChildrenImpl()) {
     for (Grid g : getChildren()) {
       ((AWTGrid) g).doHierarchial(consumer);
     }
   }
 }
예제 #3
0
  private void evalutateChangeImpl(AWTGrid sender, PlayContext context) {
    if (isGreatParentImpl()) {
      return;
    }
    GridCoord coord = sender.getCoord();
    if (coord == null) {
      return;
    }
    GridCollection peers = getPeers();
    AWTGrid grid = (AWTGrid) peers.getGrid(coord);
    final boolean locked = (grid.getStates() & States.LOCKED) != 0;
    peers.forEach(
        new Consumer<Grid>() {

          @Override
          public void accept(Grid t) {
            if (t instanceof AWTGrid) {
              AWTGrid g = ((AWTGrid) t);
              g.doHierarchial(
                  new Consumer<AWTGrid>() {

                    @Override
                    public void accept(AWTGrid t) {
                      t.setStatePlayableAndFilteredImpl(locked);
                    }
                  });
            }
          }
        });
    if (!locked) {
      grid.doHierarchial(
          new Consumer<AWTGrid>() {

            @Override
            public void accept(AWTGrid t) {
              t.setStatePlayableAndFilteredImpl(true);
            }
          });
    }
  }
예제 #4
0
  void generateChildrenImpl(final int depth) {
    if (depth == 0) return;
    setStateOnlyNonPlayableImpl(false);
    childGrids = new GridCollection(this);
    states |= States.HAS_CHILDREN;
    ChangeBlockListener evtChange = new ChangeBlockListener();
    PlayListener evtPlay = new PlayListener();
    EndListener evtEnd = new EndListener();
    final int size = getHandle().getWidth() / GridConsts.DIMENSION;
    for (int i = 0; i < GridConsts.DIMENSION; ++i) {
      for (int j = 0; j < GridConsts.DIMENSION; ++j) {
        AWTGrid g = new AWTGrid(getGameManager(), eventKey);
        AWTGridHandle h = g.getHandle();
        h.setSize(size);
        h.setLocation(i * size, j * size);
        addImpl(g);
        g.changeBlockEvent().addListener(evtChange);
        g.playEvent().addListener(evtPlay);
        g.endEvent().addListener(evtEnd);
        g.peerGrids = childGrids;
        childGrids.putGrid(new GridCoord(i, j), g);
      }
    }
    childGrids.forEach(
        new Consumer<Grid>() {

          public void accept(Grid t) {
            if (t instanceof AWTGrid) {
              ((AWTGrid) t).generateChildrenImpl(depth - 1);
            }
          }
        });
  }
예제 #5
0
 private void addImpl(AWTGrid g) {
   getHandle().add(g.getHandle());
 }