diff options
author | Joffrey Bion <joffrey.bion@amadeus.com> | 2018-04-25 17:48:13 +0200 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@amadeus.com> | 2018-04-25 17:48:13 +0200 |
commit | 0b349b3272e49a5feb261be99c9f9bd3863384e6 (patch) | |
tree | 7f74111fe36cb9387ece40bc449b046aea4dc8a1 | |
parent | Add test for BuildWonderMove (diff) | |
download | seven-wonders-0b349b3272e49a5feb261be99c9f9bd3863384e6.tar.gz seven-wonders-0b349b3272e49a5feb261be99c9f9bd3863384e6.tar.bz2 seven-wonders-0b349b3272e49a5feb261be99c9f9bd3863384e6.zip |
Fix WonderStage creation to add at least an empty effect list
3 files changed, 38 insertions, 29 deletions
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderStageDefinition.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderStageDefinition.java index 887b414a..230484ee 100644 --- a/game-engine/src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderStageDefinition.java +++ b/game-engine/src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderStageDefinition.java @@ -13,9 +13,6 @@ public class WonderStageDefinition implements Definition<WonderStage> { @Override public WonderStage create(Settings settings) { - WonderStage stage = new WonderStage(); - stage.setRequirements(requirements); - stage.setEffects(effects.create(settings)); - return stage; + return new WonderStage(requirements, effects.create(settings)); } } diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/wonders/WonderStage.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/wonders/WonderStage.java index 5f6765ee..89b20383 100644 --- a/game-engine/src/main/java/org/luxons/sevenwonders/game/wonders/WonderStage.java +++ b/game-engine/src/main/java/org/luxons/sevenwonders/game/wonders/WonderStage.java @@ -11,28 +11,25 @@ import org.luxons.sevenwonders.game.resources.BoughtResources; public class WonderStage { - private Requirements requirements; + private final Requirements requirements; - private List<Effect> effects; + private final List<Effect> effects; private CardBack cardBack; - public Requirements getRequirements() { - return requirements; + public WonderStage(Requirements requirements, List<Effect> effects) { + this.requirements = requirements; + this.effects = effects; } - public void setRequirements(Requirements requirements) { - this.requirements = requirements; + public Requirements getRequirements() { + return requirements; } public List<Effect> getEffects() { return effects; } - public void setEffects(List<Effect> effects) { - this.effects = effects; - } - public CardBack getCardBack() { return cardBack; } 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 10f5def0..0dff9dbe 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 @@ -7,6 +7,7 @@ import java.util.List; import org.luxons.sevenwonders.game.Settings; import org.luxons.sevenwonders.game.api.CustomizableSettings; +import org.luxons.sevenwonders.game.api.PlayerMove; import org.luxons.sevenwonders.game.api.Table; import org.luxons.sevenwonders.game.boards.Board; import org.luxons.sevenwonders.game.boards.Science; @@ -17,6 +18,8 @@ import org.luxons.sevenwonders.game.cards.Color; import org.luxons.sevenwonders.game.cards.Requirements; import org.luxons.sevenwonders.game.effects.Effect; import org.luxons.sevenwonders.game.effects.ScienceProgress; +import org.luxons.sevenwonders.game.moves.Move; +import org.luxons.sevenwonders.game.moves.MoveType; import org.luxons.sevenwonders.game.resources.BoughtResources; import org.luxons.sevenwonders.game.resources.Production; import org.luxons.sevenwonders.game.resources.Provider; @@ -81,15 +84,16 @@ public class TestUtils { } public static Wonder createWonder(ResourceType initialResource) { - WonderStage stage1 = new WonderStage(); - stage1.setRequirements(new Requirements()); - WonderStage stage2 = new WonderStage(); - stage1.setRequirements(new Requirements()); - WonderStage stage3 = new WonderStage(); - stage1.setRequirements(new Requirements()); + WonderStage stage1 = createWonderStage(); + WonderStage stage2 = createWonderStage(); + WonderStage stage3 = createWonderStage(); return new Wonder("Test Wonder " + initialResource.getSymbol(), initialResource, stage1, stage2, stage3); } + private static WonderStage createWonderStage(Effect... effects) { + return new WonderStage(new Requirements(), Arrays.asList(effects)); + } + public static Production createFixedProduction(ResourceType... producedTypes) { Production production = new Production(); Resources fixedProducedResources = production.getFixedResources(); @@ -128,29 +132,27 @@ public class TestUtils { } public static Card createCard(String name) { - return createCard(name, Color.BLUE, null); + return createCard(name, Color.BLUE); } public static Card createCard(Color color) { - return createCard("Test Card", color, null); + return createCard("Test Card", color); } public static Card createCard(Color color, Effect effect) { - List<Effect> effects = Collections.singletonList(effect); - return createCard("Test Card", color, effects); + return createCard("Test Card", color, effect); } private static Card createCard(int num, Color color) { - return createCard("Test Card " + num, color, null); + return createCard("Test Card " + num, color); } public static Card createGuildCard(int num, Effect effect) { - List<Effect> effects = Collections.singletonList(effect); - return createCard("Test Guild " + num, Color.PURPLE, effects); + return createCard("Test Guild " + num, Color.PURPLE, effect); } - 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"); + private static Card createCard(String name, Color color, Effect... effects) { + Card card = new Card(name, color, new Requirements(), Arrays.asList(effects), null, null, "path/to/card/image"); card.setBack(createCardBack()); return card; } @@ -210,4 +212,17 @@ public class TestUtils { board.addCard(card); card.applyTo(table, playerIndex, Collections.emptyList()); } + + public static Move createMove(int playerIndex, Card card, MoveType type, BoughtResources... boughtResources) { + PlayerMove playerMove = createPlayerMove(card, type, boughtResources); + return type.resolve(playerIndex, card, playerMove); + } + + private static PlayerMove createPlayerMove(Card card, MoveType type, BoughtResources... boughtResources) { + PlayerMove playerMove = new PlayerMove(); + playerMove.setCardName(card.getName()); + playerMove.setType(type); + playerMove.setBoughtResources(Arrays.asList(boughtResources)); + return playerMove; + } } |