summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2016-12-07 04:52:44 +0100
committerJoffrey BION <joffrey.bion@gmail.com>2016-12-08 02:10:10 +0100
commit3651553d82c66fabf96fd590a248089b4a51e7bd (patch)
tree1cd9415de9cb32164eea888092f25e568152f674 /src
parentFirst draft of resource production elements (diff)
downloadseven-wonders-3651553d82c66fabf96fd590a248089b4a51e7bd.tar.gz
seven-wonders-3651553d82c66fabf96fd590a248089b4a51e7bd.tar.bz2
seven-wonders-3651553d82c66fabf96fd590a248089b4a51e7bd.zip
First draft of the game engine: boards, card effects, costs
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/Settings.java24
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/boards/Board.java79
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/boards/Neighbour.java5
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/boards/Science.java24
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/boards/ScienceType.java5
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/boards/TradingRules.java25
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/cards/Card.java44
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/cards/Color.java5
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/cards/Requirements.java35
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/Discount.java44
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/Effect.java10
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/EndGameEffect.java9
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java21
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/InstantEffect.java10
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java21
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java21
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/ScienceIncrease.java18
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/resources/Production.java2
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/wonders/Wonder.java26
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/wonders/WonderLevel.java27
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java53
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/effects/EffectTest.java81
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/resources/ProductionTest.java2
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/resources/ResourcesTest.java38
24 files changed, 608 insertions, 21 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/game/Settings.java b/src/main/java/org/luxons/sevenwonders/game/Settings.java
new file mode 100644
index 00000000..16bce141
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/Settings.java
@@ -0,0 +1,24 @@
+package org.luxons.sevenwonders.game;
+
+public class Settings {
+
+ private int initialGold = 3;
+
+ private int defaultTradingCost = 2;
+
+ public int getInitialGold() {
+ return initialGold;
+ }
+
+ public void setInitialGold(int initialGold) {
+ this.initialGold = initialGold;
+ }
+
+ public int getDefaultTradingCost() {
+ return defaultTradingCost;
+ }
+
+ public void setDefaultTradingCost(int defaultTradingCost) {
+ this.defaultTradingCost = defaultTradingCost;
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/boards/Board.java b/src/main/java/org/luxons/sevenwonders/game/boards/Board.java
new file mode 100644
index 00000000..1744f60b
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/boards/Board.java
@@ -0,0 +1,79 @@
+package org.luxons.sevenwonders.game.boards;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.luxons.sevenwonders.game.Settings;
+import org.luxons.sevenwonders.game.cards.Card;
+import org.luxons.sevenwonders.game.resources.Production;
+import org.luxons.sevenwonders.game.wonders.Wonder;
+
+public class Board {
+
+ private final Wonder wonder;
+
+ private final List<Card> playedCards = new ArrayList<>();
+
+ private final Production production = new Production();
+
+ private final Science science = new Science();
+
+ private final TradingRules tradingRules;
+
+ private int gold;
+
+ private int wonderLevel;
+
+ public Board(Wonder wonder, Settings settings) {
+ this.wonder = wonder;
+ this.wonderLevel = 0;
+ this.gold = settings.getInitialGold();
+ this.tradingRules = new TradingRules(settings.getDefaultTradingCost());
+ production.addFixedResource(wonder.getInitialResource(), 1);
+ }
+
+ public Wonder getWonder() {
+ return wonder;
+ }
+
+ public List<Card> getPlayedCards() {
+ return playedCards;
+ }
+
+ public void addCard(Card card) {
+ playedCards.add(card);
+ }
+
+ public Production getProduction() {
+ return production;
+ }
+
+ public TradingRules getTradingRules() {
+ return tradingRules;
+ }
+
+ public Science getScience() {
+ return science;
+ }
+
+ public int getGold() {
+ return gold;
+ }
+
+ public void setGold(int amount) {
+ this.gold = amount;
+ }
+
+ public int getWonderLevel() {
+ return wonderLevel;
+ }
+
+ public void upgradeWonderLevel() {
+ int maxLevel = wonder.getLevels().size();
+ if (maxLevel == wonderLevel) {
+ throw new IllegalStateException("This wonder has already reached its maximum level");
+ }
+ this.wonderLevel++;
+ wonder.getLevels().get(wonderLevel).getEffect().apply(this, null, null);
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/boards/Neighbour.java b/src/main/java/org/luxons/sevenwonders/game/boards/Neighbour.java
new file mode 100644
index 00000000..63611173
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/boards/Neighbour.java
@@ -0,0 +1,5 @@
+package org.luxons.sevenwonders.game.boards;
+
+public enum Neighbour {
+ LEFT, RIGHT;
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/boards/Science.java b/src/main/java/org/luxons/sevenwonders/game/boards/Science.java
new file mode 100644
index 00000000..2eb0117a
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/boards/Science.java
@@ -0,0 +1,24 @@
+package org.luxons.sevenwonders.game.boards;
+
+import java.util.EnumMap;
+import java.util.Map;
+
+public class Science {
+
+ private Map<ScienceType, Integer> quantities = new EnumMap<>(ScienceType.class);
+
+ private int jokers;
+
+ public void add(ScienceType type, int quantity) {
+ quantities.merge(type, quantity, (x, y) -> x + y);
+ }
+
+ public void addJoker(int quantity) {
+ jokers += quantity;
+ }
+
+ public void addAll(Science science) {
+ science.quantities.forEach(this::add);
+ jokers += science.jokers;
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/boards/ScienceType.java b/src/main/java/org/luxons/sevenwonders/game/boards/ScienceType.java
new file mode 100644
index 00000000..06408b9e
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/boards/ScienceType.java
@@ -0,0 +1,5 @@
+package org.luxons.sevenwonders.game.boards;
+
+public enum ScienceType {
+ COMPASS, WHEEL, TABLET
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/boards/TradingRules.java b/src/main/java/org/luxons/sevenwonders/game/boards/TradingRules.java
new file mode 100644
index 00000000..96131775
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/boards/TradingRules.java
@@ -0,0 +1,25 @@
+package org.luxons.sevenwonders.game.boards;
+
+import java.util.EnumMap;
+import java.util.Map;
+
+import org.luxons.sevenwonders.game.resources.ResourceType;
+
+public class TradingRules {
+
+ private final Map<ResourceType, Map<Neighbour, Integer>> costs = new EnumMap<>(ResourceType.class);
+
+ private final int defaultCost;
+
+ public TradingRules(int defaultCost) {
+ this.defaultCost = defaultCost;
+ }
+
+ public int getCost(ResourceType type, Neighbour neighbour) {
+ return costs.computeIfAbsent(type, t -> new EnumMap<>(Neighbour.class)).getOrDefault(neighbour, defaultCost);
+ }
+
+ public void setCost(ResourceType type, Neighbour neighbour, int cost) {
+ costs.computeIfAbsent(type, t -> new EnumMap<>(Neighbour.class)).put(neighbour, cost);
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/cards/Card.java b/src/main/java/org/luxons/sevenwonders/game/cards/Card.java
new file mode 100644
index 00000000..27763b2d
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/cards/Card.java
@@ -0,0 +1,44 @@
+package org.luxons.sevenwonders.game.cards;
+
+import org.luxons.sevenwonders.game.boards.Board;
+import org.luxons.sevenwonders.game.effects.Effect;
+
+public class Card {
+
+ private final String name;
+
+ private final Color color;
+
+ private final Requirements requirements;
+
+ private final Effect effect;
+
+ public Card(String name, Color color, Requirements requirements, Effect effect) {
+ this.name = name;
+ this.color = color;
+ this.requirements = requirements;
+ this.effect = effect;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Color getColor() {
+ return color;
+ }
+
+ public Requirements getRequirements() {
+ return requirements;
+ }
+
+ public Effect getEffect() {
+ return effect;
+ }
+
+ public void play(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) {
+ board.addCard(this);
+ requirements.pay(board);
+ effect.apply(board, leftNeighbourBoard, rightNeighbourBoard);
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/cards/Color.java b/src/main/java/org/luxons/sevenwonders/game/cards/Color.java
new file mode 100644
index 00000000..87d5b5b1
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/cards/Color.java
@@ -0,0 +1,5 @@
+package org.luxons.sevenwonders.game.cards;
+
+public enum Color {
+ BROWN, GREY, YELLOW, BLUE, GREEN, RED, PURPLE;
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/cards/Requirements.java b/src/main/java/org/luxons/sevenwonders/game/cards/Requirements.java
new file mode 100644
index 00000000..e6335a58
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/cards/Requirements.java
@@ -0,0 +1,35 @@
+package org.luxons.sevenwonders.game.cards;
+
+import org.luxons.sevenwonders.game.boards.Board;
+import org.luxons.sevenwonders.game.resources.Resources;
+
+public class Requirements {
+
+ private int goldCost;
+
+ private Resources resources = new Resources();
+
+ public int getGoldCost() {
+ return goldCost;
+ }
+
+ public void setGoldCost(int goldCost) {
+ this.goldCost = goldCost;
+ }
+
+ public Resources getResources() {
+ return resources;
+ }
+
+ public void setResources(Resources resources) {
+ this.resources = resources;
+ }
+
+ public boolean isAffordedBy(Board board) {
+ return board.getGold() >= goldCost && board.getProduction().contains(resources);
+ }
+
+ public void pay(Board board) {
+ board.setGold(board.getGold() - goldCost);
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java b/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java
new file mode 100644
index 00000000..8fce19d4
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java
@@ -0,0 +1,44 @@
+package org.luxons.sevenwonders.game.effects;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.luxons.sevenwonders.game.boards.Neighbour;
+import org.luxons.sevenwonders.game.boards.Board;
+import org.luxons.sevenwonders.game.boards.TradingRules;
+import org.luxons.sevenwonders.game.resources.ResourceType;
+
+public class Discount extends InstantEffect {
+
+ private final List<ResourceType> resourceTypes = new ArrayList<>();
+
+ private final List<Neighbour> neighbours = new ArrayList<>();
+
+ private int discountedPrice;
+
+ public List<ResourceType> getResourceTypes() {
+ return resourceTypes;
+ }
+
+ public List<Neighbour> getNeighbours() {
+ return neighbours;
+ }
+
+ public int getDiscountedPrice() {
+ return discountedPrice;
+ }
+
+ public void setDiscountedPrice(int discountedPrice) {
+ this.discountedPrice = discountedPrice;
+ }
+
+ @Override
+ public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) {
+ TradingRules rules = board.getTradingRules();
+ for (ResourceType type : resourceTypes) {
+ for (Neighbour neighbour : neighbours) {
+ rules.setCost(type, neighbour, discountedPrice);
+ }
+ }
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/Effect.java b/src/main/java/org/luxons/sevenwonders/game/effects/Effect.java
new file mode 100644
index 00000000..86a6ae8c
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/Effect.java
@@ -0,0 +1,10 @@
+package org.luxons.sevenwonders.game.effects;
+
+import org.luxons.sevenwonders.game.boards.Board;
+
+public abstract class Effect {
+
+ public abstract void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard);
+
+ public abstract int computePoints(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard);
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/EndGameEffect.java b/src/main/java/org/luxons/sevenwonders/game/effects/EndGameEffect.java
new file mode 100644
index 00000000..e7a08e5c
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/EndGameEffect.java
@@ -0,0 +1,9 @@
+package org.luxons.sevenwonders.game.effects;
+
+import org.luxons.sevenwonders.game.boards.Board;
+
+public abstract class EndGameEffect extends Effect {
+
+ public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) {
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java b/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java
new file mode 100644
index 00000000..8e11073e
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java
@@ -0,0 +1,21 @@
+package org.luxons.sevenwonders.game.effects;
+
+import org.luxons.sevenwonders.game.boards.Board;
+
+public class GoldIncrease extends InstantEffect {
+
+ private int amount;
+
+ public int getAmount() {
+ return amount;
+ }
+
+ public void setAmount(int amount) {
+ this.amount = amount;
+ }
+
+ @Override
+ public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) {
+ board.setGold(board.getGold() + amount);
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/InstantEffect.java b/src/main/java/org/luxons/sevenwonders/game/effects/InstantEffect.java
new file mode 100644
index 00000000..9f2e09ff
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/InstantEffect.java
@@ -0,0 +1,10 @@
+package org.luxons.sevenwonders.game.effects;
+
+import org.luxons.sevenwonders.game.boards.Board;
+
+public abstract class InstantEffect extends Effect {
+
+ public int computePoints(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) {
+ return 0;
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java b/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java
new file mode 100644
index 00000000..3b3a24a2
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java
@@ -0,0 +1,21 @@
+package org.luxons.sevenwonders.game.effects;
+
+import org.luxons.sevenwonders.game.boards.Board;
+import org.luxons.sevenwonders.game.resources.Production;
+
+public class ProductionIncrease extends InstantEffect {
+
+ private Production production = new Production();
+
+ public Production getProduction() {
+ return production;
+ }
+
+ public void setProduction(Production production) {
+ this.production = production;
+ }
+
+ public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) {
+ board.getProduction().addAll(production);
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java b/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java
new file mode 100644
index 00000000..4238e891
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java
@@ -0,0 +1,21 @@
+package org.luxons.sevenwonders.game.effects;
+
+import org.luxons.sevenwonders.game.boards.Board;
+
+public class RawPointsIncrease extends EndGameEffect {
+
+ private int points;
+
+ public int getPoints() {
+ return points;
+ }
+
+ public void setPoints(int points) {
+ this.points = points;
+ }
+
+ @Override
+ public int computePoints(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) {
+ return points;
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/ScienceIncrease.java b/src/main/java/org/luxons/sevenwonders/game/effects/ScienceIncrease.java
new file mode 100644
index 00000000..4e3944cf
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/ScienceIncrease.java
@@ -0,0 +1,18 @@
+package org.luxons.sevenwonders.game.effects;
+
+import org.luxons.sevenwonders.game.boards.Board;
+import org.luxons.sevenwonders.game.boards.Science;
+
+public class ScienceIncrease extends InstantEffect {
+
+ private Science science;
+
+ public void setScience(Science science) {
+ this.science = science;
+ }
+
+ @Override
+ public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) {
+ board.getScience().addAll(science);
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/resources/Production.java b/src/main/java/org/luxons/sevenwonders/game/resources/Production.java
index 5463bea1..f4d46b59 100644
--- a/src/main/java/org/luxons/sevenwonders/game/resources/Production.java
+++ b/src/main/java/org/luxons/sevenwonders/game/resources/Production.java
@@ -23,7 +23,7 @@ public class Production {
alternativeResources.add(optionSet);
}
- void addAll(Resources resources) {
+ public void addAll(Resources resources) {
fixedResources.addAll(resources);
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/wonders/Wonder.java b/src/main/java/org/luxons/sevenwonders/game/wonders/Wonder.java
new file mode 100644
index 00000000..3a3d0e97
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/wonders/Wonder.java
@@ -0,0 +1,26 @@
+package org.luxons.sevenwonders.game.wonders;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.luxons.sevenwonders.game.resources.ResourceType;
+
+public class Wonder {
+
+ private final ResourceType initialResource;
+
+ private final List<WonderLevel> levels;
+
+ public Wonder(ResourceType initialResource, WonderLevel... levels) {
+ this.initialResource = initialResource;
+ this.levels = Arrays.asList(levels);
+ }
+
+ public ResourceType getInitialResource() {
+ return initialResource;
+ }
+
+ public List<WonderLevel> getLevels() {
+ return levels;
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/wonders/WonderLevel.java b/src/main/java/org/luxons/sevenwonders/game/wonders/WonderLevel.java
new file mode 100644
index 00000000..23571149
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/wonders/WonderLevel.java
@@ -0,0 +1,27 @@
+package org.luxons.sevenwonders.game.wonders;
+
+import org.luxons.sevenwonders.game.cards.Requirements;
+import org.luxons.sevenwonders.game.effects.Effect;
+
+public class WonderLevel {
+
+ private Requirements requirements;
+
+ private Effect effect;
+
+ public Requirements getRequirements() {
+ return requirements;
+ }
+
+ public void setRequirements(Requirements requirements) {
+ this.requirements = requirements;
+ }
+
+ public Effect getEffect() {
+ return effect;
+ }
+
+ public void setEffect(Effect effect) {
+ this.effect = effect;
+ }
+}
diff --git a/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java b/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java
new file mode 100644
index 00000000..db11c466
--- /dev/null
+++ b/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java
@@ -0,0 +1,53 @@
+package org.luxons.sevenwonders.game.cards;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.luxons.sevenwonders.game.Settings;
+import org.luxons.sevenwonders.game.boards.Board;
+import org.luxons.sevenwonders.game.effects.ProductionIncrease;
+import org.luxons.sevenwonders.game.resources.ResourceType;
+import org.luxons.sevenwonders.game.wonders.Wonder;
+
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertEquals;
+
+public class CardTest {
+
+ private Board board;
+
+ private Board leftBoard;
+
+ private Board rightBoard;
+
+ private Card treeFarmCard;
+
+ @Before
+ public void initBoard() {
+ Settings settings = new Settings();
+ board = new Board(new Wonder(ResourceType.WOOD), settings);
+ leftBoard = new Board(new Wonder(ResourceType.STONE), settings);
+ rightBoard = new Board(new Wonder(ResourceType.PAPYRUS), settings);
+
+ Requirements treeFarmRequirements = new Requirements();
+ treeFarmRequirements.setGoldCost(1);
+
+ ProductionIncrease treeFarmEffect = new ProductionIncrease();
+ treeFarmEffect.getProduction().addChoice(ResourceType.WOOD, ResourceType.CLAY);
+
+ treeFarmCard = new Card("Tree Farm", Color.BROWN, treeFarmRequirements, treeFarmEffect);
+ }
+
+ @Test
+ public void testInitialBoard() {
+ assertEquals(3, board.getGold());
+ }
+
+ @Test
+ public void playCardCostingMoney() {
+ board.setGold(3);
+ treeFarmCard.play(board, leftBoard, rightBoard);
+ assertEquals(2, board.getGold());
+ assertTrue(board.getPlayedCards().contains(treeFarmCard));
+ }
+
+}
diff --git a/src/test/java/org/luxons/sevenwonders/game/effects/EffectTest.java b/src/test/java/org/luxons/sevenwonders/game/effects/EffectTest.java
new file mode 100644
index 00000000..51a7a192
--- /dev/null
+++ b/src/test/java/org/luxons/sevenwonders/game/effects/EffectTest.java
@@ -0,0 +1,81 @@
+package org.luxons.sevenwonders.game.effects;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.luxons.sevenwonders.game.Settings;
+import org.luxons.sevenwonders.game.boards.Board;
+import org.luxons.sevenwonders.game.resources.ResourceType;
+import org.luxons.sevenwonders.game.resources.Resources;
+import org.luxons.sevenwonders.game.wonders.Wonder;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class EffectTest {
+
+ private static final int INITIAL_GOLD = 3;
+
+ private Board board;
+
+ private Board leftBoard;
+
+ private Board rightBoard;
+
+ private Resources resources1Stone1Wood;
+
+ private Resources resources2Stones;
+
+ private Resources resources2Stones3Clay;
+
+ @Before
+ public void init() {
+ Settings settings = new Settings();
+ settings.setInitialGold(INITIAL_GOLD);
+
+ board = new Board(new Wonder(ResourceType.WOOD), settings);
+ leftBoard = new Board(new Wonder(ResourceType.STONE), settings);
+ rightBoard = new Board(new Wonder(ResourceType.PAPYRUS), settings);
+
+ resources1Stone1Wood = new Resources();
+ resources1Stone1Wood.add(ResourceType.STONE, 1);
+ resources1Stone1Wood.add(ResourceType.WOOD, 1);
+
+ resources2Stones = new Resources();
+ resources2Stones.add(ResourceType.STONE, 2);
+
+ resources2Stones3Clay = new Resources();
+ resources2Stones3Clay.add(ResourceType.STONE, 2);
+ resources2Stones3Clay.add(ResourceType.CLAY, 3);
+ }
+
+ @Test
+ public void testInitialBoard() {
+ assertEquals(3, board.getGold());
+ }
+
+ @Test
+ public void testGoldIncrease() {
+ GoldIncrease effect = new GoldIncrease();
+ effect.setAmount(6);
+ effect.apply(board, leftBoard, rightBoard);
+ assertEquals(INITIAL_GOLD + 6, board.getGold());
+ assertEquals(INITIAL_GOLD, leftBoard.getGold());
+ assertEquals(INITIAL_GOLD, rightBoard.getGold());
+ }
+
+ @Test
+ public void testProductionIncrease_standard() {
+ ProductionIncrease effect = new ProductionIncrease();
+ effect.getProduction().addAll(resources2Stones3Clay);
+ effect.apply(board, leftBoard, rightBoard);
+ assertTrue(board.getProduction().contains(resources2Stones3Clay));
+ }
+
+ @Test
+ public void testProductionIncrease_choice() {
+ ProductionIncrease effect = new ProductionIncrease();
+ effect.getProduction().addChoice(ResourceType.ORE, ResourceType.STONE);
+ effect.apply(board, leftBoard, rightBoard);
+ assertTrue(board.getProduction().contains(resources1Stone1Wood));
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/luxons/sevenwonders/game/resources/ProductionTest.java b/src/test/java/org/luxons/sevenwonders/game/resources/ProductionTest.java
index 58b82dc1..f5c7c719 100644
--- a/src/test/java/org/luxons/sevenwonders/game/resources/ProductionTest.java
+++ b/src/test/java/org/luxons/sevenwonders/game/resources/ProductionTest.java
@@ -150,7 +150,7 @@ public class ProductionTest {
@Test
public void contains_multipleChoices_moreThanEnough() throws Exception {
Production production = new Production();
- production.addChoice(ResourceType.LINEN, ResourceType.GLASS, ResourceType.PAPYRUS);
+ production.addChoice(ResourceType.LOOM, ResourceType.GLASS, ResourceType.PAPYRUS);
production.addChoice(ResourceType.STONE, ResourceType.ORE);
production.addChoice(ResourceType.STONE, ResourceType.WOOD);
assertTrue(production.contains(resources1Stone1Wood));
diff --git a/src/test/java/org/luxons/sevenwonders/game/resources/ResourcesTest.java b/src/test/java/org/luxons/sevenwonders/game/resources/ResourcesTest.java
index efcea74e..fc4bb909 100644
--- a/src/test/java/org/luxons/sevenwonders/game/resources/ResourcesTest.java
+++ b/src/test/java/org/luxons/sevenwonders/game/resources/ResourcesTest.java
@@ -61,7 +61,7 @@ public class ResourcesTest {
assertEquals(3, resources.getQuantity(ResourceType.CLAY));
assertEquals(0, resources.getQuantity(ResourceType.ORE));
assertEquals(0, resources.getQuantity(ResourceType.GLASS));
- assertEquals(0, resources.getQuantity(ResourceType.LINEN));
+ assertEquals(0, resources.getQuantity(ResourceType.LOOM));
}
@Test
@@ -79,7 +79,7 @@ public class ResourcesTest {
assertEquals(3, resources.getQuantity(ResourceType.CLAY));
assertEquals(0, resources.getQuantity(ResourceType.ORE));
assertEquals(0, resources.getQuantity(ResourceType.GLASS));
- assertEquals(0, resources.getQuantity(ResourceType.LINEN));
+ assertEquals(0, resources.getQuantity(ResourceType.LOOM));
}
@Test
@@ -97,7 +97,7 @@ public class ResourcesTest {
assertEquals(9, resources.getQuantity(ResourceType.CLAY));
assertEquals(0, resources.getQuantity(ResourceType.ORE));
assertEquals(0, resources.getQuantity(ResourceType.GLASS));
- assertEquals(0, resources.getQuantity(ResourceType.LINEN));
+ assertEquals(0, resources.getQuantity(ResourceType.LOOM));
}
@Test
@@ -115,7 +115,7 @@ public class ResourcesTest {
assertEquals(9, resources.getQuantity(ResourceType.CLAY));
assertEquals(4, resources.getQuantity(ResourceType.ORE));
assertEquals(0, resources.getQuantity(ResourceType.GLASS));
- assertEquals(0, resources.getQuantity(ResourceType.LINEN));
+ assertEquals(0, resources.getQuantity(ResourceType.LOOM));
}
@Test
@@ -218,7 +218,7 @@ public class ResourcesTest {
assertEquals(3, diff.getQuantity(ResourceType.CLAY));
assertEquals(0, diff.getQuantity(ResourceType.ORE));
assertEquals(0, diff.getQuantity(ResourceType.GLASS));
- assertEquals(0, diff.getQuantity(ResourceType.LINEN));
+ assertEquals(0, diff.getQuantity(ResourceType.LOOM));
}
@Test
@@ -232,7 +232,7 @@ public class ResourcesTest {
assertEquals(0, diff.getQuantity(ResourceType.CLAY));
assertEquals(0, diff.getQuantity(ResourceType.ORE));
assertEquals(0, diff.getQuantity(ResourceType.GLASS));
- assertEquals(0, diff.getQuantity(ResourceType.LINEN));
+ assertEquals(0, diff.getQuantity(ResourceType.LOOM));
}
@Test
@@ -250,7 +250,7 @@ public class ResourcesTest {
assertEquals(0, diff.getQuantity(ResourceType.CLAY));
assertEquals(0, diff.getQuantity(ResourceType.ORE));
assertEquals(0, diff.getQuantity(ResourceType.GLASS));
- assertEquals(0, diff.getQuantity(ResourceType.LINEN));
+ assertEquals(0, diff.getQuantity(ResourceType.LOOM));
}
@Test
@@ -268,7 +268,7 @@ public class ResourcesTest {
assertEquals(1, diff.getQuantity(ResourceType.CLAY));
assertEquals(0, diff.getQuantity(ResourceType.ORE));
assertEquals(0, diff.getQuantity(ResourceType.GLASS));
- assertEquals(0, diff.getQuantity(ResourceType.LINEN));
+ assertEquals(0, diff.getQuantity(ResourceType.LOOM));
}
@Test
@@ -285,7 +285,7 @@ public class ResourcesTest {
assertEquals(1, diff.getQuantity(ResourceType.CLAY));
assertEquals(0, diff.getQuantity(ResourceType.ORE));
assertEquals(0, diff.getQuantity(ResourceType.GLASS));
- assertEquals(0, diff.getQuantity(ResourceType.LINEN));
+ assertEquals(0, diff.getQuantity(ResourceType.LOOM));
}
@Test
@@ -302,7 +302,7 @@ public class ResourcesTest {
assertEquals(0, diff.getQuantity(ResourceType.CLAY));
assertEquals(0, diff.getQuantity(ResourceType.ORE));
assertEquals(0, diff.getQuantity(ResourceType.GLASS));
- assertEquals(0, diff.getQuantity(ResourceType.LINEN));
+ assertEquals(0, diff.getQuantity(ResourceType.LOOM));
}
@Test
@@ -322,22 +322,22 @@ public class ResourcesTest {
Resources resources = new Resources();
Resources resources2 = new Resources();
- resources2.add(ResourceType.LINEN, 5);
+ resources2.add(ResourceType.LOOM, 5);
Resources diff = resources.minus(resources2);
- assertEquals(0, diff.getQuantity(ResourceType.LINEN));
+ assertEquals(0, diff.getQuantity(ResourceType.LOOM));
}
@Test
public void minus_someOfATypeWithZero() {
Resources resources = new Resources();
- resources.add(ResourceType.LINEN, 0);
+ resources.add(ResourceType.LOOM, 0);
Resources resources2 = new Resources();
- resources2.add(ResourceType.LINEN, 5);
+ resources2.add(ResourceType.LOOM, 5);
Resources diff = resources.minus(resources2);
- assertEquals(0, diff.getQuantity(ResourceType.LINEN));
+ assertEquals(0, diff.getQuantity(ResourceType.LOOM));
}
@Test
@@ -349,7 +349,7 @@ public class ResourcesTest {
@Test
public void isEmpty_singleZeroElement() {
Resources resources = new Resources();
- resources.add(ResourceType.LINEN, 0);
+ resources.add(ResourceType.LOOM, 0);
assertTrue(resources.isEmpty());
}
@@ -358,14 +358,14 @@ public class ResourcesTest {
Resources resources = new Resources();
resources.add(ResourceType.WOOD, 0);
resources.add(ResourceType.ORE, 0);
- resources.add(ResourceType.LINEN, 0);
+ resources.add(ResourceType.LOOM, 0);
assertTrue(resources.isEmpty());
}
@Test
public void isEmpty_singleElementMoreThanZero() {
Resources resources = new Resources();
- resources.add(ResourceType.LINEN, 3);
+ resources.add(ResourceType.LOOM, 3);
assertFalse(resources.isEmpty());
}
@@ -373,7 +373,7 @@ public class ResourcesTest {
public void isEmpty_mixedZeroAndNonZeroElements() {
Resources resources = new Resources();
resources.add(ResourceType.WOOD, 0);
- resources.add(ResourceType.LINEN, 3);
+ resources.add(ResourceType.LOOM, 3);
assertFalse(resources.isEmpty());
}
bgstack15