summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jrummikub/JRummikub.java206
-rw-r--r--src/jrummikub/control/TurnControl.java1
-rw-r--r--src/jrummikub/view/ITablePanel.java3
-rw-r--r--src/jrummikub/view/impl/TablePanel.java26
-rw-r--r--test/jrummikub/control/TurnControlTest.java21
-rw-r--r--test/jrummikub/view/MockTablePanel.java7
6 files changed, 40 insertions, 224 deletions
diff --git a/src/jrummikub/JRummikub.java b/src/jrummikub/JRummikub.java
index 945ac5d..38d152d 100644
--- a/src/jrummikub/JRummikub.java
+++ b/src/jrummikub/JRummikub.java
@@ -1,29 +1,14 @@
package jrummikub;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import javax.swing.UIManager;
-import jrummikub.control.ITurnTimer;
-import jrummikub.control.TurnTimer;
+import jrummikub.control.TurnControl;
+import jrummikub.model.GameState;
import jrummikub.model.Position;
-import jrummikub.model.Stone;
-import jrummikub.model.StoneColor;
-import jrummikub.model.StoneSet;
-import jrummikub.util.IListener;
-import jrummikub.util.IListener1;
-import jrummikub.util.IListener2;
-import jrummikub.view.IView;
+import jrummikub.view.impl.View;
public class JRummikub {
- /**
- * @param args
- */
public static void main(String[] args) {
String nativeLF = UIManager.getSystemLookAndFeelClassName();
@@ -32,188 +17,15 @@ public class JRummikub {
} catch (Exception e) {
}
- final IView view = new jrummikub.view.impl.View();
-
- view.setCurrentPlayerName("Player 1");
- ITurnTimer testTimer = new TurnTimer(view);
- testTimer.startTimer();
- view.getTablePanel().setLeftPlayerName("Player 2");
- view.getTablePanel().setTopPlayerName("Player 3");
- view.getTablePanel().setRightPlayerName("Player 4");
-
- view.getPlayerPanel().getSortByGroupsEvent().add(new IListener() {
- @Override
- public void handle() {
- System.out.println("'Sort by groups' fired");
- }
- });
- view.getPlayerPanel().getSortByRunsEvent().add(new IListener() {
- @Override
- public void handle() {
- System.out.println("'Sort by runs' fired");
- }
- });
- view.getPlayerPanel().getEndTurnEvent().add(new IListener() {
- @Override
- public void handle() {
- System.out.println("'End turn' fired");
- view.enableStartTurnPanel(true);
- }
- });
- view.getStartTurnEvent().add(new IListener() {
- @Override
- public void handle() {
- System.out.println("'Start turn' fired");
- view.enableStartTurnPanel(false);
- }
- });
-
- // stones on the board
- Map<Stone, Position> stones = new HashMap<Stone, Position>();
- stones.put(new Stone(1, StoneColor.ORANGE), new Position(0, 0));
- stones.put(new Stone(10, StoneColor.BLUE), new Position(1, 0));
- stones.put(new Stone(9, StoneColor.RED), new Position(0.5f, 1));
- stones.put(new Stone(7, StoneColor.BLACK), new Position(1.75f, 1));
-
- Stone stoneJoker = new Stone(StoneColor.RED);
- stones.put(stoneJoker, new Position(2.5f, 0));
- stones.put(new Stone(StoneColor.BLACK), new Position(3.5f, 0));
-
- view.getPlayerPanel().getHandPanel().setStones(stones);
-
- view.getPlayerPanel().getHandPanel().getClickEvent()
- .add(new IListener1<Position>() {
- @Override
- public void handle(Position p) {
- System.out.println("Hand clicked at " + p);
- }
- });
- view.getPlayerPanel().getHandPanel().getStoneClickEvent()
- .add(new IListener2<Stone, Boolean>() {
- @Override
- public void handle(Stone s, Boolean collect) {
- System.out.println("Hand clicked on " + s
- + (collect ? ", collect" : ""));
-
- }
- });
- view.getPlayerPanel().getHandPanel().getRangeClickEvent()
- .add(new IListener2<Stone, Boolean>() {
- @Override
- public void handle(Stone s, Boolean collect) {
- System.out.println("Hand range-clicked on " + s
- + (collect ? ", collect" : ""));
-
- }
- });
- view.getPlayerPanel().getHandPanel().getSetClickEvent()
- .add(new IListener2<Stone, Boolean>() {
- @Override
- public void handle(Stone s, Boolean collect) {
- System.out.println("Hand set-clicked at " + s
- + (collect ? ", collect" : ""));
-
- }
- });
-
- view.getTablePanel().getClickEvent().add(new IListener1<Position>() {
- @Override
- public void handle(Position p) {
- System.out.println("Table clicked at " + p);
- }
- });
- view.getTablePanel().getStoneClickEvent()
- .add(new IListener2<Stone, Boolean>() {
- @Override
- public void handle(Stone s, Boolean collect) {
- System.out.println("Table clicked on " + s
- + (collect ? ", collect" : ""));
-
- }
- });
- view.getTablePanel().getRangeClickEvent()
- .add(new IListener2<Stone, Boolean>() {
- @Override
- public void handle(Stone s, Boolean collect) {
- System.out.println("Table range-clicked on " + s
- + (collect ? ", collect" : ""));
-
- }
- });
- view.getTablePanel().getSetClickEvent()
- .add(new IListener2<Stone, Boolean>() {
- @Override
- public void handle(Stone s, Boolean collect) {
- System.out.println("Table set-clicked at " + s
- + (collect ? ", collect" : ""));
- view.enableWinPanel(true);
- }
- });
-
- view.getTablePanel().getLeftConnectorClickEvent()
- .add(new IListener1<StoneSet>() {
- @Override
- public void handle(StoneSet s) {
- System.out.println("Left connector clicked on " + s);
- }
- });
-
- view.getTablePanel().getRightConnectorClickEvent()
- .add(new IListener1<StoneSet>() {
- @Override
- public void handle(StoneSet s) {
- System.out.println("Right connector clicked on " + s);
- }
- });
-
- view.getTablePanel().getStoneCollectionPanel().getStoneClickEvent()
- .add(new IListener2<Stone, Boolean>() {
- @Override
- public void handle(Stone s, Boolean collect) {
- System.out.println("Collection clicked on " + s
- + (collect ? ", collect" : ""));
-
- }
- });
-
- view.getTablePanel().getStoneCollectionPanel().getRangeClickEvent()
- .add(new IListener2<Stone, Boolean>() {
- @Override
- public void handle(Stone s, Boolean collect) {
- System.out.println("Collection range-clicked on " + s
- + (collect ? ", collect" : ""));
-
- }
- });
- view.getTablePanel().getStoneCollectionPanel().getSetClickEvent()
- .add(new IListener2<Stone, Boolean>() {
- @Override
- public void handle(Stone s, Boolean collect) {
- System.out.println("Collection set-clicked at " + s
- + (collect ? ", collect" : ""));
-
- }
- });
-
- // stoneSets on the table
- Map<StoneSet, Position> stoneSets = new HashMap<StoneSet, Position>();
-
- stoneSets.put(new StoneSet(new Stone(5, StoneColor.ORANGE)),
- new Position(0.5f, 1));
-
- List<Stone> stoneList = new ArrayList<Stone>();
-
- stoneList.add(new Stone(7, StoneColor.BLACK));
- Stone stone8 = new Stone(8, StoneColor.BLACK);
- stoneList.add(stone8);
- stoneList.add(new Stone(9, StoneColor.BLACK));
- stoneList.add(new Stone(10, StoneColor.BLACK));
+ GameState gameState = new GameState();
+ View view = new View();
- stoneSets.put(new StoneSet(stoneList), new Position(3.5f, 4));
+ gameState.getActivePlayer().getHand()
+ .drop(gameState.getGameHeap().drawStone(), new Position(0, 0));
- view.getTablePanel().setStoneSets(stoneSets);
+ TurnControl turnControl = new TurnControl(gameState.getActivePlayer()
+ .getHand(), gameState.getTable(), view);
- view.setSelectedStones(Arrays.asList(stoneJoker, stone8));
}
}
diff --git a/src/jrummikub/control/TurnControl.java b/src/jrummikub/control/TurnControl.java
index 40782de..26084e3 100644
--- a/src/jrummikub/control/TurnControl.java
+++ b/src/jrummikub/control/TurnControl.java
@@ -20,6 +20,7 @@ public class TurnControl {
this.hand = hand;
this.table = table;
this.view = view;
+ this.timer = new TurnTimer(view);
setup();
}
diff --git a/src/jrummikub/view/ITablePanel.java b/src/jrummikub/view/ITablePanel.java
index f17d1fe..5c4198c 100644
--- a/src/jrummikub/view/ITablePanel.java
+++ b/src/jrummikub/view/ITablePanel.java
@@ -5,6 +5,7 @@ import java.util.Map;
import jrummikub.model.Position;
import jrummikub.model.StoneSet;
import jrummikub.util.Event1;
+import jrummikub.util.Pair;
/**
* The view of the table, where the stone sets lie
@@ -40,7 +41,7 @@ public interface ITablePanel extends IStonePanel, IClickable {
* @param stoneSets
* set stone sets on the table
*/
- public void setStoneSets(Map<StoneSet, Position> stoneSets);
+ public void setStoneSets(Iterable<Pair<StoneSet, Position>> stoneSets);
/**
* Returns the stone collection (the panel showing the stones currently
diff --git a/src/jrummikub/view/impl/TablePanel.java b/src/jrummikub/view/impl/TablePanel.java
index abbb867..f400fac 100644
--- a/src/jrummikub/view/impl/TablePanel.java
+++ b/src/jrummikub/view/impl/TablePanel.java
@@ -45,7 +45,7 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
private JLabel leftPlayerLabel, topPlayerLabel, rightPlayerLabel;
private StoneCollectionPanel stoneCollection;
- private Map<StoneSet, Position> stoneSets = Collections.emptyMap();
+ private Iterable<Pair<StoneSet, Position>> stoneSets = Collections.emptySet();
private Collection<Stone> selectedStones = Collections.emptyList();
private Event1<StoneSet> leftConnectorClickEvent = new Event1<StoneSet>();
@@ -77,13 +77,13 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
}
@Override
- public void setStoneSets(Map<StoneSet, Position> stoneSets) {
+ public void setStoneSets(Iterable<Pair<StoneSet, Position>> stoneSets) {
Map<Stone, Position> stones = new HashMap<Stone, Position>();
- for (Map.Entry<StoneSet, Position> entry : stoneSets.entrySet()) {
- float x = entry.getValue().getX(), y = entry.getValue().getY();
+ for (Pair<StoneSet, Position> entry : stoneSets) {
+ float x = entry.getSecond().getX(), y = entry.getSecond().getY();
- for (Stone stone : entry.getKey()) {
+ for (Stone stone : entry.getFirst()) {
stones.put(stone, new Position(x, y));
x++;
}
@@ -156,9 +156,9 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
float minx = -MIN_VISIBLE_WIDTH / 2, maxx = MIN_VISIBLE_WIDTH / 2;
float miny = -MIN_VISIBLE_HEIGHT / 2, maxy = MIN_VISIBLE_HEIGHT / 2;
- for (Map.Entry<StoneSet, Position> entry : stoneSets.entrySet()) {
- Position p = entry.getValue();
- StoneSet stoneSet = entry.getKey();
+ for (Pair<StoneSet, Position> entry : stoneSets) {
+ Position p = entry.getSecond();
+ StoneSet stoneSet = entry.getFirst();
if (p.getX() < minx)
minx = p.getX();
@@ -205,9 +205,9 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
}
protected boolean handleOtherClickEvent(Position pos) {
- for (Map.Entry<StoneSet, Position> entry : stoneSets.entrySet()) {
- Position p = entry.getValue();
- StoneSet stoneSet = entry.getKey();
+ for (Pair<StoneSet, Position> entry : stoneSets) {
+ Position p = entry.getSecond();
+ StoneSet stoneSet = entry.getFirst();
float x = p.getX(), y = p.getY();
// left connector
@@ -281,8 +281,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
- for (Map.Entry<StoneSet, Position> entry : stoneSets.entrySet()) {
- paintStoneSet(g, entry.getKey(), entry.getValue());
+ for (Pair<StoneSet, Position> entry : stoneSets) {
+ paintStoneSet(g, entry.getFirst(), entry.getSecond());
}
g.setTransform(oldTransform);
diff --git a/test/jrummikub/control/TurnControlTest.java b/test/jrummikub/control/TurnControlTest.java
index 8c58352..8a2416f 100644
--- a/test/jrummikub/control/TurnControlTest.java
+++ b/test/jrummikub/control/TurnControlTest.java
@@ -21,7 +21,7 @@ import org.junit.Test;
public class TurnControlTest {
class MockTimer implements ITurnTimer {
- public boolean timerRunning;
+ public boolean timerRunning = false;
public Event timeRunOutEvent = new Event();
@Override
@@ -56,6 +56,11 @@ public class TurnControlTest {
}
@Test
+ public void startTimer() {
+ assertTrue(mockTimer.timerRunning);
+ }
+
+ @Test
public void viewEndOfTurn() {
eventFired = false;
mockTimer.timerRunning = true;
@@ -141,8 +146,8 @@ public class TurnControlTest {
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
- mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(
- firstStone, false);
+ mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone,
+ false);
assertCollection(Arrays.asList(secondStone));
}
@@ -156,8 +161,8 @@ public class TurnControlTest {
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
- mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(
- firstStone, true);
+ mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone,
+ true);
assertCollection(Arrays.asList(secondStone, firstStone));
}
@@ -262,8 +267,7 @@ public class TurnControlTest {
Stone stone2 = new Stone(2, StoneColor.RED);
Stone stone3 = new Stone(3, StoneColor.RED);
Stone stone4 = new Stone(4, StoneColor.RED);
- StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3,
- stone4));
+ StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3, stone4));
mockTable.findStoneSet.put(stone1, set1);
mockTable.findStoneSet.put(stone3, set1);
@@ -283,8 +287,7 @@ public class TurnControlTest {
Stone stone2 = new Stone(2, StoneColor.RED);
Stone stone3 = new Stone(3, StoneColor.RED);
Stone stone4 = new Stone(4, StoneColor.RED);
- StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3,
- stone4));
+ StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3, stone4));
mockTable.findStoneSet.put(stone1, set1);
mockTable.findStoneSet.put(stone3, set1);
diff --git a/test/jrummikub/view/MockTablePanel.java b/test/jrummikub/view/MockTablePanel.java
index 3fcc289..65842c2 100644
--- a/test/jrummikub/view/MockTablePanel.java
+++ b/test/jrummikub/view/MockTablePanel.java
@@ -9,20 +9,19 @@ import jrummikub.util.Event1;
import jrummikub.util.Event2;
import jrummikub.util.IEvent1;
import jrummikub.util.IEvent2;
+import jrummikub.util.Pair;
public class MockTablePanel implements ITablePanel {
public Event2<Stone, Boolean> stoneClickEvent = new Event2<Stone, Boolean>();
public Event2<Stone, Boolean> setClickEvent = new Event2<Stone, Boolean>();
public Event2<Stone, Boolean> rangeClickEvent = new Event2<Stone, Boolean>();
-
+
public MockStoneCollectionPanel stoneCollectionPanel = new MockStoneCollectionPanel();
public String leftPlayerName;
public String topPlayerName;
public String rightPlayerName;
-
-
@Override
public IEvent2<Stone, Boolean> getStoneClickEvent() {
// TODO Auto-generated method stub
@@ -63,7 +62,7 @@ public class MockTablePanel implements ITablePanel {
}
@Override
- public void setStoneSets(Map<StoneSet, Position> stoneSets) {
+ public void setStoneSets(Iterable<Pair<StoneSet, Position>> stoneSets) {
// TODO Auto-generated method stub
}