diff options
author | Joffrey BION <joffrey.bion@gmail.com> | 2016-12-10 12:18:18 +0100 |
---|---|---|
committer | Joffrey BION <joffrey.bion@gmail.com> | 2016-12-10 12:25:00 +0100 |
commit | c6057aeb737ca02c9798d4354e6830217b30ffcc (patch) | |
tree | afb47dfd6ab5f0710443dc57382e3e677d1a5e10 /src/main/java | |
parent | Rework cards.json for easier deserialization (diff) | |
download | seven-wonders-c6057aeb737ca02c9798d4354e6830217b30ffcc.tar.gz seven-wonders-c6057aeb737ca02c9798d4354e6830217b30ffcc.tar.bz2 seven-wonders-c6057aeb737ca02c9798d4354e6830217b30ffcc.zip |
Separate resource providers from relative board positions
Diffstat (limited to 'src/main/java')
6 files changed, 27 insertions, 24 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/game/RelativePlayerPosition.java b/src/main/java/org/luxons/sevenwonders/game/RelativePlayerPosition.java deleted file mode 100644 index 8d078d50..00000000 --- a/src/main/java/org/luxons/sevenwonders/game/RelativePlayerPosition.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.luxons.sevenwonders.game; - -public enum RelativePlayerPosition { - LEFT_PLAYER, RIGHT_PLAYER, SELF; -} diff --git a/src/main/java/org/luxons/sevenwonders/game/boards/TradingRules.java b/src/main/java/org/luxons/sevenwonders/game/boards/TradingRules.java index 7784306a..ac13c354 100644 --- a/src/main/java/org/luxons/sevenwonders/game/boards/TradingRules.java +++ b/src/main/java/org/luxons/sevenwonders/game/boards/TradingRules.java @@ -3,12 +3,12 @@ package org.luxons.sevenwonders.game.boards; import java.util.EnumMap; import java.util.Map; -import org.luxons.sevenwonders.game.RelativePlayerPosition; +import org.luxons.sevenwonders.game.effects.Provider; import org.luxons.sevenwonders.game.resources.ResourceType; public class TradingRules { - private final Map<ResourceType, Map<RelativePlayerPosition, Integer>> costs = new EnumMap<>(ResourceType.class); + private final Map<ResourceType, Map<Provider, Integer>> costs = new EnumMap<>(ResourceType.class); private final int defaultCost; @@ -16,11 +16,11 @@ public class TradingRules { this.defaultCost = defaultCost; } - public int getCost(ResourceType type, RelativePlayerPosition target) { - return costs.computeIfAbsent(type, t -> new EnumMap<>(RelativePlayerPosition.class)).getOrDefault(target, defaultCost); + public int getCost(ResourceType type, Provider provider) { + return costs.computeIfAbsent(type, t -> new EnumMap<>(Provider.class)).getOrDefault(provider, defaultCost); } - public void setCost(ResourceType type, RelativePlayerPosition target, int cost) { - costs.computeIfAbsent(type, t -> new EnumMap<>(RelativePlayerPosition.class)).put(target, cost); + public void setCost(ResourceType type, Provider provider, int cost) { + costs.computeIfAbsent(type, t -> new EnumMap<>(Provider.class)).put(provider, cost); } } diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java b/src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java index 57b83054..2796b63a 100644 --- a/src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java +++ b/src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java @@ -3,12 +3,11 @@ package org.luxons.sevenwonders.game.effects; import java.util.List; import org.luxons.sevenwonders.game.boards.Board; -import org.luxons.sevenwonders.game.RelativePlayerPosition; import org.luxons.sevenwonders.game.cards.Color; public class BonusPerBoardElement implements Effect { - private List<RelativePlayerPosition> boards; + private List<RelativeBoardPosition> boards; private int gold; @@ -19,11 +18,11 @@ public class BonusPerBoardElement implements Effect { // only relevant if type=CARD private List<Color> colors; - public List<RelativePlayerPosition> getBoards() { + public List<RelativeBoardPosition> getBoards() { return boards; } - public void setBoards(List<RelativePlayerPosition> boards) { + public void setBoards(List<RelativeBoardPosition> boards) { this.boards = boards; } @@ -72,13 +71,13 @@ public class BonusPerBoardElement implements Effect { private int computeNbOfMatchingElementsIn(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { int totalCount = 0; - if (boards.contains(RelativePlayerPosition.SELF)) { + if (boards.contains(RelativeBoardPosition.SELF)) { totalCount += computeNbOfMatchingElementsIn(board); } - if (boards.contains(RelativePlayerPosition.LEFT_PLAYER)) { + if (boards.contains(RelativeBoardPosition.LEFT)) { totalCount += computeNbOfMatchingElementsIn(leftNeighbourBoard); } - if (boards.contains(RelativePlayerPosition.RIGHT_PLAYER)) { + if (boards.contains(RelativeBoardPosition.RIGHT)) { totalCount += computeNbOfMatchingElementsIn(rightNeighbourBoard); } return totalCount; diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java b/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java index 92d1d74d..9b5d071f 100644 --- a/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java +++ b/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java @@ -3,7 +3,6 @@ package org.luxons.sevenwonders.game.effects; import java.util.ArrayList; import java.util.List; -import org.luxons.sevenwonders.game.RelativePlayerPosition; import org.luxons.sevenwonders.game.boards.Board; import org.luxons.sevenwonders.game.boards.TradingRules; import org.luxons.sevenwonders.game.resources.ResourceType; @@ -12,7 +11,7 @@ public class Discount extends InstantEffect { private final List<ResourceType> resourceTypes = new ArrayList<>(); - private final List<RelativePlayerPosition> targets = new ArrayList<>(); + private final List<Provider> providers = new ArrayList<>(); private int discountedPrice = 1; @@ -20,8 +19,8 @@ public class Discount extends InstantEffect { return resourceTypes; } - public List<RelativePlayerPosition> getTargets() { - return targets; + public List<Provider> getProviders() { + return providers; } public int getDiscountedPrice() { @@ -36,8 +35,8 @@ public class Discount extends InstantEffect { public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { TradingRules rules = board.getTradingRules(); for (ResourceType type : resourceTypes) { - for (RelativePlayerPosition target : targets) { - rules.setCost(type, target, discountedPrice); + for (Provider provider : providers) { + rules.setCost(type, provider, discountedPrice); } } } diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/Provider.java b/src/main/java/org/luxons/sevenwonders/game/effects/Provider.java new file mode 100644 index 00000000..a586dcca --- /dev/null +++ b/src/main/java/org/luxons/sevenwonders/game/effects/Provider.java @@ -0,0 +1,5 @@ +package org.luxons.sevenwonders.game.effects; + +public enum Provider { + LEFT_PLAYER, RIGHT_PLAYER +} diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/RelativeBoardPosition.java b/src/main/java/org/luxons/sevenwonders/game/effects/RelativeBoardPosition.java new file mode 100644 index 00000000..9b640539 --- /dev/null +++ b/src/main/java/org/luxons/sevenwonders/game/effects/RelativeBoardPosition.java @@ -0,0 +1,5 @@ +package org.luxons.sevenwonders.game.effects; + +public enum RelativeBoardPosition { + LEFT, SELF, RIGHT +} |