summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorIda Massow <massow@informatik.uni-luebeck.de>2011-06-18 16:19:20 +0200
committerIda Massow <massow@informatik.uni-luebeck.de>2011-06-18 16:19:20 +0200
commitac3c13c50b87abfc6e4959fabd5107990d1eb417 (patch)
tree6457f708d25e751dea1da503df77c0f74d4d30fa /src
parentbc835d499f2fe3c8b9c5b6bc9cfca9d9666854e9 (diff)
downloadJRummikub-ac3c13c50b87abfc6e4959fabd5107990d1eb417.tar
JRummikub-ac3c13c50b87abfc6e4959fabd5107990d1eb417.zip
Ca. 150 Zeilen überflüssigen Code entfernt
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@463 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src')
-rw-r--r--src/jrummikub/control/network/AbstractGameBeginControl.java67
-rw-r--r--src/jrummikub/control/network/ConnectionControl.java33
-rw-r--r--src/jrummikub/control/turn/AIControl.java71
3 files changed, 108 insertions, 63 deletions
diff --git a/src/jrummikub/control/network/AbstractGameBeginControl.java b/src/jrummikub/control/network/AbstractGameBeginControl.java
index 598126a..fd3b546 100644
--- a/src/jrummikub/control/network/AbstractGameBeginControl.java
+++ b/src/jrummikub/control/network/AbstractGameBeginControl.java
@@ -18,6 +18,10 @@ import jrummikub.view.ISettingsPanel;
import jrummikub.view.ISettingsPanel.SettingsMode;
import jrummikub.view.IView;
+/**
+ * Abstract class for network game controls inbetween choosing and starting a
+ * game
+ */
public abstract class AbstractGameBeginControl {
protected List<Connection> connections = new ArrayList<Connection>();
protected GameData gameData;
@@ -25,6 +29,18 @@ public abstract class AbstractGameBeginControl {
protected IView view;
protected Event backEvent = new Event();
+ /**
+ * Create a new game begin control
+ *
+ * @param connection
+ * connection control for mesages and events
+ * @param view
+ * the view
+ * @param gameData
+ * game data of chosen game
+ * @param settingsMode
+ * mode of settings panel
+ */
public AbstractGameBeginControl(IConnectionControl connection, IView view,
final GameData gameData, SettingsMode settingsMode) {
this.connectionControl = connection;
@@ -35,8 +51,29 @@ public abstract class AbstractGameBeginControl {
view.getSettingsPanel().enableAddPlayerButton(false);
updateSettingsPanel();
- connections.add(view.getSettingsPanel().getBackEvent()
- .add(new IListener() {
+ addViewListeners(view, gameData);
+
+ connections.add(connectionControl.getChangeColorEvent().add(
+ new IListener2<String, Color>() {
+ @Override
+ public void handle(String sender, Color color) {
+ List<PlayerSettings> players = gameData
+ .getGameSettings().getPlayerList();
+ for (PlayerSettings s : players) {
+ if (s.getName().equals(sender)
+ && s.getType() == Type.NETWORK) {
+ s.setColor(color);
+ break;
+ }
+ }
+ updateSettingsPanel();
+ }
+ }));
+ }
+
+ private void addViewListeners(IView view, final GameData gameData) {
+ connections.add(view.getSettingsPanel().getBackEvent().add(
+ new IListener() {
@Override
public void handle() {
goBack();
@@ -62,26 +99,16 @@ public abstract class AbstractGameBeginControl {
updateSettingsPanel();
}
}));
- connections.add(connectionControl.getChangeColorEvent().add(
- new IListener2<String, Color>() {
- @Override
- public void handle(String sender, Color color) {
- List<PlayerSettings> players = gameData
- .getGameSettings().getPlayerList();
- for (PlayerSettings s : players) {
- if (s.getName().equals(sender)
- && s.getType() == Type.NETWORK) {
- s.setColor(color);
- break;
- }
- }
- updateSettingsPanel();
- }
- }));
}
protected abstract void goBack();
+ /**
+ * The back event is emitted when the player wants to go back to the
+ * previous control and panel
+ *
+ * @return the event
+ */
public Event getBackEvent() {
return backEvent;
}
@@ -96,8 +123,8 @@ public abstract class AbstractGameBeginControl {
protected void updateSettingsPanel() {
view.getSettingsPanel().setGameSettings(gameData.getGameSettings());
- Set<Color> colors = new HashSet<Color>(
- Arrays.asList(ISettingsPanel.PLAYER_COLORS));
+ Set<Color> colors = new HashSet<Color>(Arrays
+ .asList(ISettingsPanel.PLAYER_COLORS));
for (PlayerSettings player : gameData.getGameSettings().getPlayerList()) {
colors.remove(player.getColor());
diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java
index 28684b2..e435309 100644
--- a/src/jrummikub/control/network/ConnectionControl.java
+++ b/src/jrummikub/control/network/ConnectionControl.java
@@ -323,20 +323,25 @@ class ConnectionControl implements IConnectionControl {
if (!currentGame.getGameID().equals(uuid)) {
return;
}
- if (messageType.equals("game_join")) {
- gameJoinEvent.emit(sender);
- } else if (messageType.equals("game_leave")) {
- gameLeaveEvent.emit(sender);
- } else if (messageType.equals("game_join_ack")) {
- gameJoinAckEvent
- .emit(Boolean.valueOf(extension.getValue("ack")));
- } else if (messageType.equals("change_color")) {
- changeColorEvent.emit(sender, (Color) Base64
- .decodeToObject(extension.getValue("color")));
- } else {
- System.err.println("Received unrecognized message of type '"
- + messageType + "'");
- }
+ messagesDuringGame(extension, sender, messageType);
+ }
+ }
+
+ private void messagesDuringGame(DefaultPacketExtension extension,
+ String sender, String messageType) {
+ if (messageType.equals("game_join")) {
+ gameJoinEvent.emit(sender);
+ } else if (messageType.equals("game_leave")) {
+ gameLeaveEvent.emit(sender);
+ } else if (messageType.equals("game_join_ack")) {
+ gameJoinAckEvent
+ .emit(Boolean.valueOf(extension.getValue("ack")));
+ } else if (messageType.equals("change_color")) {
+ changeColorEvent.emit(sender, (Color) Base64
+ .decodeToObject(extension.getValue("color")));
+ } else {
+ System.err.println("Received unrecognized message of type '"
+ + messageType + "'");
}
}
diff --git a/src/jrummikub/control/turn/AIControl.java b/src/jrummikub/control/turn/AIControl.java
index 324c8d7..7784d7f 100644
--- a/src/jrummikub/control/turn/AIControl.java
+++ b/src/jrummikub/control/turn/AIControl.java
@@ -85,17 +85,9 @@ public class AIControl extends AbstractTurnControl {
List<Stone> tableStones = new ArrayList<Stone>();
List<Stone> handStones = new ArrayList<Stone>();
- for (Pair<Stone, Position> entry : turnInfo.getHand()) {
- handStones.add(entry.getFirst());
- }
+ addHandStones(handStones);
- if (turnInfo.getLaidOut()) {
- for (Pair<StoneSet, Position> entry : turnInfo.getTable()) {
- for (Stone stone : entry.getFirst()) {
- tableStones.add(stone);
- }
- }
- }
+ addTableStones(tableStones);
logic = new TurnLogic(settings, tableStones, handStones);
@@ -133,6 +125,22 @@ public class AIControl extends AbstractTurnControl {
}
+ private void addHandStones(List<Stone> handStones) {
+ for (Pair<Stone, Position> entry : turnInfo.getHand()) {
+ handStones.add(entry.getFirst());
+ }
+ }
+
+ private void addTableStones(List<Stone> tableStones) {
+ if (turnInfo.getLaidOut()) {
+ for (Pair<StoneSet, Position> entry : turnInfo.getTable()) {
+ for (Stone stone : entry.getFirst()) {
+ tableStones.add(stone);
+ }
+ }
+ }
+ }
+
private void executeTurn() {
if (turnDone) {
return;
@@ -143,25 +151,7 @@ public class AIControl extends AbstractTurnControl {
if (result != null) {
if (turnInfo.getLaidOut()) {
- outerLoop: for (Iterator<Pair<StoneSet, Position>> it = turnInfo
- .getTable().iterator(); it.hasNext();) {
- Pair<StoneSet, Position> pair = it.next();
- setSearch: for (Iterator<StoneSet> it2 = result.iterator(); it2
- .hasNext();) {
- StoneSet set = it2.next();
- if (set.getSize() != pair.getFirst().getSize()) {
- continue;
- }
- for (int i = 0; i < set.getSize(); i++) {
- if (set.get(i) != pair.getFirst().get(i)) {
- continue setSearch;
- }
- }
- it2.remove();
- continue outerLoop;
- }
- it.remove();
- }
+ doNotMoveExistingSets(result);
}
for (StoneSet set : result) {
@@ -178,6 +168,29 @@ public class AIControl extends AbstractTurnControl {
emitEndOfTurn();
}
+ private void doNotMoveExistingSets(List<StoneSet> result) {
+
+ outerLoop: for (Iterator<Pair<StoneSet, Position>> it = turnInfo
+ .getTable().iterator(); it.hasNext();) {
+ Pair<StoneSet, Position> pair = it.next();
+ setSearch: for (Iterator<StoneSet> it2 = result.iterator(); it2
+ .hasNext();) {
+ StoneSet set = it2.next();
+ if (set.getSize() != pair.getFirst().getSize()) {
+ continue;
+ }
+ for (int i = 0; i < set.getSize(); i++) {
+ if (set.get(i) != pair.getFirst().get(i)) {
+ continue setSearch;
+ }
+ }
+ it2.remove();
+ continue outerLoop;
+ }
+ it.remove();
+ }
+ }
+
/**
* Get the factory for the base AI control
*