summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/moves/Move.java3
-rw-r--r--game-engine/src/test/java/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.java68
-rw-r--r--game-engine/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java38
3 files changed, 95 insertions, 14 deletions
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/moves/Move.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/moves/Move.java
index 40c61eea..230b9ef1 100644
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/moves/Move.java
+++ b/game-engine/src/main/java/org/luxons/sevenwonders/game/moves/Move.java
@@ -1,6 +1,5 @@
package org.luxons.sevenwonders.game.moves;
-import java.util.ArrayList;
import java.util.List;
import org.luxons.sevenwonders.game.Settings;
@@ -17,7 +16,7 @@ public abstract class Move {
private MoveType type;
- private List<BoughtResources> boughtResources = new ArrayList<>();
+ private List<BoughtResources> boughtResources;
Move(int playerIndex, Card card, PlayerMove move) {
this.playerIndex = playerIndex;
diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.java
new file mode 100644
index 00000000..e9a75abd
--- /dev/null
+++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.java
@@ -0,0 +1,68 @@
+package org.luxons.sevenwonders.game.moves;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Test;
+import org.luxons.sevenwonders.game.Settings;
+import org.luxons.sevenwonders.game.api.PlayerMove;
+import org.luxons.sevenwonders.game.api.Table;
+import org.luxons.sevenwonders.game.cards.Card;
+import org.luxons.sevenwonders.game.resources.BoughtResources;
+import org.luxons.sevenwonders.game.test.TestUtils;
+
+import static org.junit.Assert.assertEquals;
+
+public class BuildWonderMoveTest {
+
+ @Test
+ public void validate_ok() {
+ Table table = TestUtils.createTable(3);
+ List<Card> hand = TestUtils.createSampleCards(0, 7);
+ Card cardToUse = hand.get(0);
+ Move move = createBuildWonderMove(cardToUse, Collections.emptyList());
+
+ move.validate(table, hand);
+ }
+
+ @Test(expected = InvalidMoveException.class)
+ public void validate_failsWhenCardNotInHand() {
+ Table table = TestUtils.createTable(3);
+ List<Card> hand = TestUtils.createSampleCards(0, 7);
+ Card cardToUse = TestUtils.createCard("Card that is not in the hand");
+ Move move = createBuildWonderMove(cardToUse, Collections.emptyList());
+
+ move.validate(table, hand);
+ }
+
+ @Test
+ public void place_ok() {
+ Settings settings = TestUtils.createSettings(3);
+ Table table = TestUtils.createTable(settings);
+ List<Card> hand = TestUtils.createSampleCards(0, 7);
+ Card cardToUse = hand.get(0);
+ Move move = createBuildWonderMove(cardToUse, Collections.emptyList());
+
+ int initialStage = table.getBoard(0).getWonder().getNbBuiltStages();
+
+ move.place(table, Collections.emptyList(), settings);
+
+ int newStage = table.getBoard(0).getWonder().getNbBuiltStages();
+
+ // we need to see the level increase before activation so that other players
+ assertEquals(initialStage + 1, newStage);
+ }
+
+ private static Move createBuildWonderMove(Card card, List<BoughtResources> boughtResources) {
+ PlayerMove playerMove = createPlayerMove(card, MoveType.UPGRADE_WONDER, boughtResources);
+ return MoveType.UPGRADE_WONDER.resolve(0, card, playerMove);
+ }
+
+ private static PlayerMove createPlayerMove(Card card, MoveType type, List<BoughtResources> boughtResources) {
+ PlayerMove playerMove = new PlayerMove();
+ playerMove.setCardName(card.getName());
+ playerMove.setType(type);
+ playerMove.setBoughtResources(boughtResources);
+ return playerMove;
+ }
+}
diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java
index 4b727944..10f5def0 100644
--- a/game-engine/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java
+++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java
@@ -12,6 +12,7 @@ import org.luxons.sevenwonders.game.boards.Board;
import org.luxons.sevenwonders.game.boards.Science;
import org.luxons.sevenwonders.game.boards.ScienceType;
import org.luxons.sevenwonders.game.cards.Card;
+import org.luxons.sevenwonders.game.cards.CardBack;
import org.luxons.sevenwonders.game.cards.Color;
import org.luxons.sevenwonders.game.cards.Requirements;
import org.luxons.sevenwonders.game.effects.Effect;
@@ -34,30 +35,33 @@ public class TestUtils {
return customizableSettings;
}
- private static Settings createSettings(int nbPlayers) {
+ public static Settings createSettings(int nbPlayers) {
return new Settings(nbPlayers, createCustomizableSettings());
}
public static Table createTable(int nbPlayers) {
- return new Table(createBoards(nbPlayers));
+ return createTable(createSettings(nbPlayers));
}
- private static List<Board> createBoards(int count) {
- Settings settings = createSettings(count);
+ public static Table createTable(Settings settings) {
+ return new Table(createBoards(settings.getNbPlayers(), settings));
+ }
+
+ private static List<Board> createBoards(int count, Settings settings) {
List<Board> boards = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
- boards.add(createBoard(settings, ResourceType.WOOD));
+ boards.add(createBoard(ResourceType.WOOD, settings));
}
return boards;
}
- private static Board createBoard(Settings settings, ResourceType initialResource) {
+ private static Board createBoard(ResourceType initialResource, Settings settings) {
Wonder wonder = createWonder(initialResource);
return new Board(wonder, 0, settings);
}
public static Board createBoard(ResourceType initialResource) {
- return createBoard(createSettings(5), initialResource);
+ return createBoard(initialResource, createSettings(5));
}
private static Board createBoard(ResourceType initialResource, ResourceType... production) {
@@ -124,25 +128,35 @@ public class TestUtils {
}
public static Card createCard(String name) {
- return new Card(name, Color.BLUE, new Requirements(), null, null, null, null);
+ return createCard(name, Color.BLUE, null);
}
public static Card createCard(Color color) {
- return new Card("Test Card", color, new Requirements(), null, null, null, null);
+ return createCard("Test Card", color, null);
}
public static Card createCard(Color color, Effect effect) {
List<Effect> effects = Collections.singletonList(effect);
- return new Card("Test Card", color, new Requirements(), effects, null, null, null);
+ return createCard("Test Card", color, effects);
}
private static Card createCard(int num, Color color) {
- return new Card("Test Card " + num, color, new Requirements(), null, null, null, null);
+ return createCard("Test Card " + num, color, null);
}
public static Card createGuildCard(int num, Effect effect) {
List<Effect> effects = Collections.singletonList(effect);
- return new Card("Test Guild " + num, Color.PURPLE, new Requirements(), effects, null, null, null);
+ return createCard("Test Guild " + num, Color.PURPLE, effects);
+ }
+
+ private static Card createCard(String name, Color color, List<Effect> effects) {
+ Card card = new Card(name, color, new Requirements(), effects, null, null, "path/to/card/image");
+ card.setBack(createCardBack());
+ return card;
+ }
+
+ private static CardBack createCardBack() {
+ return new CardBack("image-III");
}
public static void addCards(Board board, int nbCardsOfColor, int nbOtherCards, Color color) {
bgstack15