summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2016-12-10 12:18:18 +0100
committerJoffrey BION <joffrey.bion@gmail.com>2016-12-10 12:25:00 +0100
commitc6057aeb737ca02c9798d4354e6830217b30ffcc (patch)
treeafb47dfd6ab5f0710443dc57382e3e677d1a5e10
parentRework cards.json for easier deserialization (diff)
downloadseven-wonders-c6057aeb737ca02c9798d4354e6830217b30ffcc.tar.gz
seven-wonders-c6057aeb737ca02c9798d4354e6830217b30ffcc.tar.bz2
seven-wonders-c6057aeb737ca02c9798d4354e6830217b30ffcc.zip
Separate resource providers from relative board positions
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/RelativePlayerPosition.java5
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/boards/TradingRules.java12
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java13
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/Discount.java11
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/Provider.java5
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/RelativeBoardPosition.java5
-rw-r--r--src/main/resources/org/luxons/sevenwonders/game/data/cards.json36
7 files changed, 45 insertions, 42 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
+}
diff --git a/src/main/resources/org/luxons/sevenwonders/game/data/cards.json b/src/main/resources/org/luxons/sevenwonders/game/data/cards.json
index 18dd8d23..5649f326 100644
--- a/src/main/resources/org/luxons/sevenwonders/game/data/cards.json
+++ b/src/main/resources/org/luxons/sevenwonders/game/data/cards.json
@@ -763,8 +763,8 @@
"perBoardElement": {
"boards": [
"SELF",
- "LEFT_PLAYER",
- "RIGHT_PLAYER"
+ "LEFT",
+ "RIGHT"
],
"type": "CARD",
"color": "GREY",
@@ -839,8 +839,8 @@
"perBoardElement": {
"boards": [
"SELF",
- "LEFT_PLAYER",
- "RIGHT_PLAYER"
+ "LEFT",
+ "RIGHT"
],
"type": "CARD",
"color": "BROWN",
@@ -1572,8 +1572,8 @@
"effect": {
"perBoardElement": {
"boards": [
- "LEFT_PLAYER",
- "RIGHT_PLAYER"
+ "LEFT",
+ "RIGHT"
],
"type": "CARD",
"color": "GREY",
@@ -1595,8 +1595,8 @@
"effect": {
"perBoardElement": {
"boards": [
- "LEFT_PLAYER",
- "RIGHT_PLAYER"
+ "LEFT",
+ "RIGHT"
],
"type": "CARD",
"color": "BLUE",
@@ -1618,8 +1618,8 @@
"effect": {
"perBoardElement": {
"boards": [
- "LEFT_PLAYER",
- "RIGHT_PLAYER"
+ "LEFT",
+ "RIGHT"
],
"type": "CARD",
"color": "GREEN",
@@ -1682,8 +1682,8 @@
"effect": {
"perBoardElement": {
"boards": [
- "LEFT_PLAYER",
- "RIGHT_PLAYER"
+ "LEFT",
+ "RIGHT"
],
"type": "CARD",
"colors": [
@@ -1707,8 +1707,8 @@
"effect": {
"perBoardElement": {
"boards": [
- "LEFT_PLAYER",
- "RIGHT_PLAYER"
+ "LEFT",
+ "RIGHT"
],
"type": "DEFEAT_TOKEN",
"points": 1
@@ -1729,8 +1729,8 @@
"effect": {
"perBoardElement": {
"boards": [
- "LEFT_PLAYER",
- "RIGHT_PLAYER"
+ "LEFT",
+ "RIGHT"
],
"type": "CARD",
"color": "YELLOW",
@@ -1752,8 +1752,8 @@
"effect": {
"perBoardElement": {
"boards": [
- "LEFT_PLAYER",
- "RIGHT_PLAYER"
+ "LEFT",
+ "RIGHT"
],
"type": "CARD",
"color": "BROWN",
bgstack15