New main
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@127 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
b0a90ad6f0
commit
db7489a5c7
6 changed files with 40 additions and 224 deletions
|
@ -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();
|
||||
GameState gameState = new GameState();
|
||||
View view = new 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");
|
||||
gameState.getActivePlayer().getHand()
|
||||
.drop(gameState.getGameHeap().drawStone(), new Position(0, 0));
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
TurnControl turnControl = new TurnControl(gameState.getActivePlayer()
|
||||
.getHand(), gameState.getTable(), view);
|
||||
|
||||
// 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));
|
||||
|
||||
stoneSets.put(new StoneSet(stoneList), new Position(3.5f, 4));
|
||||
|
||||
view.getTablePanel().setStoneSets(stoneSets);
|
||||
|
||||
view.setSelectedStones(Arrays.asList(stoneJoker, stone8));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ public class TurnControl {
|
|||
this.hand = hand;
|
||||
this.table = table;
|
||||
this.view = view;
|
||||
this.timer = new TurnTimer(view);
|
||||
setup();
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
@ -55,6 +55,11 @@ public class TurnControlTest {
|
|||
testControl = new TurnControl(null, mockTable, mockView, mockTimer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startTimer() {
|
||||
assertTrue(mockTimer.timerRunning);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void viewEndOfTurn() {
|
||||
eventFired = false;
|
||||
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue