From 25c6383c73de20ce7e6bc45af6faa255e8d94dc6 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 31 May 2011 03:02:31 +0200 Subject: Allow setting stone colors to use git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@338 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/SettingsControl.java | 77 ++++++++++++++++++------------ 1 file changed, 46 insertions(+), 31 deletions(-) (limited to 'src/jrummikub/control') diff --git a/src/jrummikub/control/SettingsControl.java b/src/jrummikub/control/SettingsControl.java index fd01613..8362d52 100644 --- a/src/jrummikub/control/SettingsControl.java +++ b/src/jrummikub/control/SettingsControl.java @@ -34,9 +34,9 @@ public class SettingsControl { * Create a new settings control * * @param view - * the view to use + * the view to use * @param settings - * initial game settings + * initial game settings */ public SettingsControl(IView view, GameSettings settings) { this.view = view; @@ -46,8 +46,8 @@ public class SettingsControl { } /** - * the start game event is emitted when the user wants to start a game and - * the settings made are valid + * the start game event is emitted when the user wants to start a game and the + * settings made are valid * * @return the event */ @@ -59,9 +59,25 @@ public class SettingsControl { * Start the operation of the settings control */ public void startSettings() { + addPlayerSettingsListeners(); + + addOptionListeners1(); + addOptionListeners2(); + + connections.add(view.getSettingsPanel().getStartGameEvent() + .add(new IListener() { + @Override + public void handle() { + startGame(); + } + })); + + view.showSettingsPanel(true); + } + + private void addOptionListeners1() { connections.add(view.getSettingsPanel() - .getChangeInitialMeldThresholdEvent() - .add(new IListener1() { + .getChangeInitialMeldThresholdEvent().add(new IListener1() { @Override public void handle(Integer value) { settings.setInitialMeldThreshold(value); @@ -94,6 +110,9 @@ public class SettingsControl { update(); } })); + } + + private void addOptionListeners2() { connections.add(view.getSettingsPanel().getChangeHighestValueEvent() .add(new IListener1() { @Override @@ -110,20 +129,9 @@ public class SettingsControl { update(); } })); - - addPlayerSettingsListeners(); - - view.showSettingsPanel(true); } private void addPlayerSettingsListeners() { - connections.add(view.getSettingsPanel().getStartGameEvent() - .add(new IListener() { - @Override - public void handle() { - startGame(); - } - })); connections.add(view.getSettingsPanel().getAddPlayerEvent() .add(new IListener() { @Override @@ -193,8 +201,7 @@ public class SettingsControl { break; } - settings.getPlayerList().add( - new PlayerSettings("Spieler " + num, color)); + settings.getPlayerList().add(new PlayerSettings("Spieler " + num, color)); update(); } @@ -235,9 +242,8 @@ public class SettingsControl { private void update() { view.getSettingsPanel().enableRemovePlayerButtons( settings.getPlayerList().size() > 2); - view.getSettingsPanel() - .enableAddPlayerButton( - settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length); + view.getSettingsPanel().enableAddPlayerButton( + settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length); checkSettings(); @@ -258,9 +264,8 @@ public class SettingsControl { for (int j = i + 1; j < settings.getPlayerList().size(); ++j) { if (settings.getPlayerList().get(j).getName().equals(name)) { - view.getSettingsPanel() - .setError( - ISettingsPanel.SettingsError.DUPLICATE_PLAYER_NAME_ERROR); + view.getSettingsPanel().setError( + ISettingsPanel.SettingsError.DUPLICATE_PLAYER_NAME_ERROR); view.getSettingsPanel().enableStartGameButton(false); return false; } @@ -269,8 +274,7 @@ public class SettingsControl { int totalStonesDealt = settings.getNumberOfStonesDealt() * settings.getPlayerList().size(); - int totalStones = settings.getHighestValue() - * settings.getStoneSetNumber() + int totalStones = settings.getHighestValue() * settings.getStoneSetNumber() * settings.getStoneColors().size() + settings.getJokerNumber(); if (totalStones <= totalStonesDealt) { @@ -280,13 +284,26 @@ public class SettingsControl { return false; } + if (settings.getStoneColors().size() < 3) { + view.getSettingsPanel().setError( + ISettingsPanel.SettingsError.NOT_ENOUGH_COLORS_ERROR); + view.getSettingsPanel().enableStartGameButton(false); + return false; + } + view.getSettingsPanel().setError(ISettingsPanel.SettingsError.NO_ERROR); view.getSettingsPanel().enableStartGameButton(true); + checkWarnings(); + + return true; + } + + private void checkWarnings() { if (settings.getInitialMeldThreshold() >= 100) { view.getSettingsPanel().setError( ISettingsPanel.SettingsError.TOO_HIGH_THRESHOLD_WARNING); - return true; + return; } boolean humanPlayerFound = false; @@ -300,10 +317,8 @@ public class SettingsControl { if (!humanPlayerFound) { view.getSettingsPanel().setError( ISettingsPanel.SettingsError.COMPUTER_PLAYERS_ONLY_WARNING); - return true; + return; } - - return true; } private void startGame() { -- cgit v1.2.3