git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@554 72836036-5685-4462-b002-a69064685172
114 lines
2.5 KiB
Java
114 lines
2.5 KiB
Java
package jrummikub.control.network;
|
|
|
|
import jrummikub.control.RoundControl;
|
|
import jrummikub.control.turn.ITurnControl;
|
|
import jrummikub.model.IRoundState;
|
|
import jrummikub.model.ITable;
|
|
import jrummikub.model.PlayerSettings.Type;
|
|
import jrummikub.util.IListener;
|
|
import jrummikub.util.IListener1;
|
|
import jrummikub.view.IView;
|
|
|
|
public class NetworkRoundControl extends RoundControl {
|
|
private IConnectionControl connectionControl;
|
|
private boolean currentlyActive;
|
|
|
|
public NetworkRoundControl(IRoundState roundState, IView view,
|
|
final IConnectionControl connectionControl, boolean startActive) {
|
|
super(roundState, view, false);
|
|
|
|
this.connectionControl = connectionControl;
|
|
currentlyActive = startActive;
|
|
|
|
connections.add(connectionControl.getRoundStateUpdateEvent().add(
|
|
new IListener1<IRoundState>() {
|
|
@Override
|
|
public void handle(IRoundState state) {
|
|
setRoundState(state);
|
|
}
|
|
}));
|
|
connections.add(connectionControl.getTurnStartEvent().add(new IListener() {
|
|
@Override
|
|
public void handle() {
|
|
startTurn();
|
|
}
|
|
}));
|
|
connections.add(connectionControl.getNextPlayerEvent().add(new IListener() {
|
|
@Override
|
|
public void handle() {
|
|
NetworkRoundControl.super.nextPlayer();
|
|
}
|
|
}));
|
|
}
|
|
|
|
@Override
|
|
protected void addTurnControlListeners(ITurnControl turnControl) {
|
|
turnControl.getTableUpdateEvent().add(new IListener1<ITable>() {
|
|
@Override
|
|
public void handle(ITable table) {
|
|
connectionControl.updateTable(table);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
protected ITurnControl createTurnControl(Type type) {
|
|
switch (type) {
|
|
case HUMAN:
|
|
currentlyActive = true;
|
|
break;
|
|
case NETWORK:
|
|
currentlyActive = false;
|
|
break;
|
|
}
|
|
|
|
if (!currentlyActive) {
|
|
return new NetworkTurnControl(connectionControl);
|
|
}
|
|
|
|
return super.createTurnControl(type);
|
|
}
|
|
|
|
@Override
|
|
protected void prepareTurn() {
|
|
if (currentlyActive) {
|
|
connectionControl.startTurn();
|
|
}
|
|
|
|
doPrepareTurn();
|
|
}
|
|
|
|
@Override
|
|
protected void deal() {
|
|
super.deal();
|
|
|
|
if (currentlyActive) {
|
|
connectionControl.updateRoundState(roundState);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void nextPlayer() {
|
|
if (currentlyActive) {
|
|
connectionControl.nextPlayer();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void endOfTurn(InvalidTurnInfo invalidTurnInfo) {
|
|
if (currentlyActive) {
|
|
connectionControl.endTurn(roundState, invalidTurnInfo);
|
|
}
|
|
|
|
super.endOfTurn(invalidTurnInfo);
|
|
}
|
|
|
|
@Override
|
|
protected void redeal() {
|
|
if (currentlyActive) {
|
|
connectionControl.redeal();
|
|
}
|
|
|
|
super.redeal();
|
|
}
|
|
}
|