package jrummikub.control.network; import java.util.Date; import jrummikub.control.RoundControl.InvalidTurnInfo; import jrummikub.control.turn.AbstractTurnControl; import jrummikub.model.IRoundState; import jrummikub.model.ITable; import jrummikub.util.Event1; import jrummikub.util.IEvent1; import jrummikub.util.IListener1; import jrummikub.util.IListener2; public class NetworkTurnControl extends AbstractTurnControl { private IConnectionControl connectionControl; private Event1 stateUpdateEvent = new Event1(); public NetworkTurnControl(IConnectionControl connectionControl) { this.connectionControl = connectionControl; } public IEvent1 getStateUpdateEvent() { return stateUpdateEvent; } @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) { System.err.println(new Date() + ": Received endTurn"); NetworkControl.fixGameSettings(state.getGameSettings(), connectionControl.getNickname()); endOfTurn(state, invalidTurnInfo); } })); timer.startTimer(); } private void endOfTurn(IRoundState roundState, InvalidTurnInfo invalidTurnInfo) { cleanUp(); endOfTurnEvent.emit(roundState, invalidTurnInfo); } @Override protected void timeOut() { } @Override protected void pauseTurn() { } }