summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/control')
-rw-r--r--src/jrummikub/control/ITurnTimer.java14
-rw-r--r--src/jrummikub/control/RoundControl.java14
-rw-r--r--src/jrummikub/control/TurnControl.java22
-rw-r--r--src/jrummikub/control/TurnTimer.java12
4 files changed, 59 insertions, 3 deletions
diff --git a/src/jrummikub/control/ITurnTimer.java b/src/jrummikub/control/ITurnTimer.java
index 54f00b5..175d95f 100644
--- a/src/jrummikub/control/ITurnTimer.java
+++ b/src/jrummikub/control/ITurnTimer.java
@@ -2,12 +2,26 @@ package jrummikub.control;
import jrummikub.util.IEvent;
+/**
+ * Interface for the {@link TurnTimer}
+ */
public interface ITurnTimer {
+ /**
+ * Starts the timer
+ */
public abstract void startTimer();
+ /**
+ * Stops the timer. Stopping an already stopped timer is a no-op.
+ */
public abstract void stopTimer();
+ /**
+ * Returns the event that is emitted if the timer timed out.
+ *
+ * @return time out event
+ */
public abstract IEvent getTimeRunOutEvent();
} \ No newline at end of file
diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java
index 490873a..fc27f9b 100644
--- a/src/jrummikub/control/RoundControl.java
+++ b/src/jrummikub/control/RoundControl.java
@@ -18,6 +18,9 @@ import jrummikub.util.IListener;
import jrummikub.util.Pair;
import jrummikub.view.IView;
+/**
+ * Controller that manages a single round of rummikub
+ */
public class RoundControl {
private IGameState gameState;
private IView view;
@@ -25,6 +28,14 @@ public class RoundControl {
private Event endRoundEvent = new Event();
private List<Connection> connections = new ArrayList<Connection>();
+ /**
+ * Create a new RoundControl using the given gameState and view
+ *
+ * @param gameState
+ * initial game state
+ * @param view
+ * view used for user interaction
+ */
public RoundControl(IGameState gameState, IView view) {
this.gameState = gameState;
this.view = view;
@@ -34,6 +45,9 @@ public class RoundControl {
return endRoundEvent;
}
+ /**
+ * Begin the round
+ */
public void startRound() {
deal();
diff --git a/src/jrummikub/control/TurnControl.java b/src/jrummikub/control/TurnControl.java
index 32e6379..ace201e 100644
--- a/src/jrummikub/control/TurnControl.java
+++ b/src/jrummikub/control/TurnControl.java
@@ -21,6 +21,9 @@ import jrummikub.util.IListener2;
import jrummikub.util.Pair;
import jrummikub.view.IView;
+/**
+ * Controller for a single turn made by a human player
+ */
public class TurnControl {
private IHand hand;
private ITable table;
@@ -32,6 +35,17 @@ public class TurnControl {
private Event endOfTurnEvent = new Event();
private List<Connection> connections = new ArrayList<Connection>();
+ /**
+ * Create a new TurnControl using a given hand (of the active player), a
+ * given table and a given view for user interaction.
+ *
+ * @param hand
+ * active player's hand
+ * @param table
+ * current table
+ * @param view
+ * view for user interaction.
+ */
public TurnControl(IHand hand, ITable table, IView view) {
this.hand = hand;
this.table = table;
@@ -47,6 +61,9 @@ public class TurnControl {
this.timer = testTimer;
}
+ /**
+ * Start the turn
+ */
public void startTurn() {
IListener endOfTurnListener = new IListener() {
@@ -408,6 +425,11 @@ public class TurnControl {
view.setSelectedStones(new ArrayList<Stone>());
}
+ /**
+ * Get the event that is emitted when the turn is over
+ *
+ * @return end of turn event
+ */
public IEvent getEndOfTurnEvent() {
return endOfTurnEvent;
}
diff --git a/src/jrummikub/control/TurnTimer.java b/src/jrummikub/control/TurnTimer.java
index 789bf1a..17bdf0f 100644
--- a/src/jrummikub/control/TurnTimer.java
+++ b/src/jrummikub/control/TurnTimer.java
@@ -9,12 +9,21 @@ import jrummikub.util.Event;
import jrummikub.util.IEvent;
import jrummikub.view.IView;
+/**
+ * Count-down timer used to limit the turn time
+ */
public class TurnTimer implements ActionListener, ITurnTimer {
private IView view;
private int timeLeft = 60;
private Timer timer;
private Event timeRunOutEvent = new Event();
+ /**
+ * Create a new timer using a given view to display the current time left
+ *
+ * @param view
+ * view to display
+ */
public TurnTimer(IView view) {
this.view = view;
timer = new Timer(1000, this);
@@ -23,19 +32,16 @@ public class TurnTimer implements ActionListener, ITurnTimer {
view.getPlayerPanel().setTimeLeft(timeLeft);
}
-
@Override
public void startTimer() {
timer.start();
}
-
@Override
public void stopTimer() {
timer.stop();
}
-
@Override
public void actionPerformed(ActionEvent arg0) {
timeLeft--;