From 8a3e4c3e26cba022dfaf06f8c7cd31b33b0889e9 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Mon, 20 Jun 2011 03:19:02 +0200 Subject: Finished side panel info git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@501 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/GameControl.java | 2 +- src/jrummikub/control/RoundControl.java | 60 ++++++++++++++++++++------------- src/jrummikub/model/IPlayer.java | 10 +++++- src/jrummikub/model/Player.java | 22 ++++++++++++ src/jrummikub/view/impl/SidePanel.java | 32 ++++++++++++++---- 5 files changed, 94 insertions(+), 32 deletions(-) (limited to 'src/jrummikub') diff --git a/src/jrummikub/control/GameControl.java b/src/jrummikub/control/GameControl.java index 7e95c08..66a96b6 100644 --- a/src/jrummikub/control/GameControl.java +++ b/src/jrummikub/control/GameControl.java @@ -97,7 +97,6 @@ public class GameControl { * Game gets started by initializing the first Round */ public void startGame() { - view.showSidePanel(true); startRound(); } @@ -184,6 +183,7 @@ public class GameControl { } private void showScorePanel() { + view.showSidePanel(false); view.setBottomPanel(BottomPanelType.WIN_PANEL); view.getScorePanel().setPlayers(gameSettings.getPlayerList()); diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java index e18ce2e..ac3acf3 100644 --- a/src/jrummikub/control/RoundControl.java +++ b/src/jrummikub/control/RoundControl.java @@ -56,9 +56,9 @@ public class RoundControl { * Create a new RoundControl using the given gameState and view * * @param roundState - * initial round state + * initial round state * @param view - * view used for user interaction + * view used for user interaction */ public RoundControl(IRoundState roundState, IView view) { this.roundState = roundState; @@ -93,7 +93,7 @@ public class RoundControl { * Continue a saved round after loading */ public void continueRound() { - + connections.add(view.getStartTurnEvent().add(new IListener() { @Override public void handle() { @@ -144,7 +144,7 @@ public class RoundControl { protected void doPrepareTurn() { updateSidePanel(); - + boolean isHuman = roundState.getActivePlayer().getPlayerSettings() .getType() == HUMAN; boolean oneHuman = roundState.getGameSettings().oneHuman(); @@ -160,11 +160,12 @@ public class RoundControl { } view.getTablePanel().setStoneSets(clonedTable.clone()); - view.setCurrentPlayerName(roundState.getActivePlayer().getPlayerSettings() - .getName()); - view.setCurrentPlayerColor(roundState.getActivePlayer().getPlayerSettings() - .getColor()); - view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer().getLaidOut()); + view.setCurrentPlayerName(roundState.getActivePlayer() + .getPlayerSettings().getName()); + view.setCurrentPlayerColor(roundState.getActivePlayer() + .getPlayerSettings().getColor()); + view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer() + .getLaidOut()); turnControl = createTurnControl(roundState.getActivePlayer() .getPlayerSettings()); @@ -193,8 +194,8 @@ public class RoundControl { } turnControl.setup(new ITurnControl.TurnInfo(clonedTable, clonedHand, - roundState.getActivePlayer().getLaidOut(), turnMode), roundState - .getGameSettings(), view); + roundState.getActivePlayer().getLaidOut(), turnMode), + roundState.getGameSettings(), view); turnControl.getEndOfTurnEvent().add(new IListener1() { @Override public void handle(ITable newTable) { @@ -211,16 +212,17 @@ public class RoundControl { turnControl.startTurn(); } - + private void updateSidePanel() { view.showSidePanel(true); view.getSidePanel().setGameSettings(roundState.getGameSettings()); List players = new ArrayList(); - for (int i = 1; i < roundState.getPlayerCount(); i ++) { + for (int i = 1; i < roundState.getPlayerCount(); i++) { players.add(roundState.getNthNextPlayer(-i)); } view.getSidePanel().setPlayers(players); - view.getSidePanel().setHeapCapacity(roundState.getGameSettings().getTotalStones()); + view.getSidePanel().setHeapCapacity( + roundState.getGameSettings().getTotalStones()); view.getSidePanel().setHeapSize(roundState.getGameHeap().getSize()); } @@ -235,11 +237,13 @@ public class RoundControl { void deal() { for (int i = 0; i < roundState.getPlayerCount(); i++) { IHand hand = roundState.getNthNextPlayer(i).getHand(); - for (int j = 0; j < roundState.getGameSettings().getNumberOfStonesDealt(); j++) { - hand.drop(roundState.getGameHeap().drawStone(), new Position(0, 0)); + for (int j = 0; j < roundState.getGameSettings() + .getNumberOfStonesDealt(); j++) { + hand.drop(roundState.getGameHeap().drawStone(), new Position(0, + 0)); } } - + } private boolean laidOutValidPoints() { @@ -248,11 +252,13 @@ public class RoundControl { int totalValue = 0; for (StoneSet set : newSets) { - totalValue += set.classify(roundState.getGameSettings()).getSecond(); + totalValue += set.classify(roundState.getGameSettings()) + .getSecond(); } return totalValue == 0 - || totalValue >= roundState.getGameSettings().getInitialMeldThreshold(); + || totalValue >= roundState.getGameSettings() + .getInitialMeldThreshold(); } protected void endOfTurn(ITable newTable) { @@ -261,6 +267,11 @@ public class RoundControl { turnControl = null; + roundState.getActivePlayer().setLastTurnInvalid(false); + roundState.getActivePlayer().setLastTurnStoneCount( + roundState.getActivePlayer().getHand().getSize() + - clonedHand.getSize()); + roundState.getActivePlayer().setHand(clonedHand); boolean goToNextPlayer = true; lastTurnNotEnoughPoints = false; @@ -278,8 +289,8 @@ public class RoundControl { if (lastTurnNotEnoughPoints) { view.setInitialMeldError(roundState.getGameSettings() .getInitialMeldThreshold()); - view.setInvalidStoneSets(tableSetDifference(roundState.getTable(), - newTable)); + view.setInvalidStoneSets(tableSetDifference( + roundState.getTable(), newTable)); } else if (lastTurnMeldError) { view.setInitialMeldFirstError(); view.setInvalidStoneSets(touchedStoneSets(newTable)); @@ -379,6 +390,7 @@ public class RoundControl { Set tableDiff = tableDifference(roundState.getTable(), newTable); // deal penalty, reset roundState.getGameHeap().putBack(tableDiff); + roundState.getActivePlayer().setLastTurnInvalid(true); dealPenalty(tableDiff.size()); } @@ -471,10 +483,12 @@ public class RoundControl { stonePoints = playerHand.isInitialMeldPossible(roundState .getGameSettings()) ? 200 : 100; } else { - stonePoints = playerHand.getStonePoints(roundState.getGameSettings()); + stonePoints = playerHand.getStonePoints(roundState + .getGameSettings()); } - bestScore = updateBestScore(bestScore, -stonePoints, playerHand.getSize()); + bestScore = updateBestScore(bestScore, -stonePoints, + playerHand.getSize()); points.add(-stonePoints); pointSum += stonePoints; diff --git a/src/jrummikub/model/IPlayer.java b/src/jrummikub/model/IPlayer.java index 9df3741..a72b002 100644 --- a/src/jrummikub/model/IPlayer.java +++ b/src/jrummikub/model/IPlayer.java @@ -43,5 +43,13 @@ public interface IPlayer extends Serializable { * the player laid out * */ - void setLaidOut(boolean laidOut); + public void setLaidOut(boolean laidOut); + + public boolean wasLastTurnInvalid(); + + public void setLastTurnInvalid(boolean value); + + public int getLastTurnStoneCount(); + + public void setLastTurnStoneCount(int value); } \ No newline at end of file diff --git a/src/jrummikub/model/Player.java b/src/jrummikub/model/Player.java index 00469c5..eccac15 100644 --- a/src/jrummikub/model/Player.java +++ b/src/jrummikub/model/Player.java @@ -7,6 +7,8 @@ public class Player implements IPlayer { private PlayerSettings settings; private IHand hand; private boolean laidOut; + private boolean lastTurnInvalid; + private int lastTurnStoneCount; /** * Create a new player with a given name and color @@ -45,4 +47,24 @@ public class Player implements IPlayer { public PlayerSettings getPlayerSettings() { return settings; } + + @Override + public boolean wasLastTurnInvalid() { + return lastTurnInvalid; + } + + @Override + public void setLastTurnInvalid(boolean value) { + lastTurnInvalid = value; + } + + @Override + public int getLastTurnStoneCount() { + return lastTurnStoneCount; + } + + @Override + public void setLastTurnStoneCount(int value) { + lastTurnStoneCount = value; + } } diff --git a/src/jrummikub/view/impl/SidePanel.java b/src/jrummikub/view/impl/SidePanel.java index a4e0e43..88f5d64 100644 --- a/src/jrummikub/view/impl/SidePanel.java +++ b/src/jrummikub/view/impl/SidePanel.java @@ -63,7 +63,7 @@ class SidePanel extends JPanel implements ISidePanel { c.gridx = 0; c.gridy = 0; c.weightx = 1; - c.fill = GridBagConstraints.BOTH; + c.fill = GridBagConstraints.HORIZONTAL; infoPanel.setBorder(new MatteBorder(0, 0, 1, 0, Color.GRAY)); add(infoPanel, c); @@ -159,7 +159,9 @@ class SidePanel extends JPanel implements ISidePanel { c.weightx = 1; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.WEST; - panel.add(new JLabel(name + ": "), c); + JLabel nameLabel = new JLabel(name + ": "); + nameLabel.setPreferredSize(new Dimension(0,nameLabel.getPreferredSize().height)); + panel.add(nameLabel, c); JLabel label = new JLabel(""); label.setHorizontalAlignment(SwingConstants.RIGHT); c.weightx = 0; @@ -321,7 +323,6 @@ class SidePanel extends JPanel implements ISidePanel { JLabel playerName; JLabel playerStatus; JLabel playerColor; - public PlayerListItem(IPlayer player) { setLayout(new GridBagLayout()); @@ -343,18 +344,35 @@ class SidePanel extends JPanel implements ISidePanel { c.gridheight = 1; c.weightx = 1; c.fill = GridBagConstraints.HORIZONTAL; - c.insets = new Insets(2,2,2,2); + c.insets = new Insets(2, 2, 2, 2); playerName = new JLabel(settings.getName()); playerName.putClientProperty("html.disable", Boolean.TRUE); add(playerName, c); - + c.gridx = 1; c.gridy = 1; - playerStatus = new JLabel(player.getLaidOut() ? "rausgekommen" : "nicht rausgekommen"); + + String status = "Stein gezogen"; + + if (player.wasLastTurnInvalid()) { + status = "ungültiger Zug"; + if (!player.getLaidOut()) { + status = "ungültig, nicht rausgekommen"; + } + } else { + if (!player.getLaidOut()) { + status = "nicht rausgekommen"; + } else if (player.getLastTurnStoneCount() == 1) { + status = "1 Stein abgelegt"; + } else if (player.getLastTurnStoneCount() > 1) { + status = player.getLastTurnStoneCount() + " Steine abgelegt"; + } + } + + playerStatus = new JLabel(status); add(playerStatus, c); } - } class PlayerListPanel extends JPanel { -- cgit v1.2.3