Man kann den Timer einstellen

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@391 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Ida Massow 2011-06-09 00:11:26 +02:00
parent 45d5b3ae10
commit 8c2e4a7d59
9 changed files with 80 additions and 39 deletions

View file

@ -22,7 +22,7 @@ public class MockPlayerPanel implements IPlayerPanel {
public TurnMode turnMode; public TurnMode turnMode;
@Override @Override
public void setTimeLeft(int time) { public void setTime(int time) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }

View file

@ -121,6 +121,14 @@ public class SettingsControl {
update(); update();
} }
})); }));
connections.add(view.getSettingsPanel().getChangeTimeEvent()
.add(new IListener1<Integer>() {
@Override
public void handle(Integer value) {
settings.setTime(value);
update();
}
}));
connections.add(view.getSettingsPanel().getChangeStoneColorsEvent() connections.add(view.getSettingsPanel().getChangeStoneColorsEvent()
.add(new IListener1<Set<StoneColor>>() { .add(new IListener1<Set<StoneColor>>() {
@Override @Override

View file

@ -14,7 +14,8 @@ import jrummikub.view.IView;
*/ */
public class TurnTimer implements ActionListener, ITurnTimer { public class TurnTimer implements ActionListener, ITurnTimer {
private IView view; private IView view;
private int timeLeft = 60; private int timeLeft;
private int totalTime;
private Timer timer; private Timer timer;
private Event timeRunOutEvent = new Event(); private Event timeRunOutEvent = new Event();
@ -24,12 +25,14 @@ public class TurnTimer implements ActionListener, ITurnTimer {
* @param view * @param view
* view to display * view to display
*/ */
public TurnTimer(IView view) { public TurnTimer(IView view, int totalTime) {
this.view = view; this.view = view;
timeLeft = totalTime;
this.totalTime = totalTime;
timer = new Timer(1000, this); timer = new Timer(1000, this);
timer.setRepeats(true); timer.setRepeats(true);
timer.setCoalesce(false); timer.setCoalesce(false);
view.getPlayerPanel().setTimeLeft(timeLeft); view.getPlayerPanel().setTime(timeLeft, totalTime);
} }
@Override @Override
@ -45,7 +48,7 @@ public class TurnTimer implements ActionListener, ITurnTimer {
@Override @Override
public void actionPerformed(ActionEvent arg0) { public void actionPerformed(ActionEvent arg0) {
timeLeft--; timeLeft--;
view.getPlayerPanel().setTimeLeft(timeLeft); view.getPlayerPanel().setTime(timeLeft, totalTime);
if (timeLeft == 0) { if (timeLeft == 0) {
timer.stop(); timer.stop();
timeRunOutEvent.emit(); timeRunOutEvent.emit();

View file

@ -52,7 +52,7 @@ public abstract class AbstractTurnControl implements ITurnControl {
this.settings = settings; this.settings = settings;
this.view = view; this.view = view;
if (timer == null) { if (timer == null) {
timer = new TurnTimer(view); timer = new TurnTimer(view, settings.getTime());
} }
connections.add(timer.getTimeRunOutEvent().add(new IListener() { connections.add(timer.getTimeRunOutEvent().add(new IListener() {
@Override @Override

View file

@ -23,6 +23,7 @@ public class GameSettings implements Serializable {
private int highestValue; private int highestValue;
private int stoneSetNumber; private int stoneSetNumber;
private int numberOfStonesDealt; private int numberOfStonesDealt;
private int time;
private boolean noLimits; private boolean noLimits;
private HashSet<StoneColor> stoneColors; private HashSet<StoneColor> stoneColors;
@ -36,9 +37,10 @@ public class GameSettings implements Serializable {
highestValue = 13; highestValue = 13;
stoneSetNumber = 2; stoneSetNumber = 2;
numberOfStonesDealt = 14; numberOfStonesDealt = 14;
time = 60;
noLimits = false; noLimits = false;
stoneColors = new HashSet<StoneColor>(Arrays.asList(BLACK, BLUE, ORANGE, stoneColors = new HashSet<StoneColor>(Arrays.asList(BLACK, BLUE,
RED)); ORANGE, RED));
} }
/** /**
@ -54,7 +56,7 @@ public class GameSettings implements Serializable {
* Sets the initial meld threshold * Sets the initial meld threshold
* *
* @param value * @param value
* the value to set * the value to set
*/ */
public void setInitialMeldThreshold(int value) { public void setInitialMeldThreshold(int value) {
initialMeldThreshold = value; initialMeldThreshold = value;
@ -73,7 +75,7 @@ public class GameSettings implements Serializable {
* Sets the points counted for a joker * Sets the points counted for a joker
* *
* @param value * @param value
* the value to set * the value to set
*/ */
public void setJokerPoints(int value) { public void setJokerPoints(int value) {
jokerPoints = value; jokerPoints = value;
@ -92,7 +94,7 @@ public class GameSettings implements Serializable {
* Sets the number of jokers in game * Sets the number of jokers in game
* *
* @param value * @param value
* how many jokers will be used * how many jokers will be used
*/ */
public void setJokerNumber(int value) { public void setJokerNumber(int value) {
jokerNumber = value; jokerNumber = value;
@ -120,7 +122,7 @@ public class GameSettings implements Serializable {
* Set the highest stone value in use * Set the highest stone value in use
* *
* @param highestValue * @param highestValue
* highest stone value * highest stone value
*/ */
public void setHighestValue(int highestValue) { public void setHighestValue(int highestValue) {
this.highestValue = highestValue; this.highestValue = highestValue;
@ -139,12 +141,20 @@ public class GameSettings implements Serializable {
* Set the number of sets of stones in use * Set the number of sets of stones in use
* *
* @param stoneSets * @param stoneSets
* sets of stones in use * sets of stones in use
*/ */
public void setStoneSetNumber(int stoneSets) { public void setStoneSetNumber(int stoneSets) {
this.stoneSetNumber = stoneSets; this.stoneSetNumber = stoneSets;
} }
public int getTime() {
return time;
}
public void setTime(int time) {
this.time = time;
}
/** /**
* Use "No-Limits" rules * Use "No-Limits" rules
* *
@ -158,7 +168,7 @@ public class GameSettings implements Serializable {
* Set whether "No-Limits" rules are used * Set whether "No-Limits" rules are used
* *
* @param noLimits * @param noLimits
* use no limit rules * use no limit rules
*/ */
public void setNoLimits(boolean noLimits) { public void setNoLimits(boolean noLimits) {
this.noLimits = noLimits; this.noLimits = noLimits;
@ -177,7 +187,7 @@ public class GameSettings implements Serializable {
* Set stone colors used * Set stone colors used
* *
* @param stoneColors * @param stoneColors
* used stone colors * used stone colors
*/ */
public void setStoneColors(Set<StoneColor> stoneColors) { public void setStoneColors(Set<StoneColor> stoneColors) {
this.stoneColors = new HashSet<StoneColor>(stoneColors); this.stoneColors = new HashSet<StoneColor>(stoneColors);
@ -196,7 +206,7 @@ public class GameSettings implements Serializable {
* Set number of stones dealt at game start * Set number of stones dealt at game start
* *
* @param number * @param number
* how many Stones will be dealt initially * how many Stones will be dealt initially
*/ */
public void setNumberOfStonesDealt(int number) { public void setNumberOfStonesDealt(int number) {
numberOfStonesDealt = number; numberOfStonesDealt = number;

View file

@ -13,7 +13,7 @@ public interface IPlayerPanel {
* @param time * @param time
* the time left * the time left
*/ */
public void setTimeLeft(int time); public void setTime(int time, int totalTime);
/** /**
* The sort by groups event is emitted when the player wants to sort his * The sort by groups event is emitted when the player wants to sort his

View file

@ -6,6 +6,7 @@ import java.util.Set;
import jrummikub.control.turn.TurnControlFactory; import jrummikub.control.turn.TurnControlFactory;
import jrummikub.model.GameSettings; import jrummikub.model.GameSettings;
import jrummikub.model.StoneColor; import jrummikub.model.StoneColor;
import jrummikub.util.Event1;
import jrummikub.util.IEvent; import jrummikub.util.IEvent;
import jrummikub.util.IEvent1; import jrummikub.util.IEvent1;
import jrummikub.util.IEvent2; import jrummikub.util.IEvent2;
@ -169,6 +170,8 @@ public interface ISettingsPanel {
* @return the event * @return the event
*/ */
public IEvent1<Integer> getChangeJokerNumberEvent(); public IEvent1<Integer> getChangeJokerNumberEvent();
public Event1<Integer> getChangeTimeEvent();
/** /**
* Specifies the different kinds of settings errors that can be displayed * Specifies the different kinds of settings errors that can be displayed
@ -191,4 +194,5 @@ public interface ISettingsPanel {
/** Only computer players added */ /** Only computer players added */
COMPUTER_PLAYERS_ONLY_WARNING COMPUTER_PLAYERS_ONLY_WARNING
} }
} }

View file

@ -69,7 +69,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
* Sets the current player name * Sets the current player name
* *
* @param playerName * @param playerName
* the player name * the player name
*/ */
void setCurrentPlayerName(String playerName) { void setCurrentPlayerName(String playerName) {
currentPlayerNameLabel.setText(playerName); currentPlayerNameLabel.setText(playerName);
@ -88,7 +88,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
} }
@Override @Override
public void setTimeLeft(int time) { public void setTime(int time, int totalTime) {
timeBar.setMaximum(totalTime);
timeBar.setValue(time); timeBar.setValue(time);
timeBar.setString(Integer.toString(time / 60) + ":" timeBar.setString(Integer.toString(time / 60) + ":"
+ secondFormat.format(time % 60)); + secondFormat.format(time % 60));
@ -140,7 +141,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
leftPanel.add(hasLaidOutLabel); leftPanel.add(hasLaidOutLabel);
sortByGroupsButton = createButton(leftPanel, sortByGroupsButton = createButton(leftPanel,
"<html><center>Nach Sammlungen sortieren", new ActionListener() { "<html><center>Nach Sammlungen sortieren",
new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent arg0) { public void actionPerformed(ActionEvent arg0) {
sortByGroupsEvent.emit(); sortByGroupsEvent.emit();
@ -161,8 +163,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
private void createRightPanel() { private void createRightPanel() {
rightPanel = new JPanel(); rightPanel = new JPanel();
rightPanel.setLayout(null); rightPanel.setLayout(null);
rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET, rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET,
SIDE_PANEL_INSET, SIDE_PANEL_INSET)); SIDE_PANEL_INSET, SIDE_PANEL_INSET, SIDE_PANEL_INSET));
handRowUpButton = createButton(rightPanel, "<html><center>\u25B2", handRowUpButton = createButton(rightPanel, "<html><center>\u25B2",
new ActionListener() { new ActionListener() {
@ -234,7 +236,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
private void rescale() { private void rescale() {
Insets insets = getInsets(); Insets insets = getInsets();
int x = insets.left, y = insets.top, width = getWidth() - insets.left int x = insets.left, y = insets.top, width = getWidth() - insets.left
- insets.right, height = getHeight() - insets.top - insets.bottom; - insets.right, height = getHeight() - insets.top
- insets.bottom;
int boardWidth = hand.getWidth(); int boardWidth = hand.getWidth();
int handButtonWidth = (int) (width * HAND_ROW_BUTTON_RATIO); int handButtonWidth = (int) (width * HAND_ROW_BUTTON_RATIO);
int meanPanelWidth = (width - boardWidth) / 2; int meanPanelWidth = (width - boardWidth) / 2;
@ -243,8 +246,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
leftPanel.setBounds(x, y, leftPanelWidth, height); leftPanel.setBounds(x, y, leftPanelWidth, height);
hand.setBounds(x + leftPanelWidth, y, boardWidth, height); hand.setBounds(x + leftPanelWidth, y, boardWidth, height);
rightPanel.setBounds(x + leftPanelWidth + boardWidth, y, rightPanelWidth, rightPanel.setBounds(x + leftPanelWidth + boardWidth, y,
height); rightPanelWidth, height);
leftPanel.validate(); leftPanel.validate();
rightPanel.validate(); rightPanel.validate();
@ -252,7 +255,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
void updateButtons() { void updateButtons() {
handRowUpButton.setEnabled(hand.canRowUp()); handRowUpButton.setEnabled(hand.canRowUp());
handRowUpButton.setForeground(hand.canRowUp() ? Color.BLACK : Color.GRAY); handRowUpButton.setForeground(hand.canRowUp() ? Color.BLACK
: Color.GRAY);
handRowDownButton.setEnabled(hand.canRowDown()); handRowDownButton.setEnabled(hand.canRowDown());
handRowDownButton.setForeground(hand.canRowDown() ? Color.BLACK handRowDownButton.setForeground(hand.canRowDown() ? Color.BLACK
: Color.GRAY); : Color.GRAY);

View file

@ -75,6 +75,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
private JSpinner highestValueSpinner; private JSpinner highestValueSpinner;
private JSpinner numberOfStonesDealtSpinner; private JSpinner numberOfStonesDealtSpinner;
private JSpinner jokerNumberSpinner; private JSpinner jokerNumberSpinner;
private JSpinner timeSpinner;
private JPanel colorSelectionPanel; private JPanel colorSelectionPanel;
private Map<StoneColor, JToggleButton> colorButtons = new HashMap<StoneColor, JToggleButton>(); private Map<StoneColor, JToggleButton> colorButtons = new HashMap<StoneColor, JToggleButton>();
@ -91,7 +92,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
private Event1<Integer> changeNumberOfStonesDealtEvent = new Event1<Integer>(); private Event1<Integer> changeNumberOfStonesDealtEvent = new Event1<Integer>();
private Event1<Integer> changeHighestValueEvent = new Event1<Integer>(); private Event1<Integer> changeHighestValueEvent = new Event1<Integer>();
private Event1<Set<StoneColor>> changeStoneColorsEvent = new Event1<Set<StoneColor>>(); private Event1<Set<StoneColor>> changeStoneColorsEvent = new Event1<Set<StoneColor>>();
private Event1<Integer> changeTimeEvent = new Event1<Integer>();
@Override @Override
public IEvent getStartGameEvent() { public IEvent getStartGameEvent() {
return startGameEvent; return startGameEvent;
@ -136,6 +138,21 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
public IEvent1<Integer> getChangeHighestValueEvent() { public IEvent1<Integer> getChangeHighestValueEvent() {
return changeHighestValueEvent; return changeHighestValueEvent;
} }
@Override
public IEvent1<Integer> getChangeJokerNumberEvent() {
return changeJokerNumberEvent;
}
@Override
public IEvent2<Integer, Type> getChangePlayerTypeEvent() {
return changePlayerTypeEvent;
}
@Override
public Event1<Integer> getChangeTimeEvent() {
return changeTimeEvent;
}
@Override @Override
public IEvent1<Set<StoneColor>> getChangeStoneColorsEvent() { public IEvent1<Set<StoneColor>> getChangeStoneColorsEvent() {
@ -214,6 +231,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
highestValueSpinner.setValue(gameSettings.getHighestValue()); highestValueSpinner.setValue(gameSettings.getHighestValue());
numberOfStonesDealtSpinner.setValue(gameSettings.getNumberOfStonesDealt()); numberOfStonesDealtSpinner.setValue(gameSettings.getNumberOfStonesDealt());
jokerNumberSpinner.setValue(gameSettings.getJokerNumber()); jokerNumberSpinner.setValue(gameSettings.getJokerNumber());
timeSpinner.setValue(gameSettings.getTime());
for (StoneColor color : StoneColor.values()) { for (StoneColor color : StoneColor.values()) {
colorButtons.get(color).getModel() colorButtons.get(color).getModel()
@ -300,13 +318,16 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
makeOptionLabel(4, "Jokeranzahl:"); makeOptionLabel(4, "Jokeranzahl:");
jokerNumberSpinner = makeOptionSpinner(4, 1, 999, 1, changeJokerNumberEvent); jokerNumberSpinner = makeOptionSpinner(4, 1, 999, 1, changeJokerNumberEvent);
makeOptionLabel(5, "Zeit für Spielzug:");
timeSpinner = makeOptionSpinner(5, 1, 999, 1, changeTimeEvent);
makeOptionLabel(5, "Steinfarben:"); makeOptionLabel(6, "Steinfarben:");
createColorSelectionPanel(5); createColorSelectionPanel(6);
GridBagConstraints c = new GridBagConstraints(); GridBagConstraints c = new GridBagConstraints();
c.gridx = 1; c.gridx = 1;
c.gridy = 6; c.gridy = 7;
c.fill = GridBagConstraints.BOTH; c.fill = GridBagConstraints.BOTH;
c.weightx = 1; c.weightx = 1;
c.weighty = 1; c.weighty = 1;
@ -601,13 +622,4 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
} }
} }
@Override
public IEvent1<Integer> getChangeJokerNumberEvent() {
return changeJokerNumberEvent;
}
@Override
public IEvent2<Integer, Type> getChangePlayerTypeEvent() {
return changePlayerTypeEvent;
}
} }