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); } } }); }
private void acceptImpl(Player player) { setStateLockedImpl(); if (hasStateChildrenImpl()) { getHandle().removeAll(); this.childGrids.clear(); this.childGrids = null; this.states = getStates() & ~States.HAS_CHILDREN; } synchronized (mutex) { this.player = player; getHandle().setImage(getImageOfPlayerImpl(player), true); boolean isGreat = isGreatParentImpl(); if (isGreat) { getGameManager().getTurnManager().endEvent().raise(eventKey, this, new EmptyEventContext()); playEvent.raise( eventKey, this, new PlayContextImpl(getGameManager().getFlagOf(player), null)); return; } PlayContextImpl context = new PlayContextImpl(getGameManager().getFlagOf(player), getCoord()); playEvent.raise(eventKey, this, context); GridCoord c = getCoord(); GridCollection.UpdateInfo ui = peerGrids.update(); Flag f = ui.getFlag(); if (f != Flag.NONE) { localEndEvent.raise(eventKey, this, new PlayContextImpl(f, c)); } } }
public GridCoord getCoord() { synchronized (mutex) { if (peerGrids == null) { throw new IllegalStateException("No coordinate - top level grid: " + this.getHandle()); } GridCoord rv = peerGrids.getCoord(this); if (rv == null) { throw new IllegalStateException("Peers do not recognized this grid"); } return rv; } }
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); } }); } }