package jrummikub.control.network; import jrummikub.control.RoundControl.InvalidTurnInfo; import jrummikub.control.turn.AbstractTurnControl; import jrummikub.model.IRoundState; import jrummikub.model.ITable; import jrummikub.util.IListener; import jrummikub.util.IListener1; import jrummikub.util.IListener2; /** * Turn control for network games */ public class NetworkTurnControl extends AbstractTurnControl { private IConnectionControl connectionControl; /** * Creates new network turn control * * @param connectionControl * the current connection control */ public NetworkTurnControl(IConnectionControl connectionControl) { this.connectionControl = connectionControl; } @Override public void doStartTurn() { connections.add(connectionControl.getTableUpdateEvent().add( new IListener1() { @Override public void handle(ITable table) { view.getTablePanel().setStoneSets(table); } })); connections.add(connectionControl.getTurnEndEvent().add( new IListener2() { @Override public void handle(IRoundState state, InvalidTurnInfo invalidTurnInfo) { endOfTurn(state, invalidTurnInfo); } })); connections.add(connectionControl.getRedealEvent().add(new IListener() { @Override public void handle() { redeal(); } })); timer.startTimer(); } private void endOfTurn(IRoundState roundState, InvalidTurnInfo invalidTurnInfo) { cleanUp(); endOfTurnEvent.emit(roundState, invalidTurnInfo); } private void redeal() { cleanUp(); redealEvent.emit(); } @Override protected void timeOut() { } }