/** * A player can only select certain pits for their move. That's why some have to be enabled and * some have to be disabled before a player's turn. */ @Override public void setPitEnabled(PlayerColor side, int col, boolean enabled) { AbsolutePanel pnl; if (col < 6) { if (side.isNorth()) { pnl = (AbsolutePanel) gameGrid.getWidget(0, State.getMirrorIndex(col, 5)); } else if (side.isSouth()) { pnl = (AbsolutePanel) gameGrid.getWidget(1, col); } else throw new IllegalMoveException(); final int colB = col; int row = side.isNorth() ? 0 : 1; if (enabled) { // the handerRegs keeps track of all click handlers of the pits // by removing it from this array the handler is removed from // the pit (absolutePanel) as well handlerRegs[row][col].removeHandler(); handlerRegs[row][col] = pnl.addDomHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { presenter.makeMove(colB); } }, ClickEvent.getType()); } else { handlerRegs[row][col].removeHandler(); handlerRegs[row][col] = pnl.addDomHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { setWarnLabelText(messages.warnMessage()); } }, ClickEvent.getType()); } } }
/** The seedAmount will be placed on the right side at the correct index */ @Override public void setSeeds(PlayerColor side, int col, int seedAmount) { if (col < 6) { AbsolutePanel pnl; if (side.isNorth()) { pnl = (AbsolutePanel) gameGrid.getWidget(0, State.getMirrorIndex(col, 5)); } else if (side.isSouth()) { pnl = (AbsolutePanel) gameGrid.getWidget(1, col); } else throw new IllegalMoveException(); addSeeds(pnl, seedAmount); } else if (col == 6) { AbsolutePanel pnl; if (side.isNorth()) { pnl = (AbsolutePanel) treasureGridN.getWidget(0, 0); } else if (side.isSouth()) { pnl = (AbsolutePanel) treasureGridS.getWidget(0, 0); } else throw new IllegalMoveException(); addSeedsToTreasureChest(pnl, seedAmount); } else throw new IllegalMoveException(); }