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 PlayerSettings playerSettings;
|
||||||
/** */
|
/** */
|
||||||
public boolean laidOut;
|
public boolean laidOut;
|
||||||
|
/** */
|
||||||
|
public boolean lastTurnInvalid;
|
||||||
|
/** */
|
||||||
|
public int lastTurnStoneCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param playerSettings
|
* @param playerSettings
|
||||||
|
@ -48,4 +52,24 @@ public class MockPlayer implements IPlayer {
|
||||||
public void setHand(IHand hand) {
|
public void setHand(IHand hand) {
|
||||||
this.hand = 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
|
* Game gets started by initializing the first Round
|
||||||
*/
|
*/
|
||||||
public void startGame() {
|
public void startGame() {
|
||||||
view.showSidePanel(true);
|
|
||||||
startRound();
|
startRound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,6 +183,7 @@ public class GameControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showScorePanel() {
|
private void showScorePanel() {
|
||||||
|
view.showSidePanel(false);
|
||||||
view.setBottomPanel(BottomPanelType.WIN_PANEL);
|
view.setBottomPanel(BottomPanelType.WIN_PANEL);
|
||||||
|
|
||||||
view.getScorePanel().setPlayers(gameSettings.getPlayerList());
|
view.getScorePanel().setPlayers(gameSettings.getPlayerList());
|
||||||
|
|
|
@ -56,9 +56,9 @@ public class RoundControl {
|
||||||
* Create a new RoundControl using the given gameState and view
|
* Create a new RoundControl using the given gameState and view
|
||||||
*
|
*
|
||||||
* @param roundState
|
* @param roundState
|
||||||
* initial round state
|
* initial round state
|
||||||
* @param view
|
* @param view
|
||||||
* view used for user interaction
|
* view used for user interaction
|
||||||
*/
|
*/
|
||||||
public RoundControl(IRoundState roundState, IView view) {
|
public RoundControl(IRoundState roundState, IView view) {
|
||||||
this.roundState = roundState;
|
this.roundState = roundState;
|
||||||
|
@ -93,7 +93,7 @@ public class RoundControl {
|
||||||
* Continue a saved round after loading
|
* Continue a saved round after loading
|
||||||
*/
|
*/
|
||||||
public void continueRound() {
|
public void continueRound() {
|
||||||
|
|
||||||
connections.add(view.getStartTurnEvent().add(new IListener() {
|
connections.add(view.getStartTurnEvent().add(new IListener() {
|
||||||
@Override
|
@Override
|
||||||
public void handle() {
|
public void handle() {
|
||||||
|
@ -144,7 +144,7 @@ public class RoundControl {
|
||||||
|
|
||||||
protected void doPrepareTurn() {
|
protected void doPrepareTurn() {
|
||||||
updateSidePanel();
|
updateSidePanel();
|
||||||
|
|
||||||
boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
|
boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
|
||||||
.getType() == HUMAN;
|
.getType() == HUMAN;
|
||||||
boolean oneHuman = roundState.getGameSettings().oneHuman();
|
boolean oneHuman = roundState.getGameSettings().oneHuman();
|
||||||
|
@ -160,11 +160,12 @@ public class RoundControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
view.getTablePanel().setStoneSets(clonedTable.clone());
|
view.getTablePanel().setStoneSets(clonedTable.clone());
|
||||||
view.setCurrentPlayerName(roundState.getActivePlayer().getPlayerSettings()
|
view.setCurrentPlayerName(roundState.getActivePlayer()
|
||||||
.getName());
|
.getPlayerSettings().getName());
|
||||||
view.setCurrentPlayerColor(roundState.getActivePlayer().getPlayerSettings()
|
view.setCurrentPlayerColor(roundState.getActivePlayer()
|
||||||
.getColor());
|
.getPlayerSettings().getColor());
|
||||||
view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer().getLaidOut());
|
view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer()
|
||||||
|
.getLaidOut());
|
||||||
|
|
||||||
turnControl = createTurnControl(roundState.getActivePlayer()
|
turnControl = createTurnControl(roundState.getActivePlayer()
|
||||||
.getPlayerSettings());
|
.getPlayerSettings());
|
||||||
|
@ -193,8 +194,8 @@ public class RoundControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
turnControl.setup(new ITurnControl.TurnInfo(clonedTable, clonedHand,
|
turnControl.setup(new ITurnControl.TurnInfo(clonedTable, clonedHand,
|
||||||
roundState.getActivePlayer().getLaidOut(), turnMode), roundState
|
roundState.getActivePlayer().getLaidOut(), turnMode),
|
||||||
.getGameSettings(), view);
|
roundState.getGameSettings(), view);
|
||||||
turnControl.getEndOfTurnEvent().add(new IListener1<ITable>() {
|
turnControl.getEndOfTurnEvent().add(new IListener1<ITable>() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(ITable newTable) {
|
public void handle(ITable newTable) {
|
||||||
|
@ -211,16 +212,17 @@ public class RoundControl {
|
||||||
|
|
||||||
turnControl.startTurn();
|
turnControl.startTurn();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSidePanel() {
|
private void updateSidePanel() {
|
||||||
view.showSidePanel(true);
|
view.showSidePanel(true);
|
||||||
view.getSidePanel().setGameSettings(roundState.getGameSettings());
|
view.getSidePanel().setGameSettings(roundState.getGameSettings());
|
||||||
List<IPlayer> players = new ArrayList<IPlayer>();
|
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));
|
players.add(roundState.getNthNextPlayer(-i));
|
||||||
}
|
}
|
||||||
view.getSidePanel().setPlayers(players);
|
view.getSidePanel().setPlayers(players);
|
||||||
view.getSidePanel().setHeapCapacity(roundState.getGameSettings().getTotalStones());
|
view.getSidePanel().setHeapCapacity(
|
||||||
|
roundState.getGameSettings().getTotalStones());
|
||||||
view.getSidePanel().setHeapSize(roundState.getGameHeap().getSize());
|
view.getSidePanel().setHeapSize(roundState.getGameHeap().getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,11 +237,13 @@ public class RoundControl {
|
||||||
void deal() {
|
void deal() {
|
||||||
for (int i = 0; i < roundState.getPlayerCount(); i++) {
|
for (int i = 0; i < roundState.getPlayerCount(); i++) {
|
||||||
IHand hand = roundState.getNthNextPlayer(i).getHand();
|
IHand hand = roundState.getNthNextPlayer(i).getHand();
|
||||||
for (int j = 0; j < roundState.getGameSettings().getNumberOfStonesDealt(); j++) {
|
for (int j = 0; j < roundState.getGameSettings()
|
||||||
hand.drop(roundState.getGameHeap().drawStone(), new Position(0, 0));
|
.getNumberOfStonesDealt(); j++) {
|
||||||
|
hand.drop(roundState.getGameHeap().drawStone(), new Position(0,
|
||||||
|
0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean laidOutValidPoints() {
|
private boolean laidOutValidPoints() {
|
||||||
|
@ -248,11 +252,13 @@ public class RoundControl {
|
||||||
|
|
||||||
int totalValue = 0;
|
int totalValue = 0;
|
||||||
for (StoneSet set : newSets) {
|
for (StoneSet set : newSets) {
|
||||||
totalValue += set.classify(roundState.getGameSettings()).getSecond();
|
totalValue += set.classify(roundState.getGameSettings())
|
||||||
|
.getSecond();
|
||||||
}
|
}
|
||||||
|
|
||||||
return totalValue == 0
|
return totalValue == 0
|
||||||
|| totalValue >= roundState.getGameSettings().getInitialMeldThreshold();
|
|| totalValue >= roundState.getGameSettings()
|
||||||
|
.getInitialMeldThreshold();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void endOfTurn(ITable newTable) {
|
protected void endOfTurn(ITable newTable) {
|
||||||
|
@ -261,6 +267,11 @@ public class RoundControl {
|
||||||
|
|
||||||
turnControl = null;
|
turnControl = null;
|
||||||
|
|
||||||
|
roundState.getActivePlayer().setLastTurnInvalid(false);
|
||||||
|
roundState.getActivePlayer().setLastTurnStoneCount(
|
||||||
|
roundState.getActivePlayer().getHand().getSize()
|
||||||
|
- clonedHand.getSize());
|
||||||
|
|
||||||
roundState.getActivePlayer().setHand(clonedHand);
|
roundState.getActivePlayer().setHand(clonedHand);
|
||||||
boolean goToNextPlayer = true;
|
boolean goToNextPlayer = true;
|
||||||
lastTurnNotEnoughPoints = false;
|
lastTurnNotEnoughPoints = false;
|
||||||
|
@ -278,8 +289,8 @@ public class RoundControl {
|
||||||
if (lastTurnNotEnoughPoints) {
|
if (lastTurnNotEnoughPoints) {
|
||||||
view.setInitialMeldError(roundState.getGameSettings()
|
view.setInitialMeldError(roundState.getGameSettings()
|
||||||
.getInitialMeldThreshold());
|
.getInitialMeldThreshold());
|
||||||
view.setInvalidStoneSets(tableSetDifference(roundState.getTable(),
|
view.setInvalidStoneSets(tableSetDifference(
|
||||||
newTable));
|
roundState.getTable(), newTable));
|
||||||
} else if (lastTurnMeldError) {
|
} else if (lastTurnMeldError) {
|
||||||
view.setInitialMeldFirstError();
|
view.setInitialMeldFirstError();
|
||||||
view.setInvalidStoneSets(touchedStoneSets(newTable));
|
view.setInvalidStoneSets(touchedStoneSets(newTable));
|
||||||
|
@ -379,6 +390,7 @@ public class RoundControl {
|
||||||
Set<Stone> tableDiff = tableDifference(roundState.getTable(), newTable);
|
Set<Stone> tableDiff = tableDifference(roundState.getTable(), newTable);
|
||||||
// deal penalty, reset
|
// deal penalty, reset
|
||||||
roundState.getGameHeap().putBack(tableDiff);
|
roundState.getGameHeap().putBack(tableDiff);
|
||||||
|
roundState.getActivePlayer().setLastTurnInvalid(true);
|
||||||
dealPenalty(tableDiff.size());
|
dealPenalty(tableDiff.size());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -471,10 +483,12 @@ public class RoundControl {
|
||||||
stonePoints = playerHand.isInitialMeldPossible(roundState
|
stonePoints = playerHand.isInitialMeldPossible(roundState
|
||||||
.getGameSettings()) ? 200 : 100;
|
.getGameSettings()) ? 200 : 100;
|
||||||
} else {
|
} 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);
|
points.add(-stonePoints);
|
||||||
pointSum += stonePoints;
|
pointSum += stonePoints;
|
||||||
|
|
|
@ -43,5 +43,13 @@ public interface IPlayer extends Serializable {
|
||||||
* the player laid out
|
* 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 PlayerSettings settings;
|
||||||
private IHand hand;
|
private IHand hand;
|
||||||
private boolean laidOut;
|
private boolean laidOut;
|
||||||
|
private boolean lastTurnInvalid;
|
||||||
|
private int lastTurnStoneCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new player with a given name and color
|
* Create a new player with a given name and color
|
||||||
|
@ -45,4 +47,24 @@ public class Player implements IPlayer {
|
||||||
public PlayerSettings getPlayerSettings() {
|
public PlayerSettings getPlayerSettings() {
|
||||||
return settings;
|
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.gridx = 0;
|
||||||
c.gridy = 0;
|
c.gridy = 0;
|
||||||
c.weightx = 1;
|
c.weightx = 1;
|
||||||
c.fill = GridBagConstraints.BOTH;
|
c.fill = GridBagConstraints.HORIZONTAL;
|
||||||
infoPanel.setBorder(new MatteBorder(0, 0, 1, 0, Color.GRAY));
|
infoPanel.setBorder(new MatteBorder(0, 0, 1, 0, Color.GRAY));
|
||||||
add(infoPanel, c);
|
add(infoPanel, c);
|
||||||
|
|
||||||
|
@ -159,7 +159,9 @@ class SidePanel extends JPanel implements ISidePanel {
|
||||||
c.weightx = 1;
|
c.weightx = 1;
|
||||||
c.fill = GridBagConstraints.HORIZONTAL;
|
c.fill = GridBagConstraints.HORIZONTAL;
|
||||||
c.anchor = GridBagConstraints.WEST;
|
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("");
|
JLabel label = new JLabel("");
|
||||||
label.setHorizontalAlignment(SwingConstants.RIGHT);
|
label.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||||
c.weightx = 0;
|
c.weightx = 0;
|
||||||
|
@ -321,7 +323,6 @@ class SidePanel extends JPanel implements ISidePanel {
|
||||||
JLabel playerName;
|
JLabel playerName;
|
||||||
JLabel playerStatus;
|
JLabel playerStatus;
|
||||||
JLabel playerColor;
|
JLabel playerColor;
|
||||||
|
|
||||||
|
|
||||||
public PlayerListItem(IPlayer player) {
|
public PlayerListItem(IPlayer player) {
|
||||||
setLayout(new GridBagLayout());
|
setLayout(new GridBagLayout());
|
||||||
|
@ -343,18 +344,35 @@ class SidePanel extends JPanel implements ISidePanel {
|
||||||
c.gridheight = 1;
|
c.gridheight = 1;
|
||||||
c.weightx = 1;
|
c.weightx = 1;
|
||||||
c.fill = GridBagConstraints.HORIZONTAL;
|
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 = new JLabel(settings.getName());
|
||||||
playerName.putClientProperty("html.disable", Boolean.TRUE);
|
playerName.putClientProperty("html.disable", Boolean.TRUE);
|
||||||
add(playerName, c);
|
add(playerName, c);
|
||||||
|
|
||||||
c.gridx = 1;
|
c.gridx = 1;
|
||||||
c.gridy = 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);
|
add(playerStatus, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class PlayerListPanel extends JPanel {
|
class PlayerListPanel extends JPanel {
|
||||||
|
|
Reference in a new issue