Fix network mode
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@521 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
2f08091b65
commit
0b1151e6af
5 changed files with 117 additions and 6 deletions
|
@ -44,6 +44,10 @@ public class MockConnectionControl implements IConnectionControl {
|
||||||
/** */
|
/** */
|
||||||
public MockEvent2<IRoundState, InvalidTurnInfo> turnEndEvent = new MockEvent2<IRoundState, InvalidTurnInfo>();
|
public MockEvent2<IRoundState, InvalidTurnInfo> turnEndEvent = new MockEvent2<IRoundState, InvalidTurnInfo>();
|
||||||
/** */
|
/** */
|
||||||
|
public MockEvent1<IRoundState> roundStateUpdateEvent = new MockEvent1<IRoundState>();
|
||||||
|
/** */
|
||||||
|
public MockEvent nextPlayerEvent = new MockEvent();
|
||||||
|
/** */
|
||||||
public MockEvent turnStartEvent = new MockEvent();
|
public MockEvent turnStartEvent = new MockEvent();
|
||||||
/** */
|
/** */
|
||||||
public GameData currentGame;
|
public GameData currentGame;
|
||||||
|
@ -147,6 +151,16 @@ public class MockConnectionControl implements IConnectionControl {
|
||||||
return turnStartEvent;
|
return turnStartEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IEvent1<IRoundState> getRoundStateUpdateEvent() {
|
||||||
|
return roundStateUpdateEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IEvent getNextPlayerEvent() {
|
||||||
|
return nextPlayerEvent;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void offerGame(GameData data) {
|
public void offerGame(GameData data) {
|
||||||
offeredGame = data;
|
offeredGame = data;
|
||||||
|
@ -217,4 +231,16 @@ public class MockConnectionControl implements IConnectionControl {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateRoundState(IRoundState roundState) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void nextPlayer() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -264,7 +264,7 @@ public class RoundControl {
|
||||||
return TurnControlFactory.getFactory(type).create();
|
return TurnControlFactory.getFactory(type).create();
|
||||||
}
|
}
|
||||||
|
|
||||||
void deal() {
|
protected void deal() {
|
||||||
for (int i = 0; i < roundState.getPlayerCount(); i++) {
|
for (int i = 0; i < roundState.getPlayerCount(); i++) {
|
||||||
IHand hand = roundState.getNthNextPlayer(i).getHand();
|
IHand hand = roundState.getNthNextPlayer(i).getHand();
|
||||||
for (int j = 0; j < roundState.getGameSettings().getNumberOfStonesDealt(); j++) {
|
for (int j = 0; j < roundState.getGameSettings().getNumberOfStonesDealt(); j++) {
|
||||||
|
@ -276,8 +276,9 @@ public class RoundControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void endOfTurn(InvalidTurnInfo invalidTurnInfo) {
|
protected void endOfTurn(InvalidTurnInfo invalidTurnInfo) {
|
||||||
boolean wasHuman = (turnControl instanceof HumanTurnControl);
|
boolean wasAI = turnControl instanceof AIControl;
|
||||||
boolean wasAI = (turnControl instanceof AIControl);
|
boolean wasHuman = turnControl instanceof HumanTurnControl;
|
||||||
|
|
||||||
turnControl = null;
|
turnControl = null;
|
||||||
|
|
||||||
view.getTablePanel().setStoneSets(invalidTurnInfo.getTable());
|
view.getTablePanel().setStoneSets(invalidTurnInfo.getTable());
|
||||||
|
@ -314,10 +315,13 @@ public class RoundControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
view.setBottomPanel(BottomPanelType.NONHUMAN_HAND_PANEL);
|
view.setBottomPanel(BottomPanelType.NONHUMAN_HAND_PANEL);
|
||||||
nextPlayer();
|
|
||||||
|
if (wasHuman || wasAI) {
|
||||||
|
nextPlayer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void nextPlayer() {
|
protected void nextPlayer() {
|
||||||
view.setSelectedStones(Collections.<Stone> emptyList());
|
view.setSelectedStones(Collections.<Stone> emptyList());
|
||||||
view.setInvalidStoneSets(Collections.<StoneSet> emptyList());
|
view.setInvalidStoneSets(Collections.<StoneSet> emptyList());
|
||||||
view.setStoneCollectionHidden(false);
|
view.setStoneCollectionHidden(false);
|
||||||
|
|
|
@ -85,9 +85,11 @@ public class ConnectionControl implements IConnectionControl {
|
||||||
|
|
||||||
private Event gameStartEvent = new Event();
|
private Event gameStartEvent = new Event();
|
||||||
private Event roundStartEvent = new Event();
|
private Event roundStartEvent = new Event();
|
||||||
|
private Event1<IRoundState> roundStateUpdateEvent = new Event1<IRoundState>();
|
||||||
|
|
||||||
private Event1<ITable> tableUpdateEvent = new Event1<ITable>();
|
private Event1<ITable> tableUpdateEvent = new Event1<ITable>();
|
||||||
private Event2<IRoundState, InvalidTurnInfo> turnEndEvent = new Event2<IRoundState, InvalidTurnInfo>();
|
private Event2<IRoundState, InvalidTurnInfo> turnEndEvent = new Event2<IRoundState, InvalidTurnInfo>();
|
||||||
|
private Event nextPlayerEvent = new Event();
|
||||||
private Event turnStartEvent = new Event();
|
private Event turnStartEvent = new Event();
|
||||||
|
|
||||||
private GameData currentGame;
|
private GameData currentGame;
|
||||||
|
@ -181,6 +183,11 @@ public class ConnectionControl implements IConnectionControl {
|
||||||
return roundStartEvent;
|
return roundStartEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IEvent1<IRoundState> getRoundStateUpdateEvent() {
|
||||||
|
return roundStateUpdateEvent;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEvent1<ITable> getTableUpdateEvent() {
|
public IEvent1<ITable> getTableUpdateEvent() {
|
||||||
return tableUpdateEvent;
|
return tableUpdateEvent;
|
||||||
|
@ -191,6 +198,11 @@ public class ConnectionControl implements IConnectionControl {
|
||||||
return turnEndEvent;
|
return turnEndEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IEvent getNextPlayerEvent() {
|
||||||
|
return nextPlayerEvent;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEvent getTurnStartEvent() {
|
public IEvent getTurnStartEvent() {
|
||||||
return turnStartEvent;
|
return turnStartEvent;
|
||||||
|
@ -312,6 +324,20 @@ public class ConnectionControl implements IConnectionControl {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateRoundState(final IRoundState roundState) {
|
||||||
|
final UUID uuid = currentGame.getGameID();
|
||||||
|
run(new SendRunner() {
|
||||||
|
@Override
|
||||||
|
protected void addData(DefaultPacketExtension extension) {
|
||||||
|
extension.setValue("messageType", "round_state_update");
|
||||||
|
extension.setValue("uuid", uuid.toString());
|
||||||
|
extension.setValue("state",
|
||||||
|
Base64.encodeObject(roundState, Base64.GZIP));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateTable(final ITable table) {
|
public void updateTable(final ITable table) {
|
||||||
final UUID uuid = currentGame.getGameID();
|
final UUID uuid = currentGame.getGameID();
|
||||||
|
@ -340,6 +366,18 @@ public class ConnectionControl implements IConnectionControl {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void nextPlayer() {
|
||||||
|
final UUID uuid = currentGame.getGameID();
|
||||||
|
run(new SendRunner() {
|
||||||
|
@Override
|
||||||
|
protected void addData(DefaultPacketExtension extension) {
|
||||||
|
extension.setValue("messageType", "next_player");
|
||||||
|
extension.setValue("uuid", uuid.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startTurn() {
|
public void startTurn() {
|
||||||
final UUID uuid = currentGame.getGameID();
|
final UUID uuid = currentGame.getGameID();
|
||||||
|
@ -459,6 +497,9 @@ public class ConnectionControl implements IConnectionControl {
|
||||||
gameStartEvent.emit();
|
gameStartEvent.emit();
|
||||||
} else if (messageType.equals("round_start")) {
|
} else if (messageType.equals("round_start")) {
|
||||||
roundStartEvent.emit();
|
roundStartEvent.emit();
|
||||||
|
} else if (messageType.equals("round_state_update")) {
|
||||||
|
roundStateUpdateEvent.emit((IRoundState) Base64.decodeToObject(extension
|
||||||
|
.getValue("state")));
|
||||||
} else if (messageType.equals("table_update")) {
|
} else if (messageType.equals("table_update")) {
|
||||||
tableUpdateEvent.emit((ITable) Base64.decodeToObject(extension
|
tableUpdateEvent.emit((ITable) Base64.decodeToObject(extension
|
||||||
.getValue("table")));
|
.getValue("table")));
|
||||||
|
@ -466,6 +507,8 @@ public class ConnectionControl implements IConnectionControl {
|
||||||
TurnEndData data = (TurnEndData) Base64.decodeToObject(extension
|
TurnEndData data = (TurnEndData) Base64.decodeToObject(extension
|
||||||
.getValue("data"));
|
.getValue("data"));
|
||||||
turnEndEvent.emit(data.getRoundState(), data.getInvalidTurnInfo());
|
turnEndEvent.emit(data.getRoundState(), data.getInvalidTurnInfo());
|
||||||
|
} else if (messageType.equals("next_player")) {
|
||||||
|
nextPlayerEvent.emit();
|
||||||
} else if (messageType.equals("turn_start")) {
|
} else if (messageType.equals("turn_start")) {
|
||||||
turnStartEvent.emit();
|
turnStartEvent.emit();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -40,10 +40,14 @@ interface IConnectionControl {
|
||||||
|
|
||||||
public IEvent getRoundStartEvent();
|
public IEvent getRoundStartEvent();
|
||||||
|
|
||||||
|
public IEvent1<IRoundState> getRoundStateUpdateEvent();
|
||||||
|
|
||||||
public IEvent1<ITable> getTableUpdateEvent();
|
public IEvent1<ITable> getTableUpdateEvent();
|
||||||
|
|
||||||
public IEvent2<IRoundState, InvalidTurnInfo> getTurnEndEvent();
|
public IEvent2<IRoundState, InvalidTurnInfo> getTurnEndEvent();
|
||||||
|
|
||||||
|
public IEvent getNextPlayerEvent();
|
||||||
|
|
||||||
public IEvent getTurnStartEvent();
|
public IEvent getTurnStartEvent();
|
||||||
|
|
||||||
public void offerGame(GameData data);
|
public void offerGame(GameData data);
|
||||||
|
@ -66,10 +70,13 @@ interface IConnectionControl {
|
||||||
|
|
||||||
public void startRound();
|
public void startRound();
|
||||||
|
|
||||||
|
public void updateRoundState(IRoundState roundState);
|
||||||
|
|
||||||
public void updateTable(ITable table);
|
public void updateTable(ITable table);
|
||||||
|
|
||||||
public void endTurn(IRoundState state, InvalidTurnInfo invalidTurnInfo);
|
public void endTurn(IRoundState state, InvalidTurnInfo invalidTurnInfo);
|
||||||
|
|
||||||
public void startTurn();
|
public void nextPlayer();
|
||||||
|
|
||||||
|
public void startTurn();
|
||||||
}
|
}
|
|
@ -20,12 +20,27 @@ public class NetworkRoundControl extends RoundControl {
|
||||||
this.connectionControl = connectionControl;
|
this.connectionControl = connectionControl;
|
||||||
currentlyActive = startActive;
|
currentlyActive = startActive;
|
||||||
|
|
||||||
|
connections.add(connectionControl.getRoundStateUpdateEvent().add(
|
||||||
|
new IListener1<IRoundState>() {
|
||||||
|
@Override
|
||||||
|
public void handle(IRoundState state) {
|
||||||
|
NetworkControl.fixGameSettings(state.getGameSettings(),
|
||||||
|
connectionControl.getNickname());
|
||||||
|
setRoundState(state);
|
||||||
|
}
|
||||||
|
}));
|
||||||
connections.add(connectionControl.getTurnStartEvent().add(new IListener() {
|
connections.add(connectionControl.getTurnStartEvent().add(new IListener() {
|
||||||
@Override
|
@Override
|
||||||
public void handle() {
|
public void handle() {
|
||||||
startTurn();
|
startTurn();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
connections.add(connectionControl.getNextPlayerEvent().add(new IListener() {
|
||||||
|
@Override
|
||||||
|
public void handle() {
|
||||||
|
NetworkRoundControl.super.nextPlayer();
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -67,6 +82,22 @@ public class NetworkRoundControl extends RoundControl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void deal() {
|
||||||
|
super.deal();
|
||||||
|
|
||||||
|
if (currentlyActive) {
|
||||||
|
connectionControl.updateRoundState(roundState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void nextPlayer() {
|
||||||
|
if (currentlyActive) {
|
||||||
|
connectionControl.nextPlayer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void endOfTurn(InvalidTurnInfo invalidTurnInfo) {
|
protected void endOfTurn(InvalidTurnInfo invalidTurnInfo) {
|
||||||
if (currentlyActive) {
|
if (currentlyActive) {
|
||||||
|
|
Reference in a new issue