diff options
author | Ida Massow <massow@informatik.uni-luebeck.de> | 2011-05-04 16:49:40 +0200 |
---|---|---|
committer | Ida Massow <massow@informatik.uni-luebeck.de> | 2011-05-04 16:49:40 +0200 |
commit | 614d0935be71708331c9b1d65f430d6bf5b00777 (patch) | |
tree | 626005f6920598877418a9a9479d8a4d11b62b16 /src | |
parent | 4870017d27c5ed9357e4807ce83a80609b13e14b (diff) | |
download | JRummikub-614d0935be71708331c9b1d65f430d6bf5b00777.tar JRummikub-614d0935be71708331c9b1d65f430d6bf5b00777.zip |
Timer läuft ab
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@106 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src')
-rw-r--r-- | src/jrummikub/JRummikub.java | 4 | ||||
-rw-r--r-- | src/jrummikub/control/TurnTimer.java | 44 |
2 files changed, 46 insertions, 2 deletions
diff --git a/src/jrummikub/JRummikub.java b/src/jrummikub/JRummikub.java index 5bddc68..5ea5a26 100644 --- a/src/jrummikub/JRummikub.java +++ b/src/jrummikub/JRummikub.java @@ -8,6 +8,7 @@ import java.util.Map; import javax.swing.UIManager; +import jrummikub.control.TurnTimer; import jrummikub.model.Position; import jrummikub.model.Stone; import jrummikub.model.StoneColor; @@ -33,7 +34,8 @@ public class JRummikub { final IView view = new jrummikub.view.impl.View(); view.setCurrentPlayerName("Player 1"); - view.getPlayerPanel().setTimeLeft(42); + TurnTimer testTimer = new TurnTimer(view); + testTimer.startTimer(); view.getTablePanel().setLeftPlayerName("Player 2"); view.getTablePanel().setTopPlayerName("Player 3"); view.getTablePanel().setRightPlayerName("Player 4"); diff --git a/src/jrummikub/control/TurnTimer.java b/src/jrummikub/control/TurnTimer.java index 701e892..9e694f7 100644 --- a/src/jrummikub/control/TurnTimer.java +++ b/src/jrummikub/control/TurnTimer.java @@ -1,5 +1,47 @@ package jrummikub.control; -public class TurnTimer { +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.Timer; + +import jrummikub.util.Event; +import jrummikub.util.IEvent; +import jrummikub.view.IView; + +public class TurnTimer implements ActionListener { + private IView view; + private int timeLeft = 60; + private Timer timer; + private Event timeRunOutEvent = new Event(); + + public TurnTimer(IView view) { + this.view = view; + timer = new Timer(1000, this); + timer.setRepeats(true); + timer.setCoalesce(false); + view.getPlayerPanel().setTimeLeft(timeLeft); + } + + public void startTimer() { + timer.start(); + } + + public void stopTimer() { + timer.stop(); + } + + @Override + public void actionPerformed(ActionEvent arg0) { + timeLeft--; + view.getPlayerPanel().setTimeLeft(timeLeft); + if (timeLeft == 0) { + timer.stop(); + timeRunOutEvent.emit(); + } + } + + public IEvent getTimeRunOutEvent() { + return timeRunOutEvent; + } } |