summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/control/network')
-rw-r--r--src/jrummikub/control/network/GameOfferControl.java33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/jrummikub/control/network/GameOfferControl.java b/src/jrummikub/control/network/GameOfferControl.java
index b513170..c697647 100644
--- a/src/jrummikub/control/network/GameOfferControl.java
+++ b/src/jrummikub/control/network/GameOfferControl.java
@@ -12,6 +12,7 @@ import jrummikub.util.GameData;
import jrummikub.util.IEvent1;
import jrummikub.util.IListener;
import jrummikub.util.IListener1;
+import jrummikub.view.ISettingsPanel.SettingsError;
import jrummikub.view.ISettingsPanel.SettingsMode;
import jrummikub.view.IView;
@@ -44,19 +45,31 @@ public class GameOfferControl extends AbstractGameBeginControl {
public void handle() {
List<PlayerSettings> players = gameData.getGameSettings()
.getPlayerList();
- for (PlayerSettings s : players) {
- if (s.getType() == Type.NETWORK) {
- startGame();
- return;
- }
+ if (checkPlayers()) {
+ startGame();
}
}
}));
+
+ checkPlayers();
+ }
+
+ private boolean checkPlayers() {
+ for (PlayerSettings s : gameData.getGameSettings().getPlayerList()) {
+ if (s.getType() == Type.NETWORK) {
+ view.getSettingsPanel().setError(SettingsError.NO_ERROR);
+ view.getSettingsPanel().enableStartGameButton(true);
+ return true;
+ }
+ }
+
+ view.getSettingsPanel().setError(SettingsError.WAITING_FOR_PLAYERS);
+ view.getSettingsPanel().enableStartGameButton(false);
+ return false;
}
private void addConnectionControlListeners(
- final IConnectionControl connectionControl,
- final GameSettings settings) {
+ final IConnectionControl connectionControl, final GameSettings settings) {
connections.add(connectionControl.getGameJoinEvent().add(
new IListener1<String>() {
@Override
@@ -65,7 +78,10 @@ public class GameOfferControl extends AbstractGameBeginControl {
if (player.getType() == Type.VACANT) {
player.setName(sender);
player.setType(Type.NETWORK);
+
updateSettingsPanel();
+ checkPlayers();
+
connectionControl.ackJoinGame(sender, true);
connectionControl.offerGame(gameData);
return;
@@ -88,7 +104,10 @@ public class GameOfferControl extends AbstractGameBeginControl {
break;
}
}
+
updateSettingsPanel();
+ checkPlayers();
+
connectionControl.offerGame(gameData);
}
}));