Ca. 150 Zeilen überflüssigen Code entfernt
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@463 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
bc835d499f
commit
ac3c13c50b
6 changed files with 339 additions and 416 deletions
mock/jrummikub/control/network
src/jrummikub/control
test/jrummikub/control/turn
|
@ -11,6 +11,7 @@ import jrummikub.util.MockEvent;
|
|||
import jrummikub.util.MockEvent1;
|
||||
import jrummikub.util.MockEvent2;
|
||||
|
||||
/** */
|
||||
public class MockConnectionControl implements IConnectionControl {
|
||||
/** */
|
||||
public String nickname;
|
||||
|
|
|
@ -18,6 +18,10 @@ import jrummikub.view.ISettingsPanel;
|
|||
import jrummikub.view.ISettingsPanel.SettingsMode;
|
||||
import jrummikub.view.IView;
|
||||
|
||||
/**
|
||||
* Abstract class for network game controls inbetween choosing and starting a
|
||||
* game
|
||||
*/
|
||||
public abstract class AbstractGameBeginControl {
|
||||
protected List<Connection> connections = new ArrayList<Connection>();
|
||||
protected GameData gameData;
|
||||
|
@ -25,6 +29,18 @@ public abstract class AbstractGameBeginControl {
|
|||
protected IView view;
|
||||
protected Event backEvent = new Event();
|
||||
|
||||
/**
|
||||
* Create a new game begin control
|
||||
*
|
||||
* @param connection
|
||||
* connection control for mesages and events
|
||||
* @param view
|
||||
* the view
|
||||
* @param gameData
|
||||
* game data of chosen game
|
||||
* @param settingsMode
|
||||
* mode of settings panel
|
||||
*/
|
||||
public AbstractGameBeginControl(IConnectionControl connection, IView view,
|
||||
final GameData gameData, SettingsMode settingsMode) {
|
||||
this.connectionControl = connection;
|
||||
|
@ -35,8 +51,29 @@ public abstract class AbstractGameBeginControl {
|
|||
view.getSettingsPanel().enableAddPlayerButton(false);
|
||||
updateSettingsPanel();
|
||||
|
||||
connections.add(view.getSettingsPanel().getBackEvent()
|
||||
.add(new IListener() {
|
||||
addViewListeners(view, gameData);
|
||||
|
||||
connections.add(connectionControl.getChangeColorEvent().add(
|
||||
new IListener2<String, Color>() {
|
||||
@Override
|
||||
public void handle(String sender, Color color) {
|
||||
List<PlayerSettings> players = gameData
|
||||
.getGameSettings().getPlayerList();
|
||||
for (PlayerSettings s : players) {
|
||||
if (s.getName().equals(sender)
|
||||
&& s.getType() == Type.NETWORK) {
|
||||
s.setColor(color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
updateSettingsPanel();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void addViewListeners(IView view, final GameData gameData) {
|
||||
connections.add(view.getSettingsPanel().getBackEvent().add(
|
||||
new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
goBack();
|
||||
|
@ -62,26 +99,16 @@ public abstract class AbstractGameBeginControl {
|
|||
updateSettingsPanel();
|
||||
}
|
||||
}));
|
||||
connections.add(connectionControl.getChangeColorEvent().add(
|
||||
new IListener2<String, Color>() {
|
||||
@Override
|
||||
public void handle(String sender, Color color) {
|
||||
List<PlayerSettings> players = gameData
|
||||
.getGameSettings().getPlayerList();
|
||||
for (PlayerSettings s : players) {
|
||||
if (s.getName().equals(sender)
|
||||
&& s.getType() == Type.NETWORK) {
|
||||
s.setColor(color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
updateSettingsPanel();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
protected abstract void goBack();
|
||||
|
||||
/**
|
||||
* The back event is emitted when the player wants to go back to the
|
||||
* previous control and panel
|
||||
*
|
||||
* @return the event
|
||||
*/
|
||||
public Event getBackEvent() {
|
||||
return backEvent;
|
||||
}
|
||||
|
@ -96,8 +123,8 @@ public abstract class AbstractGameBeginControl {
|
|||
protected void updateSettingsPanel() {
|
||||
view.getSettingsPanel().setGameSettings(gameData.getGameSettings());
|
||||
|
||||
Set<Color> colors = new HashSet<Color>(
|
||||
Arrays.asList(ISettingsPanel.PLAYER_COLORS));
|
||||
Set<Color> colors = new HashSet<Color>(Arrays
|
||||
.asList(ISettingsPanel.PLAYER_COLORS));
|
||||
|
||||
for (PlayerSettings player : gameData.getGameSettings().getPlayerList()) {
|
||||
colors.remove(player.getColor());
|
||||
|
|
|
@ -323,20 +323,25 @@ class ConnectionControl implements IConnectionControl {
|
|||
if (!currentGame.getGameID().equals(uuid)) {
|
||||
return;
|
||||
}
|
||||
if (messageType.equals("game_join")) {
|
||||
gameJoinEvent.emit(sender);
|
||||
} else if (messageType.equals("game_leave")) {
|
||||
gameLeaveEvent.emit(sender);
|
||||
} else if (messageType.equals("game_join_ack")) {
|
||||
gameJoinAckEvent
|
||||
.emit(Boolean.valueOf(extension.getValue("ack")));
|
||||
} else if (messageType.equals("change_color")) {
|
||||
changeColorEvent.emit(sender, (Color) Base64
|
||||
.decodeToObject(extension.getValue("color")));
|
||||
} else {
|
||||
System.err.println("Received unrecognized message of type '"
|
||||
+ messageType + "'");
|
||||
}
|
||||
messagesDuringGame(extension, sender, messageType);
|
||||
}
|
||||
}
|
||||
|
||||
private void messagesDuringGame(DefaultPacketExtension extension,
|
||||
String sender, String messageType) {
|
||||
if (messageType.equals("game_join")) {
|
||||
gameJoinEvent.emit(sender);
|
||||
} else if (messageType.equals("game_leave")) {
|
||||
gameLeaveEvent.emit(sender);
|
||||
} else if (messageType.equals("game_join_ack")) {
|
||||
gameJoinAckEvent
|
||||
.emit(Boolean.valueOf(extension.getValue("ack")));
|
||||
} else if (messageType.equals("change_color")) {
|
||||
changeColorEvent.emit(sender, (Color) Base64
|
||||
.decodeToObject(extension.getValue("color")));
|
||||
} else {
|
||||
System.err.println("Received unrecognized message of type '"
|
||||
+ messageType + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -85,17 +85,9 @@ public class AIControl extends AbstractTurnControl {
|
|||
List<Stone> tableStones = new ArrayList<Stone>();
|
||||
List<Stone> handStones = new ArrayList<Stone>();
|
||||
|
||||
for (Pair<Stone, Position> entry : turnInfo.getHand()) {
|
||||
handStones.add(entry.getFirst());
|
||||
}
|
||||
addHandStones(handStones);
|
||||
|
||||
if (turnInfo.getLaidOut()) {
|
||||
for (Pair<StoneSet, Position> entry : turnInfo.getTable()) {
|
||||
for (Stone stone : entry.getFirst()) {
|
||||
tableStones.add(stone);
|
||||
}
|
||||
}
|
||||
}
|
||||
addTableStones(tableStones);
|
||||
|
||||
logic = new TurnLogic(settings, tableStones, handStones);
|
||||
|
||||
|
@ -133,6 +125,22 @@ public class AIControl extends AbstractTurnControl {
|
|||
|
||||
}
|
||||
|
||||
private void addHandStones(List<Stone> handStones) {
|
||||
for (Pair<Stone, Position> entry : turnInfo.getHand()) {
|
||||
handStones.add(entry.getFirst());
|
||||
}
|
||||
}
|
||||
|
||||
private void addTableStones(List<Stone> tableStones) {
|
||||
if (turnInfo.getLaidOut()) {
|
||||
for (Pair<StoneSet, Position> entry : turnInfo.getTable()) {
|
||||
for (Stone stone : entry.getFirst()) {
|
||||
tableStones.add(stone);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void executeTurn() {
|
||||
if (turnDone) {
|
||||
return;
|
||||
|
@ -143,25 +151,7 @@ public class AIControl extends AbstractTurnControl {
|
|||
if (result != null) {
|
||||
|
||||
if (turnInfo.getLaidOut()) {
|
||||
outerLoop: for (Iterator<Pair<StoneSet, Position>> it = turnInfo
|
||||
.getTable().iterator(); it.hasNext();) {
|
||||
Pair<StoneSet, Position> pair = it.next();
|
||||
setSearch: for (Iterator<StoneSet> it2 = result.iterator(); it2
|
||||
.hasNext();) {
|
||||
StoneSet set = it2.next();
|
||||
if (set.getSize() != pair.getFirst().getSize()) {
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < set.getSize(); i++) {
|
||||
if (set.get(i) != pair.getFirst().get(i)) {
|
||||
continue setSearch;
|
||||
}
|
||||
}
|
||||
it2.remove();
|
||||
continue outerLoop;
|
||||
}
|
||||
it.remove();
|
||||
}
|
||||
doNotMoveExistingSets(result);
|
||||
}
|
||||
|
||||
for (StoneSet set : result) {
|
||||
|
@ -178,6 +168,29 @@ public class AIControl extends AbstractTurnControl {
|
|||
emitEndOfTurn();
|
||||
}
|
||||
|
||||
private void doNotMoveExistingSets(List<StoneSet> result) {
|
||||
|
||||
outerLoop: for (Iterator<Pair<StoneSet, Position>> it = turnInfo
|
||||
.getTable().iterator(); it.hasNext();) {
|
||||
Pair<StoneSet, Position> pair = it.next();
|
||||
setSearch: for (Iterator<StoneSet> it2 = result.iterator(); it2
|
||||
.hasNext();) {
|
||||
StoneSet set = it2.next();
|
||||
if (set.getSize() != pair.getFirst().getSize()) {
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < set.getSize(); i++) {
|
||||
if (set.get(i) != pair.getFirst().get(i)) {
|
||||
continue setSearch;
|
||||
}
|
||||
}
|
||||
it2.remove();
|
||||
continue outerLoop;
|
||||
}
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the factory for the base AI control
|
||||
*
|
||||
|
|
|
@ -38,7 +38,7 @@ public class AIControlTest {
|
|||
@Before
|
||||
public void setUp() {
|
||||
aiControl = TurnControlFactory.getFactory(Type.COMPUTER).create();
|
||||
((AIControl)aiControl).useBackgroundThread = false;
|
||||
((AIControl) aiControl).useBackgroundThread = false;
|
||||
gameSettings = new GameSettings();
|
||||
playerSettings = new PlayerSettings("ROBOT_01", Color.GRAY);
|
||||
player = new Player(playerSettings);
|
||||
|
@ -73,6 +73,7 @@ public class AIControlTest {
|
|||
|
||||
/**
|
||||
* @throws InterruptedException
|
||||
* if timeout
|
||||
*/
|
||||
@Test(timeout = 10000)
|
||||
public void testTurnZeroNoRedealing() throws InterruptedException {
|
||||
|
@ -86,6 +87,7 @@ public class AIControlTest {
|
|||
|
||||
/**
|
||||
* @throws InterruptedException
|
||||
* if timeout
|
||||
*/
|
||||
@Test(timeout = 10000)
|
||||
public void testTurnZeroNotMelding() throws InterruptedException {
|
||||
|
@ -101,6 +103,7 @@ public class AIControlTest {
|
|||
|
||||
/**
|
||||
* @throws InterruptedException
|
||||
* if timeout
|
||||
*/
|
||||
@Test(timeout = 10000)
|
||||
public void testNormalTurnMelding() throws InterruptedException {
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.junit.Test;
|
|||
* Tests for {@link HumanTurnControl}
|
||||
*/
|
||||
public class TurnControlTest {
|
||||
@SuppressWarnings("serial")
|
||||
static class AccessibleTable extends Table {
|
||||
StoneSet[] getSetArray() {
|
||||
return objects.keySet().toArray(new StoneSet[0]);
|
||||
|
@ -75,6 +76,28 @@ public class TurnControlTest {
|
|||
MockTable mockTable;
|
||||
MockHand mockHand;
|
||||
boolean eventFired;
|
||||
Stone blueOne = new Stone(1, BLUE);
|
||||
Stone redOne = new Stone(1, RED);
|
||||
Stone blackOne = new Stone(1, BLACK);
|
||||
Stone blueTwo = new Stone(2, BLUE);
|
||||
Stone blueThree = new Stone(3, BLUE);
|
||||
Stone blueFour = new Stone(4, BLUE);
|
||||
Stone redTwo = new Stone(2, RED);
|
||||
Stone redThree = new Stone(3, RED);
|
||||
Stone redFour = new Stone(4, RED);
|
||||
Stone blackTwo = new Stone(2, BLACK);
|
||||
Stone blackThree = new Stone(3, BLACK);
|
||||
Stone blackFour = new Stone(4, BLACK);
|
||||
Stone blackFive = new Stone(5, BLACK);
|
||||
Stone redJoker = new Stone(RED);
|
||||
Stone blackJoker = new Stone(BLACK);
|
||||
Stone orange10 = new Stone(10, StoneColor.ORANGE);
|
||||
Stone blue4a = new Stone(4, StoneColor.BLUE);
|
||||
Stone black5 = new Stone(5, StoneColor.BLACK);
|
||||
Stone orange13 = new Stone(13, StoneColor.ORANGE);
|
||||
Stone red11 = new Stone(11, StoneColor.RED);
|
||||
Stone black10 = new Stone(10, StoneColor.BLACK);
|
||||
Stone black13 = new Stone(13, StoneColor.BLACK);
|
||||
|
||||
private void checkTableDisplay(ITable table) {
|
||||
Iterator<Pair<StoneSet, Position>> stoneSetsView = mockView.tablePanel.stoneSets
|
||||
|
@ -110,8 +133,8 @@ public class TurnControlTest {
|
|||
mockPlayer = new MockPlayer(null, null);
|
||||
mockPlayer.hand = mockHand;
|
||||
testControl = new HumanTurnControl(mockTimer);
|
||||
testControl.setup(new ITurnControl.TurnInfo(mockTable,
|
||||
mockPlayer.getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN),
|
||||
testControl.setup(new ITurnControl.TurnInfo(mockTable, mockPlayer
|
||||
.getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN),
|
||||
new GameSettings(), mockView);
|
||||
}
|
||||
|
||||
|
@ -130,14 +153,14 @@ public class TurnControlTest {
|
|||
mockView.bottomPanelType = BottomPanelType.START_TURN_PANEL;
|
||||
|
||||
List<Pair<Stone, Position>> stones = Arrays.asList(
|
||||
new Pair<Stone, Position>(new Stone(RED), new Position(0, 0)),
|
||||
new Pair<Stone, Position>(new Stone(BLACK), new Position(1, 0)));
|
||||
new Pair<Stone, Position>(redJoker, new Position(0, 0)),
|
||||
new Pair<Stone, Position>(blackJoker, new Position(1, 0)));
|
||||
|
||||
mockHand.iterable = stones;
|
||||
|
||||
testControl = new HumanTurnControl(mockTimer);
|
||||
testControl.setup(new ITurnControl.TurnInfo(mockTable,
|
||||
mockPlayer.getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN),
|
||||
testControl.setup(new ITurnControl.TurnInfo(mockTable, mockPlayer
|
||||
.getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN),
|
||||
new GameSettings(), mockView);
|
||||
testControl.startTurn();
|
||||
|
||||
|
@ -215,19 +238,15 @@ public class TurnControlTest {
|
|||
public void selectStoneInHand() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone firstStone = new Stone(StoneColor.RED);
|
||||
|
||||
// Select first stone
|
||||
mockView.handPanel.stoneClickEvent.emit(firstStone, false);
|
||||
mockView.handPanel.stoneClickEvent.emit(redJoker, false);
|
||||
|
||||
assertCollection(Arrays.asList(firstStone));
|
||||
assertCollection(Arrays.asList(redJoker));
|
||||
|
||||
// Select second stone
|
||||
Stone secondStone = new Stone(StoneColor.BLACK);
|
||||
mockView.handPanel.stoneClickEvent.emit(secondStone, false);
|
||||
|
||||
assertCollection(Arrays.asList(secondStone));
|
||||
mockView.handPanel.stoneClickEvent.emit(blackJoker, false);
|
||||
|
||||
assertCollection(Arrays.asList(blackJoker));
|
||||
}
|
||||
|
||||
/** */
|
||||
|
@ -235,23 +254,20 @@ public class TurnControlTest {
|
|||
public void collectStoneInHand() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone firstStone = new Stone(StoneColor.RED);
|
||||
|
||||
// Select first stone
|
||||
mockView.handPanel.stoneClickEvent.emit(firstStone, true);
|
||||
mockView.handPanel.stoneClickEvent.emit(redJoker, true);
|
||||
|
||||
assertCollection(Arrays.asList(firstStone));
|
||||
assertCollection(Arrays.asList(redJoker));
|
||||
|
||||
// Select second stone
|
||||
Stone secondStone = new Stone(StoneColor.BLACK);
|
||||
mockView.handPanel.stoneClickEvent.emit(secondStone, true);
|
||||
mockView.handPanel.stoneClickEvent.emit(blackJoker, true);
|
||||
|
||||
assertCollection(Arrays.asList(firstStone, secondStone));
|
||||
assertCollection(Arrays.asList(redJoker, blackJoker));
|
||||
|
||||
// De-select first stone
|
||||
mockView.handPanel.stoneClickEvent.emit(firstStone, true);
|
||||
mockView.handPanel.stoneClickEvent.emit(redJoker, true);
|
||||
|
||||
assertCollection(Arrays.asList(secondStone));
|
||||
assertCollection(Arrays.asList(blackJoker));
|
||||
}
|
||||
|
||||
/** */
|
||||
|
@ -259,16 +275,13 @@ public class TurnControlTest {
|
|||
public void deselectStoneInCollection() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone firstStone = new Stone(StoneColor.RED);
|
||||
Stone secondStone = new Stone(StoneColor.BLACK);
|
||||
mockView.handPanel.stoneClickEvent.emit(redJoker, true);
|
||||
mockView.handPanel.stoneClickEvent.emit(blackJoker, true);
|
||||
|
||||
mockView.handPanel.stoneClickEvent.emit(firstStone, true);
|
||||
mockView.handPanel.stoneClickEvent.emit(secondStone, true);
|
||||
|
||||
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone,
|
||||
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(redJoker,
|
||||
false);
|
||||
|
||||
assertCollection(Arrays.asList(secondStone));
|
||||
assertCollection(Arrays.asList(blackJoker));
|
||||
}
|
||||
|
||||
/** */
|
||||
|
@ -276,16 +289,13 @@ public class TurnControlTest {
|
|||
public void reorderCollection() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone firstStone = new Stone(StoneColor.RED);
|
||||
Stone secondStone = new Stone(StoneColor.BLACK);
|
||||
mockView.handPanel.stoneClickEvent.emit(redJoker, true);
|
||||
mockView.handPanel.stoneClickEvent.emit(blackJoker, true);
|
||||
|
||||
mockView.handPanel.stoneClickEvent.emit(firstStone, true);
|
||||
mockView.handPanel.stoneClickEvent.emit(secondStone, true);
|
||||
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(
|
||||
blackJoker, true);
|
||||
|
||||
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone,
|
||||
true);
|
||||
|
||||
assertCollection(Arrays.asList(secondStone, firstStone));
|
||||
assertCollection(Arrays.asList(redJoker, blackJoker));
|
||||
}
|
||||
|
||||
/** */
|
||||
|
@ -293,16 +303,13 @@ public class TurnControlTest {
|
|||
public void deselectWholeCollection() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone firstStone = new Stone(StoneColor.RED);
|
||||
Stone secondStone = new Stone(StoneColor.BLACK);
|
||||
mockView.handPanel.stoneClickEvent.emit(redJoker, true);
|
||||
mockView.handPanel.stoneClickEvent.emit(blackJoker, true);
|
||||
|
||||
mockView.handPanel.stoneClickEvent.emit(firstStone, true);
|
||||
mockView.handPanel.stoneClickEvent.emit(secondStone, true);
|
||||
|
||||
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone,
|
||||
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(redJoker,
|
||||
true);
|
||||
|
||||
mockView.tablePanel.stoneCollectionPanel.setClickEvent.emit(firstStone,
|
||||
mockView.tablePanel.stoneCollectionPanel.setClickEvent.emit(redJoker,
|
||||
true);
|
||||
|
||||
assertCollection(new ArrayList<Stone>());
|
||||
|
@ -313,19 +320,13 @@ public class TurnControlTest {
|
|||
public void selectStoneOnTable() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone firstStone = new Stone(StoneColor.RED);
|
||||
|
||||
// Select first stone
|
||||
mockView.tablePanel.stoneClickEvent.emit(firstStone, false);
|
||||
|
||||
assertCollection(Arrays.asList(firstStone));
|
||||
mockView.tablePanel.stoneClickEvent.emit(redJoker, false);
|
||||
assertCollection(Arrays.asList(redJoker));
|
||||
|
||||
// Select second stone
|
||||
Stone secondStone = new Stone(StoneColor.BLACK);
|
||||
mockView.tablePanel.stoneClickEvent.emit(secondStone, false);
|
||||
|
||||
assertCollection(Arrays.asList(secondStone));
|
||||
|
||||
mockView.tablePanel.stoneClickEvent.emit(blackJoker, false);
|
||||
assertCollection(Arrays.asList(blackJoker));
|
||||
}
|
||||
|
||||
/** */
|
||||
|
@ -333,23 +334,17 @@ public class TurnControlTest {
|
|||
public void collectStoneOnTable() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone firstStone = new Stone(StoneColor.RED);
|
||||
|
||||
// Select first stone
|
||||
mockView.tablePanel.stoneClickEvent.emit(firstStone, true);
|
||||
|
||||
assertCollection(Arrays.asList(firstStone));
|
||||
mockView.tablePanel.stoneClickEvent.emit(redJoker, true);
|
||||
assertCollection(Arrays.asList(redJoker));
|
||||
|
||||
// Select second stone
|
||||
Stone secondStone = new Stone(StoneColor.BLACK);
|
||||
mockView.tablePanel.stoneClickEvent.emit(secondStone, true);
|
||||
|
||||
assertCollection(Arrays.asList(firstStone, secondStone));
|
||||
mockView.tablePanel.stoneClickEvent.emit(blackJoker, true);
|
||||
assertCollection(Arrays.asList(redJoker, blackJoker));
|
||||
|
||||
// De-select first stone
|
||||
mockView.tablePanel.stoneClickEvent.emit(firstStone, true);
|
||||
|
||||
assertCollection(Arrays.asList(secondStone));
|
||||
mockView.tablePanel.stoneClickEvent.emit(redJoker, true);
|
||||
assertCollection(Arrays.asList(blackJoker));
|
||||
}
|
||||
|
||||
/** */
|
||||
|
@ -357,22 +352,18 @@ public class TurnControlTest {
|
|||
public void selectSetOnTable() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone stone1 = new Stone(StoneColor.RED);
|
||||
Stone stone2 = new Stone(StoneColor.BLACK);
|
||||
StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2));
|
||||
Stone stone3 = new Stone(1, StoneColor.RED);
|
||||
Stone stone4 = new Stone(1, StoneColor.BLACK);
|
||||
StoneSet set2 = new StoneSet(Arrays.asList(stone3, stone4));
|
||||
StoneSet set1 = new StoneSet(Arrays.asList(redJoker, blackJoker));
|
||||
StoneSet set2 = new StoneSet(Arrays.asList(redOne, blackOne));
|
||||
|
||||
mockTable.findStoneSet.put(stone1, set1);
|
||||
mockTable.findStoneSet.put(stone4, set2);
|
||||
mockTable.findStoneSet.put(redJoker, set1);
|
||||
mockTable.findStoneSet.put(blackOne, set2);
|
||||
|
||||
mockView.tablePanel.stoneClickEvent.emit(stone1, false);
|
||||
mockView.tablePanel.setClickEvent.emit(stone1, false);
|
||||
assertCollection(Arrays.asList(stone1, stone2));
|
||||
mockView.tablePanel.stoneClickEvent.emit(stone4, false);
|
||||
mockView.tablePanel.setClickEvent.emit(stone4, false);
|
||||
assertCollection(Arrays.asList(stone3, stone4));
|
||||
mockView.tablePanel.stoneClickEvent.emit(redJoker, false);
|
||||
mockView.tablePanel.setClickEvent.emit(redJoker, false);
|
||||
assertCollection(Arrays.asList(redJoker, blackJoker));
|
||||
mockView.tablePanel.stoneClickEvent.emit(blackOne, false);
|
||||
mockView.tablePanel.setClickEvent.emit(blackOne, false);
|
||||
assertCollection(Arrays.asList(redOne, blackOne));
|
||||
}
|
||||
|
||||
/** */
|
||||
|
@ -380,22 +371,18 @@ public class TurnControlTest {
|
|||
public void collectSetOnTable() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone stone1 = new Stone(StoneColor.RED);
|
||||
Stone stone2 = new Stone(StoneColor.BLACK);
|
||||
StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2));
|
||||
Stone stone3 = new Stone(1, StoneColor.RED);
|
||||
Stone stone4 = new Stone(1, StoneColor.BLACK);
|
||||
StoneSet set2 = new StoneSet(Arrays.asList(stone3, stone4));
|
||||
StoneSet set1 = new StoneSet(Arrays.asList(redJoker, blackJoker));
|
||||
StoneSet set2 = new StoneSet(Arrays.asList(redOne, blackOne));
|
||||
|
||||
mockTable.findStoneSet.put(stone1, set1);
|
||||
mockTable.findStoneSet.put(stone4, set2);
|
||||
mockTable.findStoneSet.put(redJoker, set1);
|
||||
mockTable.findStoneSet.put(blackOne, set2);
|
||||
|
||||
mockView.tablePanel.stoneClickEvent.emit(stone1, true);
|
||||
mockView.tablePanel.setClickEvent.emit(stone1, true);
|
||||
assertCollection(Arrays.asList(stone1, stone2));
|
||||
mockView.tablePanel.stoneClickEvent.emit(stone4, true);
|
||||
mockView.tablePanel.setClickEvent.emit(stone4, true);
|
||||
assertCollection(Arrays.asList(stone1, stone2, stone3, stone4));
|
||||
mockView.tablePanel.stoneClickEvent.emit(redJoker, true);
|
||||
mockView.tablePanel.setClickEvent.emit(redJoker, true);
|
||||
assertCollection(Arrays.asList(redJoker, blackJoker));
|
||||
mockView.tablePanel.stoneClickEvent.emit(blackOne, true);
|
||||
mockView.tablePanel.setClickEvent.emit(blackOne, true);
|
||||
assertCollection(Arrays.asList(redJoker, blackJoker, redOne, blackOne));
|
||||
}
|
||||
|
||||
/** */
|
||||
|
@ -403,20 +390,16 @@ public class TurnControlTest {
|
|||
public void rangeSelectOnTableReverse() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone stone1 = new Stone(1, StoneColor.RED);
|
||||
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(redOne, redTwo, redThree,
|
||||
redFour));
|
||||
|
||||
mockTable.findStoneSet.put(stone1, set1);
|
||||
mockTable.findStoneSet.put(stone3, set1);
|
||||
mockTable.findStoneSet.put(redOne, set1);
|
||||
mockTable.findStoneSet.put(redThree, set1);
|
||||
|
||||
mockView.tablePanel.stoneClickEvent.emit(stone3, false);
|
||||
mockView.tablePanel.rangeClickEvent.emit(stone1, true);
|
||||
|
||||
assertCollection(Arrays.asList(stone1, stone2, stone3));
|
||||
mockView.tablePanel.stoneClickEvent.emit(redThree, false);
|
||||
mockView.tablePanel.rangeClickEvent.emit(redOne, true);
|
||||
|
||||
assertCollection(Arrays.asList(redOne, redTwo, redThree));
|
||||
}
|
||||
|
||||
/** */
|
||||
|
@ -424,20 +407,17 @@ public class TurnControlTest {
|
|||
public void rangeSelectOnTable() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone stone1 = new Stone(1, StoneColor.RED);
|
||||
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(redOne, redTwo, redThree,
|
||||
stone4));
|
||||
|
||||
mockTable.findStoneSet.put(stone1, set1);
|
||||
mockTable.findStoneSet.put(stone3, set1);
|
||||
mockTable.findStoneSet.put(redOne, set1);
|
||||
mockTable.findStoneSet.put(redThree, set1);
|
||||
|
||||
mockView.tablePanel.stoneClickEvent.emit(stone1, false);
|
||||
mockView.tablePanel.rangeClickEvent.emit(stone3, true);
|
||||
|
||||
assertCollection(Arrays.asList(stone1, stone2, stone3));
|
||||
mockView.tablePanel.stoneClickEvent.emit(redOne, false);
|
||||
mockView.tablePanel.rangeClickEvent.emit(redThree, true);
|
||||
|
||||
assertCollection(Arrays.asList(redOne, redTwo, redThree));
|
||||
}
|
||||
|
||||
/** */
|
||||
|
@ -445,23 +425,18 @@ public class TurnControlTest {
|
|||
public void rangeCollectOnTable() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone extraStone = new Stone(StoneColor.RED);
|
||||
StoneSet set1 = new StoneSet(Arrays.asList(redOne, redTwo, redThree,
|
||||
redFour));
|
||||
|
||||
Stone stone1 = new Stone(1, StoneColor.RED);
|
||||
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));
|
||||
mockTable.findStoneSet.put(redOne, set1);
|
||||
mockTable.findStoneSet.put(redThree, set1);
|
||||
|
||||
mockTable.findStoneSet.put(stone1, set1);
|
||||
mockTable.findStoneSet.put(stone3, set1);
|
||||
mockView.tablePanel.stoneClickEvent.emit(redJoker, false);
|
||||
|
||||
mockView.tablePanel.stoneClickEvent.emit(extraStone, false);
|
||||
mockView.tablePanel.stoneClickEvent.emit(redOne, true);
|
||||
mockView.tablePanel.rangeClickEvent.emit(redThree, false);
|
||||
|
||||
mockView.tablePanel.stoneClickEvent.emit(stone1, true);
|
||||
mockView.tablePanel.rangeClickEvent.emit(stone3, false);
|
||||
|
||||
assertCollection(Arrays.asList(extraStone, stone1, stone2, stone3));
|
||||
assertCollection(Arrays.asList(redJoker, redOne, redTwo, redThree));
|
||||
}
|
||||
|
||||
/** */
|
||||
|
@ -469,24 +444,19 @@ public class TurnControlTest {
|
|||
public void rangeFailSelect() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone stone1 = new Stone(1, StoneColor.RED);
|
||||
Stone stone2 = new Stone(2, StoneColor.RED);
|
||||
StoneSet set1 = new StoneSet(Arrays.asList(stone1));
|
||||
StoneSet set2 = new StoneSet(Arrays.asList(stone2));
|
||||
StoneSet set1 = new StoneSet(Arrays.asList(redOne));
|
||||
StoneSet set2 = new StoneSet(Arrays.asList(redTwo));
|
||||
|
||||
mockTable.findStoneSet.put(stone1, set1);
|
||||
mockTable.findStoneSet.put(stone2, set2);
|
||||
mockTable.findStoneSet.put(redOne, set1);
|
||||
mockTable.findStoneSet.put(redTwo, set2);
|
||||
|
||||
// Select first stone
|
||||
mockView.tablePanel.stoneClickEvent.emit(stone1, false);
|
||||
|
||||
assertCollection(Arrays.asList(stone1));
|
||||
mockView.tablePanel.stoneClickEvent.emit(redOne, false);
|
||||
assertCollection(Arrays.asList(redOne));
|
||||
|
||||
// Select second stone
|
||||
mockView.tablePanel.rangeClickEvent.emit(stone2, false);
|
||||
|
||||
assertCollection(Arrays.asList(stone1, stone2));
|
||||
|
||||
mockView.tablePanel.rangeClickEvent.emit(redTwo, false);
|
||||
assertCollection(Arrays.asList(redOne, redTwo));
|
||||
}
|
||||
|
||||
/** */
|
||||
|
@ -494,23 +464,19 @@ public class TurnControlTest {
|
|||
public void rangeFailCollect() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone stone1 = new Stone(1, StoneColor.RED);
|
||||
Stone stone2 = new Stone(2, StoneColor.RED);
|
||||
StoneSet set1 = new StoneSet(Arrays.asList(stone1));
|
||||
StoneSet set2 = new StoneSet(Arrays.asList(stone2));
|
||||
StoneSet set1 = new StoneSet(Arrays.asList(redOne));
|
||||
StoneSet set2 = new StoneSet(Arrays.asList(redTwo));
|
||||
|
||||
mockTable.findStoneSet.put(stone1, set1);
|
||||
mockTable.findStoneSet.put(stone2, set2);
|
||||
mockTable.findStoneSet.put(redOne, set1);
|
||||
mockTable.findStoneSet.put(redTwo, set2);
|
||||
|
||||
// Select first stone
|
||||
mockView.tablePanel.stoneClickEvent.emit(stone1, true);
|
||||
|
||||
assertCollection(Arrays.asList(stone1));
|
||||
mockView.tablePanel.stoneClickEvent.emit(redOne, true);
|
||||
assertCollection(Arrays.asList(redOne));
|
||||
|
||||
// Select second stone
|
||||
mockView.tablePanel.rangeClickEvent.emit(stone2, true);
|
||||
|
||||
assertCollection(Arrays.asList(stone1, stone2));
|
||||
mockView.tablePanel.rangeClickEvent.emit(redTwo, true);
|
||||
assertCollection(Arrays.asList(redOne, redTwo));
|
||||
}
|
||||
|
||||
/** */
|
||||
|
@ -518,19 +484,15 @@ public class TurnControlTest {
|
|||
public void rangeSelectOnHandReverse() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone stone1 = new Stone(1, StoneColor.RED);
|
||||
Stone stone2 = new Stone(2, StoneColor.RED);
|
||||
Stone stone3 = new Stone(3, StoneColor.RED);
|
||||
Stone stone4 = new Stone(4, StoneColor.RED);
|
||||
mockHand.drop(stone1, new Position(0, 0));
|
||||
mockHand.drop(stone2, new Position(1.5f, 0));
|
||||
mockHand.drop(stone3, new Position(0, 1));
|
||||
mockHand.drop(stone4, new Position(1, 1));
|
||||
mockHand.drop(redOne, new Position(0, 0));
|
||||
mockHand.drop(redTwo, new Position(1.5f, 0));
|
||||
mockHand.drop(redThree, new Position(0, 1));
|
||||
mockHand.drop(redFour, new Position(1, 1));
|
||||
|
||||
mockView.handPanel.stoneClickEvent.emit(stone3, false);
|
||||
mockView.handPanel.rangeClickEvent.emit(stone1, true);
|
||||
mockView.handPanel.stoneClickEvent.emit(redThree, false);
|
||||
mockView.handPanel.rangeClickEvent.emit(redOne, true);
|
||||
|
||||
assertCollection(Arrays.asList(stone1, stone2, stone3));
|
||||
assertCollection(Arrays.asList(redOne, redTwo, redThree));
|
||||
}
|
||||
|
||||
/** */
|
||||
|
@ -538,19 +500,15 @@ public class TurnControlTest {
|
|||
public void rangeSelectOnHand() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone stone1 = new Stone(1, StoneColor.RED);
|
||||
Stone stone2 = new Stone(2, StoneColor.RED);
|
||||
Stone stone3 = new Stone(3, StoneColor.RED);
|
||||
Stone stone4 = new Stone(4, StoneColor.RED);
|
||||
mockHand.drop(stone1, new Position(0, 0));
|
||||
mockHand.drop(stone2, new Position(1.5f, 0));
|
||||
mockHand.drop(stone3, new Position(0, 1));
|
||||
mockHand.drop(stone4, new Position(1, 1));
|
||||
mockHand.drop(redOne, new Position(0, 0));
|
||||
mockHand.drop(redTwo, new Position(1.5f, 0));
|
||||
mockHand.drop(redThree, new Position(0, 1));
|
||||
mockHand.drop(redFour, new Position(1, 1));
|
||||
|
||||
mockView.handPanel.stoneClickEvent.emit(stone1, false);
|
||||
mockView.handPanel.rangeClickEvent.emit(stone3, true);
|
||||
mockView.handPanel.stoneClickEvent.emit(redOne, false);
|
||||
mockView.handPanel.rangeClickEvent.emit(redThree, true);
|
||||
|
||||
assertCollection(Arrays.asList(stone1, stone2, stone3));
|
||||
assertCollection(Arrays.asList(redOne, redTwo, redThree));
|
||||
}
|
||||
|
||||
/** */
|
||||
|
@ -558,22 +516,16 @@ public class TurnControlTest {
|
|||
public void rangeCollectOnHand() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone extraStone = new Stone(StoneColor.RED);
|
||||
mockHand.drop(redOne, new Position(0, 0));
|
||||
mockHand.drop(redTwo, new Position(1.5f, 0));
|
||||
mockHand.drop(redThree, new Position(0, 1));
|
||||
mockHand.drop(redFour, new Position(1, 1));
|
||||
|
||||
Stone stone1 = new Stone(1, StoneColor.RED);
|
||||
Stone stone2 = new Stone(2, StoneColor.RED);
|
||||
Stone stone3 = new Stone(3, StoneColor.RED);
|
||||
Stone stone4 = new Stone(4, StoneColor.RED);
|
||||
mockHand.drop(stone1, new Position(0, 0));
|
||||
mockHand.drop(stone2, new Position(1.5f, 0));
|
||||
mockHand.drop(stone3, new Position(0, 1));
|
||||
mockHand.drop(stone4, new Position(1, 1));
|
||||
mockView.handPanel.stoneClickEvent.emit(redJoker, false);
|
||||
|
||||
mockView.handPanel.stoneClickEvent.emit(extraStone, false);
|
||||
|
||||
mockView.handPanel.stoneClickEvent.emit(stone1, true);
|
||||
mockView.handPanel.rangeClickEvent.emit(stone3, false);
|
||||
assertCollection(Arrays.asList(extraStone, stone1, stone2, stone3));
|
||||
mockView.handPanel.stoneClickEvent.emit(redOne, true);
|
||||
mockView.handPanel.rangeClickEvent.emit(redThree, false);
|
||||
assertCollection(Arrays.asList(redJoker, redOne, redTwo, redThree));
|
||||
}
|
||||
|
||||
/** */
|
||||
|
@ -581,21 +533,18 @@ public class TurnControlTest {
|
|||
public void rangeFailSelectHand() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone stone1 = new Stone(1, StoneColor.RED);
|
||||
Stone stone2 = new Stone(2, StoneColor.RED);
|
||||
StoneSet set1 = new StoneSet(Arrays.asList(stone1));
|
||||
mockTable.findStoneSet.put(stone1, set1);
|
||||
mockHand.drop(stone2, new Position(0, 0));
|
||||
StoneSet set1 = new StoneSet(Arrays.asList(redOne));
|
||||
mockTable.findStoneSet.put(redOne, set1);
|
||||
mockHand.drop(redTwo, new Position(0, 0));
|
||||
// Select first stone
|
||||
mockView.tablePanel.stoneClickEvent.emit(stone1, false);
|
||||
mockView.tablePanel.stoneClickEvent.emit(redOne, false);
|
||||
|
||||
assertCollection(Arrays.asList(stone1));
|
||||
assertCollection(Arrays.asList(redOne));
|
||||
|
||||
// Select second stone
|
||||
mockView.handPanel.rangeClickEvent.emit(stone2, false);
|
||||
|
||||
assertCollection(Arrays.asList(stone1, stone2));
|
||||
mockView.handPanel.rangeClickEvent.emit(redTwo, false);
|
||||
|
||||
assertCollection(Arrays.asList(redOne, redTwo));
|
||||
}
|
||||
|
||||
/** */
|
||||
|
@ -603,20 +552,16 @@ public class TurnControlTest {
|
|||
public void rangeFailCollectHand() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone stone1 = new Stone(1, StoneColor.RED);
|
||||
Stone stone2 = new Stone(2, StoneColor.RED);
|
||||
StoneSet set1 = new StoneSet(Arrays.asList(stone1));
|
||||
mockTable.findStoneSet.put(stone1, set1);
|
||||
mockHand.drop(stone2, new Position(0, 0));
|
||||
StoneSet set1 = new StoneSet(Arrays.asList(redOne));
|
||||
mockTable.findStoneSet.put(redOne, set1);
|
||||
mockHand.drop(redTwo, new Position(0, 0));
|
||||
// Select first stone
|
||||
mockView.tablePanel.stoneClickEvent.emit(stone1, false);
|
||||
|
||||
assertCollection(Arrays.asList(stone1));
|
||||
mockView.tablePanel.stoneClickEvent.emit(redOne, false);
|
||||
assertCollection(Arrays.asList(redOne));
|
||||
|
||||
// Select second stone
|
||||
mockView.handPanel.rangeClickEvent.emit(stone2, true);
|
||||
|
||||
assertCollection(Arrays.asList(stone1, stone2));
|
||||
mockView.handPanel.rangeClickEvent.emit(redTwo, true);
|
||||
assertCollection(Arrays.asList(redOne, redTwo));
|
||||
}
|
||||
|
||||
private void assertCollection(List<Stone> expected) {
|
||||
|
@ -631,27 +576,15 @@ public class TurnControlTest {
|
|||
public void testAddLeft() {
|
||||
AccessibleTable table = new AccessibleTable();
|
||||
HumanTurnControl turnControl = new HumanTurnControl(mockTimer);
|
||||
turnControl.setup(new ITurnControl.TurnInfo(table, mockPlayer.getHand(),
|
||||
mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), new GameSettings(),
|
||||
mockView);
|
||||
turnControl.setup(new ITurnControl.TurnInfo(table,
|
||||
mockPlayer.getHand(), mockPlayer.getLaidOut(),
|
||||
TurnMode.NORMAL_TURN), new GameSettings(), mockView);
|
||||
turnControl.startTurn();
|
||||
Stone blueOne = new Stone(1, BLUE);
|
||||
Stone redOne = new Stone(1, RED);
|
||||
Stone blackOne = new Stone(1, BLACK);
|
||||
Stone blueTwo = new Stone(2, BLUE);
|
||||
Stone blueThree = new Stone(3, BLUE);
|
||||
Stone blueFour = new Stone(4, BLUE);
|
||||
Stone redTwo = new Stone(2, RED);
|
||||
Stone redThree = new Stone(3, RED);
|
||||
Stone redFour = new Stone(4, RED);
|
||||
Stone blackTwo = new Stone(2, BLACK);
|
||||
Stone blackThree = new Stone(3, BLACK);
|
||||
Stone blackFour = new Stone(4, BLACK);
|
||||
Stone blackFive = new Stone(5, BLACK);
|
||||
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne,
|
||||
redTwo, redThree, redFour, blackTwo, blackThree));
|
||||
StoneSet oldSet2 = new StoneSet(
|
||||
Arrays.asList(blueTwo, blackFour, blackFive));
|
||||
|
||||
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
|
||||
blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
|
||||
StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
|
||||
blackFive));
|
||||
table.drop(oldSet1, new Position(0, 0));
|
||||
table.drop(oldSet2, new Position(0, 0));
|
||||
mockHand.drop(blueThree, new Position(0, 0));
|
||||
|
@ -750,27 +683,14 @@ public class TurnControlTest {
|
|||
public void testAddRight() {
|
||||
AccessibleTable table = new AccessibleTable();
|
||||
HumanTurnControl turnControl = new HumanTurnControl(mockTimer);
|
||||
turnControl.setup(new ITurnControl.TurnInfo(table, mockPlayer.getHand(),
|
||||
mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), new GameSettings(),
|
||||
mockView);
|
||||
turnControl.setup(new ITurnControl.TurnInfo(table,
|
||||
mockPlayer.getHand(), mockPlayer.getLaidOut(),
|
||||
TurnMode.NORMAL_TURN), new GameSettings(), mockView);
|
||||
turnControl.startTurn();
|
||||
Stone blueOne = new Stone(1, BLUE);
|
||||
Stone redOne = new Stone(1, RED);
|
||||
Stone blackOne = new Stone(1, BLACK);
|
||||
Stone blueTwo = new Stone(2, BLUE);
|
||||
Stone blueThree = new Stone(3, BLUE);
|
||||
Stone blueFour = new Stone(4, BLUE);
|
||||
Stone redTwo = new Stone(2, RED);
|
||||
Stone redThree = new Stone(3, RED);
|
||||
Stone redFour = new Stone(4, RED);
|
||||
Stone blackTwo = new Stone(2, BLACK);
|
||||
Stone blackThree = new Stone(3, BLACK);
|
||||
Stone blackFour = new Stone(4, BLACK);
|
||||
Stone blackFive = new Stone(5, BLACK);
|
||||
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne,
|
||||
redTwo, redThree, redFour, blackTwo, blackThree));
|
||||
StoneSet oldSet2 = new StoneSet(
|
||||
Arrays.asList(blueTwo, blackFour, blackFive));
|
||||
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
|
||||
blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
|
||||
StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
|
||||
blackFive));
|
||||
table.drop(oldSet1, new Position(0, 0));
|
||||
table.drop(oldSet2, new Position(0, 0));
|
||||
mockHand.drop(blueThree, new Position(0, 0));
|
||||
|
@ -869,27 +789,14 @@ public class TurnControlTest {
|
|||
public void testAddNewSet() {
|
||||
AccessibleTable table = new AccessibleTable();
|
||||
HumanTurnControl turnControl = new HumanTurnControl(mockTimer);
|
||||
turnControl.setup(new ITurnControl.TurnInfo(table, mockPlayer.getHand(),
|
||||
mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), new GameSettings(),
|
||||
mockView);
|
||||
turnControl.setup(new ITurnControl.TurnInfo(table,
|
||||
mockPlayer.getHand(), mockPlayer.getLaidOut(),
|
||||
TurnMode.NORMAL_TURN), new GameSettings(), mockView);
|
||||
turnControl.startTurn();
|
||||
Stone blueOne = new Stone(1, BLUE);
|
||||
Stone redOne = new Stone(1, RED);
|
||||
Stone blackOne = new Stone(1, BLACK);
|
||||
Stone blueTwo = new Stone(2, BLUE);
|
||||
Stone blueThree = new Stone(3, BLUE);
|
||||
Stone blueFour = new Stone(4, BLUE);
|
||||
Stone redTwo = new Stone(2, RED);
|
||||
Stone redThree = new Stone(3, RED);
|
||||
Stone redFour = new Stone(4, RED);
|
||||
Stone blackTwo = new Stone(2, BLACK);
|
||||
Stone blackThree = new Stone(3, BLACK);
|
||||
Stone blackFour = new Stone(4, BLACK);
|
||||
Stone blackFive = new Stone(5, BLACK);
|
||||
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne,
|
||||
redTwo, redThree, redFour, blackTwo, blackThree));
|
||||
StoneSet oldSet2 = new StoneSet(
|
||||
Arrays.asList(blueTwo, blackFour, blackFive));
|
||||
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
|
||||
blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
|
||||
StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
|
||||
blackFive));
|
||||
table.drop(oldSet1, new Position(0, 0));
|
||||
table.drop(oldSet2, new Position(0, 0));
|
||||
mockHand.drop(blueThree, new Position(0, 0));
|
||||
|
@ -962,28 +869,15 @@ public class TurnControlTest {
|
|||
public void testSortByGroups() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone red1 = new Stone(1, StoneColor.RED);
|
||||
Stone blue2 = new Stone(2, StoneColor.BLUE);
|
||||
Stone red4 = new Stone(4, StoneColor.RED);
|
||||
Stone red3 = new Stone(3, StoneColor.RED);
|
||||
Stone orange10 = new Stone(10, StoneColor.ORANGE);
|
||||
Stone blue1 = new Stone(1, StoneColor.BLUE);
|
||||
Stone blue4 = new Stone(4, StoneColor.BLUE);
|
||||
Stone blue4a = new Stone(4, StoneColor.BLUE);
|
||||
Stone joker = new Stone(StoneColor.BLACK);
|
||||
Stone black5 = new Stone(5, StoneColor.BLACK);
|
||||
Stone orange13 = new Stone(13, StoneColor.ORANGE);
|
||||
Stone red11 = new Stone(11, StoneColor.RED);
|
||||
Stone black10 = new Stone(10, StoneColor.BLACK);
|
||||
mockHand.drop(red1, new Position(0, 0));
|
||||
mockHand.drop(blue2, new Position(0, 0));
|
||||
mockHand.drop(red4, new Position(0, 0));
|
||||
mockHand.drop(red3, new Position(0, 0));
|
||||
mockHand.drop(redOne, new Position(0, 0));
|
||||
mockHand.drop(blueTwo, new Position(0, 0));
|
||||
mockHand.drop(redFour, new Position(0, 0));
|
||||
mockHand.drop(redThree, new Position(0, 0));
|
||||
mockHand.drop(orange10, new Position(0, 0));
|
||||
mockHand.drop(blue1, new Position(0, 0));
|
||||
mockHand.drop(blue4, new Position(0, 0));
|
||||
mockHand.drop(blueOne, new Position(0, 0));
|
||||
mockHand.drop(blueFour, new Position(0, 0));
|
||||
mockHand.drop(blue4a, new Position(0, 0));
|
||||
mockHand.drop(joker, new Position(0, 0));
|
||||
mockHand.drop(blackJoker, new Position(0, 0));
|
||||
mockHand.drop(black5, new Position(0, 0));
|
||||
mockHand.drop(orange13, new Position(0, 0));
|
||||
mockHand.drop(red11, new Position(0, 0));
|
||||
|
@ -993,28 +887,28 @@ public class TurnControlTest {
|
|||
|
||||
List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>(
|
||||
mockHand.stones);
|
||||
Collections
|
||||
.sort(stones, new HumanTurnControl.HandStonePositionComparator());
|
||||
Collections.sort(stones,
|
||||
new HumanTurnControl.HandStonePositionComparator());
|
||||
|
||||
assertEquals(stones.size(), 13);
|
||||
|
||||
assertSame(stones.get(0).getFirst(), blue1);
|
||||
assertSame(stones.get(1).getFirst(), red1);
|
||||
assertSame(stones.get(2).getFirst(), blue2);
|
||||
assertSame(stones.get(3).getFirst(), red3);
|
||||
assertSame(stones.get(0).getFirst(), blueOne);
|
||||
assertSame(stones.get(1).getFirst(), redOne);
|
||||
assertSame(stones.get(2).getFirst(), blueTwo);
|
||||
assertSame(stones.get(3).getFirst(), redThree);
|
||||
|
||||
assertTrue(stones.get(4).getFirst() == blue4
|
||||
assertTrue(stones.get(4).getFirst() == blueFour
|
||||
|| stones.get(4).getFirst() == blue4a);
|
||||
assertTrue(stones.get(5).getFirst() == blue4
|
||||
assertTrue(stones.get(5).getFirst() == blueFour
|
||||
|| stones.get(5).getFirst() == blue4a);
|
||||
|
||||
assertSame(stones.get(6).getFirst(), red4);
|
||||
assertSame(stones.get(6).getFirst(), redFour);
|
||||
assertSame(stones.get(7).getFirst(), black5);
|
||||
assertSame(stones.get(8).getFirst(), black10);
|
||||
assertSame(stones.get(9).getFirst(), orange10);
|
||||
assertSame(stones.get(10).getFirst(), red11);
|
||||
assertSame(stones.get(11).getFirst(), orange13);
|
||||
assertSame(stones.get(12).getFirst(), joker);
|
||||
assertSame(stones.get(12).getFirst(), blackJoker);
|
||||
|
||||
checkHandDisplay(mockHand);
|
||||
}
|
||||
|
@ -1024,28 +918,15 @@ public class TurnControlTest {
|
|||
public void testSortByRuns() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone red1 = new Stone(1, StoneColor.RED);
|
||||
Stone blue2 = new Stone(2, StoneColor.BLUE);
|
||||
Stone red4 = new Stone(4, StoneColor.RED);
|
||||
Stone red3 = new Stone(3, StoneColor.RED);
|
||||
Stone orange10 = new Stone(10, StoneColor.ORANGE);
|
||||
Stone blue1 = new Stone(1, StoneColor.BLUE);
|
||||
Stone blue4 = new Stone(4, StoneColor.BLUE);
|
||||
Stone blue4a = new Stone(4, StoneColor.BLUE);
|
||||
Stone joker = new Stone(StoneColor.BLACK);
|
||||
Stone black5 = new Stone(5, StoneColor.BLACK);
|
||||
Stone orange13 = new Stone(13, StoneColor.ORANGE);
|
||||
Stone red11 = new Stone(11, StoneColor.RED);
|
||||
Stone black10 = new Stone(10, StoneColor.BLACK);
|
||||
mockHand.drop(red1, new Position(0, 0));
|
||||
mockHand.drop(blue2, new Position(0, 0));
|
||||
mockHand.drop(red4, new Position(0, 0));
|
||||
mockHand.drop(red3, new Position(0, 0));
|
||||
mockHand.drop(redOne, new Position(0, 0));
|
||||
mockHand.drop(blueTwo, new Position(0, 0));
|
||||
mockHand.drop(redFour, new Position(0, 0));
|
||||
mockHand.drop(redThree, new Position(0, 0));
|
||||
mockHand.drop(orange10, new Position(0, 0));
|
||||
mockHand.drop(blue1, new Position(0, 0));
|
||||
mockHand.drop(blue4, new Position(0, 0));
|
||||
mockHand.drop(blueOne, new Position(0, 0));
|
||||
mockHand.drop(blueFour, new Position(0, 0));
|
||||
mockHand.drop(blue4a, new Position(0, 0));
|
||||
mockHand.drop(joker, new Position(0, 0));
|
||||
mockHand.drop(blackJoker, new Position(0, 0));
|
||||
mockHand.drop(black5, new Position(0, 0));
|
||||
mockHand.drop(orange13, new Position(0, 0));
|
||||
mockHand.drop(red11, new Position(0, 0));
|
||||
|
@ -1055,8 +936,8 @@ public class TurnControlTest {
|
|||
|
||||
List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>(
|
||||
mockHand.stones);
|
||||
Collections
|
||||
.sort(stones, new HumanTurnControl.HandStonePositionComparator());
|
||||
Collections.sort(stones,
|
||||
new HumanTurnControl.HandStonePositionComparator());
|
||||
|
||||
assertEquals(stones.size(), 13);
|
||||
|
||||
|
@ -1064,19 +945,19 @@ public class TurnControlTest {
|
|||
assertSame(stones.get(1).getFirst(), black10);
|
||||
assertSame(stones.get(2).getFirst(), orange10);
|
||||
assertSame(stones.get(3).getFirst(), orange13);
|
||||
assertSame(stones.get(4).getFirst(), blue1);
|
||||
assertSame(stones.get(5).getFirst(), blue2);
|
||||
assertSame(stones.get(4).getFirst(), blueOne);
|
||||
assertSame(stones.get(5).getFirst(), blueTwo);
|
||||
|
||||
assertTrue(stones.get(6).getFirst() == blue4
|
||||
assertTrue(stones.get(6).getFirst() == blueFour
|
||||
|| stones.get(6).getFirst() == blue4a);
|
||||
assertTrue(stones.get(7).getFirst() == blue4
|
||||
assertTrue(stones.get(7).getFirst() == blueFour
|
||||
|| stones.get(7).getFirst() == blue4a);
|
||||
|
||||
assertSame(stones.get(8).getFirst(), red1);
|
||||
assertSame(stones.get(9).getFirst(), red3);
|
||||
assertSame(stones.get(10).getFirst(), red4);
|
||||
assertSame(stones.get(8).getFirst(), redOne);
|
||||
assertSame(stones.get(9).getFirst(), redThree);
|
||||
assertSame(stones.get(10).getFirst(), redFour);
|
||||
assertSame(stones.get(11).getFirst(), red11);
|
||||
assertSame(stones.get(12).getFirst(), joker);
|
||||
assertSame(stones.get(12).getFirst(), blackJoker);
|
||||
|
||||
checkHandDisplay(mockHand);
|
||||
}
|
||||
|
@ -1086,21 +967,18 @@ public class TurnControlTest {
|
|||
public void testDropHandValid() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone firstStone = new Stone(StoneColor.RED);
|
||||
Stone secondStone = new Stone(StoneColor.BLACK);
|
||||
mockHand.drop(redJoker, new Position(0, 0));
|
||||
mockHand.drop(blackJoker, new Position(1, 0));
|
||||
|
||||
mockHand.drop(firstStone, new Position(0, 0));
|
||||
mockHand.drop(secondStone, new Position(1, 0));
|
||||
|
||||
mockView.handPanel.stoneClickEvent.emit(firstStone, true);
|
||||
mockView.handPanel.stoneClickEvent.emit(secondStone, true);
|
||||
mockView.handPanel.stoneClickEvent.emit(redJoker, true);
|
||||
mockView.handPanel.stoneClickEvent.emit(blackJoker, true);
|
||||
|
||||
mockView.handPanel.clickEvent.emit(new Position(2, 0.25f));
|
||||
|
||||
assertCollection(new ArrayList<Stone>());
|
||||
|
||||
Set<Stone> expected = new HashSet<Stone>(Arrays.asList(firstStone,
|
||||
secondStone));
|
||||
Set<Stone> expected = new HashSet<Stone>(Arrays.asList(redJoker,
|
||||
blackJoker));
|
||||
assertEquals(expected, mockHand.pickups);
|
||||
|
||||
Set<Stone> handStones = new HashSet<Stone>();
|
||||
|
@ -1116,23 +994,19 @@ public class TurnControlTest {
|
|||
public void testDropHandInvalid() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone firstStone = new Stone(StoneColor.RED);
|
||||
Stone secondStone = new Stone(StoneColor.BLACK);
|
||||
Stone thirdStone = new Stone(13, StoneColor.BLACK);
|
||||
mockHand.drop(redJoker, new Position(0, 0));
|
||||
mockHand.drop(black13, new Position(1, 0));
|
||||
|
||||
mockHand.drop(firstStone, new Position(0, 0));
|
||||
mockHand.drop(thirdStone, new Position(1, 0));
|
||||
|
||||
mockView.handPanel.stoneClickEvent.emit(firstStone, true);
|
||||
mockView.tablePanel.stoneClickEvent.emit(secondStone, true);
|
||||
mockView.handPanel.stoneClickEvent.emit(thirdStone, true);
|
||||
mockView.handPanel.stoneClickEvent.emit(redJoker, true);
|
||||
mockView.tablePanel.stoneClickEvent.emit(blackJoker, true);
|
||||
mockView.handPanel.stoneClickEvent.emit(black13, true);
|
||||
|
||||
mockView.handPanel.clickEvent.emit(new Position(2, 0.25f));
|
||||
|
||||
assertCollection(Arrays.asList(secondStone));
|
||||
assertCollection(Arrays.asList(blackJoker));
|
||||
|
||||
Set<Stone> expected = new HashSet<Stone>(Arrays.asList(firstStone,
|
||||
thirdStone));
|
||||
Set<Stone> expected = new HashSet<Stone>(Arrays.asList(redJoker,
|
||||
black13));
|
||||
assertEquals(expected, mockHand.pickups);
|
||||
|
||||
Set<Stone> handStones = new HashSet<Stone>();
|
||||
|
|
Reference in a new issue