diff options
author | Ida Massow <massow@informatik.uni-luebeck.de> | 2011-05-10 03:13:11 +0200 |
---|---|---|
committer | Ida Massow <massow@informatik.uni-luebeck.de> | 2011-05-10 03:13:11 +0200 |
commit | a64492dc4b7a08f0d976da10e2da455c20767fd5 (patch) | |
tree | 351699cf01d288d66a0e537bc111fcc37505aa1b /src/jrummikub | |
parent | b14a707d4fca0560437189fecce93cf21c38cbf6 (diff) | |
download | JRummikub-a64492dc4b7a08f0d976da10e2da455c20767fd5.tar JRummikub-a64492dc4b7a08f0d976da10e2da455c20767fd5.zip |
WinPanel funktioniert und ist getestet und überhaupt ist alles ganz toll
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@211 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub')
-rw-r--r-- | src/jrummikub/JRummikub.java | 10 | ||||
-rw-r--r-- | src/jrummikub/control/GameControl.java | 59 | ||||
-rw-r--r-- | src/jrummikub/control/RoundControl.java | 40 | ||||
-rw-r--r-- | src/jrummikub/control/TurnControl.java | 6 |
4 files changed, 93 insertions, 22 deletions
diff --git a/src/jrummikub/JRummikub.java b/src/jrummikub/JRummikub.java index d02f4c8..e9fd9dd 100644 --- a/src/jrummikub/JRummikub.java +++ b/src/jrummikub/JRummikub.java @@ -2,8 +2,7 @@ package jrummikub; import javax.swing.UIManager; -import jrummikub.control.RoundControl; -import jrummikub.model.GameState; +import jrummikub.control.GameControl; import jrummikub.view.impl.View; /** @@ -15,7 +14,7 @@ public class JRummikub { * The main method * * @param args - * command line arguments + * command line arguments */ public static void main(String[] args) { String nativeLF = UIManager.getSystemLookAndFeelClassName(); @@ -25,11 +24,10 @@ public class JRummikub { } catch (Exception e) { } - GameState gameState = new GameState(); View view = new View(); - RoundControl roundControl = new RoundControl(gameState, view); - roundControl.startRound(); + GameControl gameControl = new GameControl(view); + gameControl.startGame(); } diff --git a/src/jrummikub/control/GameControl.java b/src/jrummikub/control/GameControl.java new file mode 100644 index 0000000..ee87bd5 --- /dev/null +++ b/src/jrummikub/control/GameControl.java @@ -0,0 +1,59 @@ +package jrummikub.control; + +import jrummikub.model.GameState; +import jrummikub.util.IListener; +import jrummikub.view.IView; + +public class GameControl { + final static int HAND_HEIGHT = 2; + final static int HAND_WIDTH = 14; + private IView view; + private RoundControl roundControl; + + public GameControl(IView view) { + this.view = view; + view.getPlayerPanel().getHandPanel().setHandHeight(HAND_HEIGHT); + view.getPlayerPanel().getHandPanel().setHandWidth(HAND_WIDTH); + + view.getNewGameEvent().add(new IListener() { + @Override + public void handle() { + startRound(); + } + }); + view.getQuitEvent().add(new IListener() { + @Override + public void handle() { + quitProgram(); + } + }); + } + + public void startGame() { + startRound(); + } + + private void startRound() { + if (roundControl != null) { + return; + } + + GameState gameState = new GameState(); + + roundControl = new RoundControl(gameState, view); + roundControl.getEndRoundEvent().add(new IListener() { + + @Override + public void handle() { + roundControl = null; + } + }); + + roundControl.startRound(); + } + + private void quitProgram() { + System.exit(0); + } + +} diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java index f536acc..63accaa 100644 --- a/src/jrummikub/control/RoundControl.java +++ b/src/jrummikub/control/RoundControl.java @@ -1,6 +1,8 @@ package jrummikub.control; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.Set; import jrummikub.model.IGameState; @@ -9,35 +11,39 @@ import jrummikub.model.ITable; import jrummikub.model.Position; import jrummikub.model.Stone; import jrummikub.model.StoneSet; +import jrummikub.util.Connection; +import jrummikub.util.Event; +import jrummikub.util.IEvent; import jrummikub.util.IListener; import jrummikub.util.Pair; import jrummikub.view.IView; public class RoundControl { - // TODO move to game control once existent - final static int HAND_HEIGHT = 2; - final static int HAND_WIDTH = 14; private IGameState gameState; private IView view; private ITable clonedTable; + private Event endRoundEvent = new Event(); + private List<Connection> connections = new ArrayList<Connection>(); public RoundControl(IGameState gameState, IView view) { this.gameState = gameState; this.view = view; - view.getPlayerPanel().getHandPanel().setHandHeight(HAND_HEIGHT); - view.getPlayerPanel().getHandPanel().setHandWidth(HAND_WIDTH); + } + + public IEvent getEndRoundEvent() { + return endRoundEvent; } public void startRound() { deal(); - view.getStartTurnEvent().add(new IListener() { + connections.add(view.getStartTurnEvent().add(new IListener() { @Override public void handle() { startTurn(); } - }); + })); prepareTurn(); } @@ -58,13 +64,13 @@ public class RoundControl { private void startTurn() { TurnControl turnControl = new TurnControl(gameState.getActivePlayer() .getHand(), clonedTable, view); - turnControl.getEndOfTurnEvent().add(new IListener() { + connections.add(turnControl.getEndOfTurnEvent().add(new IListener() { @Override public void handle() { endOfTurn(); } - }); + })); turnControl.startTurn(); } @@ -73,14 +79,17 @@ public class RoundControl { for (int i = 0; i < gameState.getPlayerCount(); i++) { IHand hand = gameState.getNthNextPlayer(i).getHand(); for (int j = 0; j < 7; j++) { - hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 0)); - hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 1)); + hand.drop(gameState.getGameHeap().drawStone(), new Position(j, + 0)); + hand.drop(gameState.getGameHeap().drawStone(), new Position(j, + 1)); } } } private void endOfTurn() { - Set<Stone> tableDiff = tableDifference(gameState.getTable(), clonedTable); + Set<Stone> tableDiff = tableDifference(gameState.getTable(), + clonedTable); if (!tableDiff.isEmpty()) { // Player has made a move if (clonedTable.isValid()) { @@ -128,7 +137,8 @@ public class RoundControl { .getActivePlayer() .getHand() .drop(gameState.getGameHeap().drawStone(), - new Position(HAND_WIDTH - 1, HAND_HEIGHT - 1)); + new Position(GameControl.HAND_WIDTH - 1, + GameControl.HAND_HEIGHT - 1)); } private void dealPenalty(int count) { @@ -137,6 +147,10 @@ public class RoundControl { } private void win() { + for (Connection c : connections) { + c.remove(); + } + endRoundEvent.emit(); view.enableWinPanel(true); } } diff --git a/src/jrummikub/control/TurnControl.java b/src/jrummikub/control/TurnControl.java index 632c3ee..32e6379 100644 --- a/src/jrummikub/control/TurnControl.java +++ b/src/jrummikub/control/TurnControl.java @@ -30,7 +30,7 @@ public class TurnControl { private List<Stone> selectedStones = new ArrayList<Stone>(); private Event endOfTurnEvent = new Event(); - List<Connection> connections = new ArrayList<Connection>(); + private List<Connection> connections = new ArrayList<Connection>(); public TurnControl(IHand hand, ITable table, IView view) { this.hand = hand; @@ -203,11 +203,11 @@ public class TurnControl { for (Stone stone : stones) { hand.drop(stone, new Position(x, y)); x++; - if (x >= RoundControl.HAND_WIDTH) { + if (x >= GameControl.HAND_WIDTH) { x = 0; y++; - if (y >= RoundControl.HAND_HEIGHT) { + if (y >= GameControl.HAND_HEIGHT) { throw new ArrayIndexOutOfBoundsException(); // TODO We can't // handle // this yet... |