Implement score panel
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@298 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
eea456991c
commit
9cf3dc09ae
8 changed files with 270 additions and 14 deletions
32
mock/jrummikub/view/MockScorePanel.java
Normal file
32
mock/jrummikub/view/MockScorePanel.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package jrummikub.view;
|
||||
|
||||
import jrummikub.model.PlayerSettings;
|
||||
import jrummikub.model.Score;
|
||||
|
||||
public class MockScorePanel implements IScorePanel {
|
||||
|
||||
@Override
|
||||
public void setScores(Iterable<Score> scores) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAccumulatedScore(Score finalScore) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayers(Iterable<PlayerSettings> players) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -12,7 +12,9 @@ import jrummikub.util.MockEvent;
|
|||
public class MockView implements IView {
|
||||
/** */
|
||||
public MockSettingsPanel settingsPanel = new MockSettingsPanel();
|
||||
|
||||
/** */
|
||||
public MockScorePanel scorePanel = new MockScorePanel();
|
||||
/** */
|
||||
public MockPlayerPanel playerPanel = new MockPlayerPanel();
|
||||
/** */
|
||||
public MockTablePanel tablePanel = new MockTablePanel();
|
||||
|
@ -97,4 +99,15 @@ public class MockView implements IView {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public IScorePanel getScorePanel() {
|
||||
return scorePanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showScorePanel(boolean show) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,9 +34,10 @@ public class GameControl {
|
|||
public GameControl(GameSettings gameSettings, IView view) {
|
||||
this.gameSettings = gameSettings;
|
||||
this.view = view;
|
||||
|
||||
|
||||
gameState = new GameState();
|
||||
gameState.setFirstRoundFirstPlayer((int)(Math.random() * gameSettings.getPlayerList().size()));
|
||||
gameState.setFirstRoundFirstPlayer((int) (Math.random() * gameSettings
|
||||
.getPlayerList().size()));
|
||||
|
||||
connections.add(view.getNewRoundEvent().add(new IListener() {
|
||||
@Override
|
||||
|
@ -64,20 +65,22 @@ public class GameControl {
|
|||
return;
|
||||
}
|
||||
|
||||
view.showScorePanel(false);
|
||||
|
||||
IRoundState roundState = new RoundState(gameSettings);
|
||||
|
||||
// TODO: add number of already played rounds
|
||||
roundState.setActivePlayerNumber(gameState.getFirstRoundFirstPlayer());
|
||||
|
||||
roundState.setActivePlayerNumber(gameState.getFirstRoundFirstPlayer()
|
||||
+ gameState.getScores().size());
|
||||
|
||||
roundControl = new RoundControl(roundState, view);
|
||||
roundControl.getEndOfRoundEvent().add(new IListener1<Score>() {
|
||||
|
||||
@Override
|
||||
public void handle(Score roundScore) {
|
||||
endOfRound();
|
||||
endOfRound(roundScore);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
roundControl.getRestartRoundEvent().add(new IListener() {
|
||||
|
||||
@Override
|
||||
|
@ -88,15 +91,23 @@ public class GameControl {
|
|||
|
||||
roundControl.startRound();
|
||||
}
|
||||
|
||||
|
||||
private void restartRound() {
|
||||
roundControl = null;
|
||||
startRound();
|
||||
}
|
||||
|
||||
private void endOfRound() {
|
||||
private void endOfRound(Score roundScore) {
|
||||
gameState.getScores().add(roundScore);
|
||||
|
||||
roundControl = null;
|
||||
view.enableWinPanel(true);
|
||||
|
||||
view.getScorePanel().setPlayers(gameSettings.getPlayerList());
|
||||
view.getScorePanel().setScores(gameState.getScores());
|
||||
view.getScorePanel().setAccumulatedScore(gameState.getAccumulatedScore());
|
||||
view.getScorePanel().update();
|
||||
view.showScorePanel(true);
|
||||
}
|
||||
|
||||
private void finalScore() {
|
||||
|
|
|
@ -6,8 +6,8 @@ import java.util.List;
|
|||
* Score of a single round
|
||||
*/
|
||||
public class Score {
|
||||
List<Boolean> winners;
|
||||
List<Integer> points;
|
||||
private List<Boolean> winners;
|
||||
private List<Integer> points;
|
||||
|
||||
/**
|
||||
* Create a new round score
|
||||
|
|
35
src/jrummikub/view/IScorePanel.java
Normal file
35
src/jrummikub/view/IScorePanel.java
Normal file
|
@ -0,0 +1,35 @@
|
|||
package jrummikub.view;
|
||||
|
||||
import jrummikub.model.PlayerSettings;
|
||||
import jrummikub.model.Score;
|
||||
|
||||
/**
|
||||
* The panel the scores are displayed in
|
||||
*/
|
||||
public interface IScorePanel {
|
||||
/**
|
||||
* Sets the scores of the played rounds
|
||||
*
|
||||
* @param scores the round scores
|
||||
*/
|
||||
public void setScores(Iterable<Score> scores);
|
||||
|
||||
/**
|
||||
* Sets the accumulated scores to display
|
||||
*
|
||||
* @param accumulatedScore the accumulated score
|
||||
*/
|
||||
public void setAccumulatedScore(Score accumulatedScore);
|
||||
|
||||
/**
|
||||
* Sets the player list to display
|
||||
*
|
||||
* @param players the player list
|
||||
*/
|
||||
void setPlayers(Iterable<PlayerSettings> players);
|
||||
|
||||
/**
|
||||
* Updates the score display
|
||||
*/
|
||||
void update();
|
||||
}
|
|
@ -16,6 +16,13 @@ public interface IView {
|
|||
*/
|
||||
public ISettingsPanel getSettingsPanel();
|
||||
|
||||
/**
|
||||
* Returns the score panel
|
||||
*
|
||||
* @return the score panel
|
||||
*/
|
||||
public IScorePanel getScorePanel();
|
||||
|
||||
/**
|
||||
* Returns the table
|
||||
*
|
||||
|
@ -91,7 +98,16 @@ public interface IView {
|
|||
/**
|
||||
* Shows or hides the game settings panel
|
||||
*
|
||||
* @param show specifies if the panel shall be shown or hidden
|
||||
* @param show
|
||||
* specifies if the panel shall be shown or hidden
|
||||
*/
|
||||
void showSettingsPanel(boolean show);
|
||||
|
||||
/**
|
||||
* Shows or hides the score panel
|
||||
*
|
||||
* @param show
|
||||
* specifies if the panel shall be shown or hidden
|
||||
*/
|
||||
void showScorePanel(boolean show);
|
||||
}
|
||||
|
|
131
src/jrummikub/view/impl/ScorePanel.java
Normal file
131
src/jrummikub/view/impl/ScorePanel.java
Normal file
|
@ -0,0 +1,131 @@
|
|||
package jrummikub.view.impl;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
import jrummikub.model.PlayerSettings;
|
||||
import jrummikub.model.Score;
|
||||
import jrummikub.view.IScorePanel;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
class ScorePanel extends JPanel implements IScorePanel {
|
||||
private Iterable<PlayerSettings> players;
|
||||
private Iterable<Score> scores;
|
||||
private Score accumulatedScore;
|
||||
|
||||
public ScorePanel() {
|
||||
setLayout(new GridBagLayout());
|
||||
setBorder(new LineBorder(Color.BLACK));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayers(Iterable<PlayerSettings> players) {
|
||||
this.players = players;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScores(Iterable<Score> scores) {
|
||||
this.scores = scores;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAccumulatedScore(Score accumulatedScore) {
|
||||
this.accumulatedScore = accumulatedScore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
this.removeAll();
|
||||
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
c.weightx = 1.0;
|
||||
c.gridwidth = GridBagConstraints.REMAINDER;
|
||||
|
||||
addPlayerNames();
|
||||
|
||||
add(new JSeparator(), c);
|
||||
|
||||
int n = 0;
|
||||
for (Iterator<Score> it = scores.iterator(); it.hasNext();) {
|
||||
addScoreRow(it.next(), ++n);
|
||||
}
|
||||
|
||||
add(new JSeparator(), c);
|
||||
|
||||
addAccumulatedScore();
|
||||
}
|
||||
|
||||
private void addPlayerNames() {
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
c.weightx = 1.0;
|
||||
|
||||
JLabel roundHead = new JLabel("Runde");
|
||||
roundHead.setHorizontalAlignment(JLabel.CENTER);
|
||||
add(roundHead, c);
|
||||
|
||||
for (Iterator<PlayerSettings> it = players.iterator(); it.hasNext();) {
|
||||
PlayerSettings player = it.next();
|
||||
|
||||
if (!it.hasNext()) {
|
||||
c.gridwidth = GridBagConstraints.REMAINDER;
|
||||
}
|
||||
|
||||
JLabel playerNameLabel = new JLabel(player.getName());
|
||||
playerNameLabel.setIcon(ImageUtil.createColorIcon(player.getColor(), 12,
|
||||
1));
|
||||
playerNameLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||
|
||||
add(playerNameLabel, c);
|
||||
}
|
||||
}
|
||||
|
||||
private void addScoreRow(Score score, int n) {
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
c.weightx = 1.0;
|
||||
c.gridwidth = 1;
|
||||
|
||||
JLabel roundLabel = new JLabel(Integer.toString(n));
|
||||
roundLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||
add(roundLabel, c);
|
||||
|
||||
for (int i = 0; i < score.getPoints().size(); ++i) {
|
||||
if (i == score.getPoints().size()-1) {
|
||||
c.gridwidth = GridBagConstraints.REMAINDER;
|
||||
}
|
||||
|
||||
JLabel scoreLabel = new JLabel(Integer.toString(score.getPoints().get(i)));
|
||||
scoreLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||
add(scoreLabel, c);
|
||||
}
|
||||
}
|
||||
|
||||
private void addAccumulatedScore() {
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
c.weightx = 1.0;
|
||||
|
||||
JLabel accumLabel = new JLabel("Gesamt");
|
||||
accumLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||
add(accumLabel, c);
|
||||
|
||||
for (int i = 0; i < accumulatedScore.getPoints().size(); ++i) {
|
||||
if (i == accumulatedScore.getPoints().size()-1) {
|
||||
c.gridwidth = GridBagConstraints.REMAINDER;
|
||||
}
|
||||
|
||||
JLabel scoreLabel = new JLabel(Integer.toString(accumulatedScore.getPoints().get(i)));
|
||||
scoreLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||
add(scoreLabel, c);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ import jrummikub.model.Stone;
|
|||
import jrummikub.util.IEvent;
|
||||
import jrummikub.view.IHandPanel;
|
||||
import jrummikub.view.IPlayerPanel;
|
||||
import jrummikub.view.IScorePanel;
|
||||
import jrummikub.view.ISettingsPanel;
|
||||
import jrummikub.view.ITablePanel;
|
||||
import jrummikub.view.IView;
|
||||
|
@ -32,6 +33,7 @@ public class View extends JFrame implements IView {
|
|||
private StartTurnPanel startTurnPanel;
|
||||
private WinPanel winPanel;
|
||||
private SettingsPanel settingsPanel;
|
||||
private ScorePanel scorePanel;
|
||||
|
||||
private final static float PLAYER_PANEL_RATIO = 0.14f;
|
||||
private final static int PLAYER_PANEL_BORDER_WIDTH = 1;
|
||||
|
@ -46,6 +48,11 @@ public class View extends JFrame implements IView {
|
|||
return settingsPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScorePanel getScorePanel() {
|
||||
return scorePanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITablePanel getTablePanel() {
|
||||
return table;
|
||||
|
@ -100,6 +107,11 @@ public class View extends JFrame implements IView {
|
|||
layeredPane.setLayer(settingsPanel, JLayeredPane.POPUP_LAYER);
|
||||
layeredPane.add(settingsPanel);
|
||||
|
||||
scorePanel = new ScorePanel();
|
||||
scorePanel.setVisible(false);
|
||||
layeredPane.setLayer(scorePanel, JLayeredPane.POPUP_LAYER);
|
||||
layeredPane.add(scorePanel);
|
||||
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
|
@ -132,6 +144,7 @@ public class View extends JFrame implements IView {
|
|||
startTurnPanel.setBounds(0, tableHeight, width, playerPanelHeight);
|
||||
winPanel.setBounds(0, tableHeight, width, playerPanelHeight);
|
||||
settingsPanel.setBounds(width / 4, height / 4, width / 2, height / 2);
|
||||
scorePanel.setBounds(width / 8, height / 4, width * 3 / 4, height / 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -159,6 +172,11 @@ public class View extends JFrame implements IView {
|
|||
settingsPanel.setVisible(show);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showScorePanel(boolean show) {
|
||||
scorePanel.setVisible(show);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentPlayerName(String playerName) {
|
||||
playerPanel.setCurrentPlayerName(playerName);
|
||||
|
|
Reference in a new issue