Finished side panel info
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@501 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
4df5c0e665
commit
8a3e4c3e26
6 changed files with 118 additions and 32 deletions
|
@ -11,6 +11,10 @@ public class MockPlayer implements IPlayer {
|
|||
public PlayerSettings playerSettings;
|
||||
/** */
|
||||
public boolean laidOut;
|
||||
/** */
|
||||
public boolean lastTurnInvalid;
|
||||
/** */
|
||||
public int lastTurnStoneCount;
|
||||
|
||||
/**
|
||||
* @param playerSettings
|
||||
|
@ -48,4 +52,24 @@ public class MockPlayer implements IPlayer {
|
|||
public void setHand(IHand hand) {
|
||||
this.hand = hand;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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<ITable>() {
|
||||
@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<IPlayer> players = new ArrayList<IPlayer>();
|
||||
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<Stone> 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;
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Reference in a new issue