diff options
Diffstat (limited to 'src/jrummikub/control/network/GameOfferControl.java')
-rw-r--r-- | src/jrummikub/control/network/GameOfferControl.java | 94 |
1 files changed, 20 insertions, 74 deletions
diff --git a/src/jrummikub/control/network/GameOfferControl.java b/src/jrummikub/control/network/GameOfferControl.java index f0dc526..f09eb6e 100644 --- a/src/jrummikub/control/network/GameOfferControl.java +++ b/src/jrummikub/control/network/GameOfferControl.java @@ -1,41 +1,23 @@ package jrummikub.control.network; -import java.awt.Color; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.UUID; import jrummikub.model.GameSettings; import jrummikub.model.PlayerSettings; import jrummikub.model.PlayerSettings.Type; -import jrummikub.util.Connection; import jrummikub.util.GameData; -import jrummikub.util.IListener; import jrummikub.util.IListener1; -import jrummikub.util.IListener2; -import jrummikub.view.ISettingsPanel; import jrummikub.view.ISettingsPanel.SettingsMode; import jrummikub.view.IView; -public class GameOfferControl { - private List<Connection> connections = new ArrayList<Connection>(); - private GameData gameData; - private ConnectionControl connectionControl; - private IView view; +public class GameOfferControl extends AbstractGameBeginControl { public GameOfferControl(final ConnectionControl connectionControl, final GameSettings settings, final IView view) { - this.connectionControl = connectionControl; - this.view = view; - - gameData = new GameData(UUID.randomUUID(), settings); - - view.getSettingsPanel().setSettingsMode(SettingsMode.NETWORK_OFFER); - view.getSettingsPanel().enableAddPlayerButton(false); - updateSettingsPanel(settings); + super(connectionControl, view, + new GameData(UUID.randomUUID(), settings), + SettingsMode.NETWORK_OFFER); connections.add(connectionControl.getGameJoinEvent().add( new IListener1<String>() { @@ -45,7 +27,7 @@ public class GameOfferControl { if (player.getType() == Type.VACANT) { player.setName(sender); player.setType(Type.NETWORK); - updateSettingsPanel(settings); + updateSettingsPanel(); connectionControl.ackJoinGame(sender, true); connectionControl.offerGame(gameData); return; @@ -55,60 +37,24 @@ public class GameOfferControl { connectionControl.ackJoinGame(sender, false); } })); - connections.add(view.getSettingsPanel().getChangePlayerColorEvent() - .add(new IListener2<Integer, Color>() { + connections.add(connectionControl.getGameLeaveEvent().add( + new IListener1<String>() { @Override - public void handle(Integer i, Color color) { - for (PlayerSettings player : settings.getPlayerList()) { - if (player.getColor() == color) { - return; + public void handle(String sender) { + List<PlayerSettings> players = gameData + .getGameSettings().getPlayerList(); + for (PlayerSettings s : players) { + if (s.getName().equals(sender) + && s.getType() == Type.NETWORK) { + s.setType(Type.VACANT); + s.setName("Offen"); + break; } } - settings.getPlayerList().get(i).setColor(color); - updateSettingsPanel(settings); + updateSettingsPanel(); + connectionControl.offerGame(gameData); } })); - connections.add(connectionControl.getGameLeaveEvent().add(new IListener1<String>() { - @Override - public void handle(String sender) { - List<PlayerSettings> players = gameData.getGameSettings().getPlayerList(); - int index=0; - for(PlayerSettings s:players){ - if (s.getName().equals(sender)){ - break; - } - index++; - } - //Only remove network players - if(gameData.getGameSettings().getPlayerList().get(index).getType() == Type.NETWORK){ - gameData.getGameSettings().getPlayerList().get(index).setType(Type.VACANT); - gameData.getGameSettings().getPlayerList().get(index).setName("Offen"); - } - updateSettingsPanel(gameData.getGameSettings()); - connectionControl.offerGame(gameData); - - } - })); - connections.add(view.getSettingsPanel().getBackEvent().add(new IListener() { - @Override - public void handle() { - // TODO Auto-generated method stub - - } - })); - } - - private void updateSettingsPanel(GameSettings settings) { - view.getSettingsPanel().setGameSettings(settings); - - Set<Color> colors = new HashSet<Color>( - Arrays.asList(ISettingsPanel.PLAYER_COLORS)); - - for (PlayerSettings player : settings.getPlayerList()) { - colors.remove(player.getColor()); - } - - view.getSettingsPanel().setPlayerColors(colors); } public void startGameOffer() { @@ -118,7 +64,7 @@ public class GameOfferControl { } - public void abort() { - connectionControl.withdrawGame(); + protected void goBack() { + // TODO } } |