summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2016-12-25 14:57:41 +0100
committerjbion <joffrey.bion@amadeus.com>2016-12-25 14:58:06 +0100
commit1cb84124da0d3d238e44af77b6cba508eb734986 (patch)
tree029b301ea511673c6c269e175353b6a55d0ef24e
parentTake into account boughtResources in move validation (diff)
downloadseven-wonders-1cb84124da0d3d238e44af77b6cba508eb734986.tar.gz
seven-wonders-1cb84124da0d3d238e44af77b6cba508eb734986.tar.bz2
seven-wonders-1cb84124da0d3d238e44af77b6cba508eb734986.zip
Extract military stuff into its own object
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/Settings.java28
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/boards/Board.java23
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/boards/BoardElementType.java2
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/boards/Military.java45
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java2
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.java8
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.java4
7 files changed, 88 insertions, 24 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/game/Settings.java b/src/main/java/org/luxons/sevenwonders/game/Settings.java
index ecd22d24..7159670d 100644
--- a/src/main/java/org/luxons/sevenwonders/game/Settings.java
+++ b/src/main/java/org/luxons/sevenwonders/game/Settings.java
@@ -1,5 +1,7 @@
package org.luxons.sevenwonders.game;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Random;
import org.luxons.sevenwonders.game.data.definitions.WonderSide;
@@ -18,6 +20,16 @@ public class Settings {
private long randomSeedForTests = -1;
+ private int lostPointsPerDefeat = 1;
+
+ private Map<Integer, Integer> wonPointsPerVictoryPerAge = new HashMap<>();
+
+ public Settings() {
+ wonPointsPerVictoryPerAge.put(1, 1);
+ wonPointsPerVictoryPerAge.put(2, 3);
+ wonPointsPerVictoryPerAge.put(3, 5);
+ }
+
public int getNbPlayers() {
if (nbPlayers < 0) {
throw new IllegalStateException("The number of players has not been initialized");
@@ -61,6 +73,22 @@ public class Settings {
this.wonderSide = wonderSide;
}
+ public int getLostPointsPerDefeat() {
+ return lostPointsPerDefeat;
+ }
+
+ public void setLostPointsPerDefeat(int lostPointsPerDefeat) {
+ this.lostPointsPerDefeat = lostPointsPerDefeat;
+ }
+
+ public Map<Integer, Integer> getWonPointsPerVictoryPerAge() {
+ return wonPointsPerVictoryPerAge;
+ }
+
+ public void setWonPointsPerVictoryPerAge(Map<Integer, Integer> wonPointsPerVictoryPerAge) {
+ this.wonPointsPerVictoryPerAge = wonPointsPerVictoryPerAge;
+ }
+
public long getRandomSeedForTests() {
return randomSeedForTests;
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/boards/Board.java b/src/main/java/org/luxons/sevenwonders/game/boards/Board.java
index 7734ec83..e8afecd5 100644
--- a/src/main/java/org/luxons/sevenwonders/game/boards/Board.java
+++ b/src/main/java/org/luxons/sevenwonders/game/boards/Board.java
@@ -25,17 +25,16 @@ public class Board {
private final TradingRules tradingRules;
- private int gold;
-
- private int nbWarSymbols;
+ private final Military military;
- private int nbDefeatTokens;
+ private int gold;
public Board(Wonder wonder, Player player, Settings settings) {
this.wonder = wonder;
this.player = player;
this.gold = settings.getInitialGold();
this.tradingRules = new TradingRules(settings.getDefaultTradingCost());
+ this.military = new Military(settings);
production.addFixedResource(wonder.getInitialResource(), 1);
}
@@ -94,20 +93,8 @@ public class Board {
this.gold -= amount;
}
- public int getNbWarSymbols() {
- return nbWarSymbols;
- }
-
- public void setNbWarSymbols(int nbWarSymbols) {
- this.nbWarSymbols = nbWarSymbols;
- }
-
- public int getNbDefeatTokens() {
- return nbDefeatTokens;
- }
-
- public void setNbDefeatTokens(int nbDefeatTokens) {
- this.nbDefeatTokens= nbDefeatTokens;
+ public Military getMilitary() {
+ return military;
}
private static class InsufficientFundsException extends RuntimeException {
diff --git a/src/main/java/org/luxons/sevenwonders/game/boards/BoardElementType.java b/src/main/java/org/luxons/sevenwonders/game/boards/BoardElementType.java
index d1fba60c..e50f4ea0 100644
--- a/src/main/java/org/luxons/sevenwonders/game/boards/BoardElementType.java
+++ b/src/main/java/org/luxons/sevenwonders/game/boards/BoardElementType.java
@@ -20,7 +20,7 @@ public enum BoardElementType {
DEFEAT_TOKEN {
@Override
public int getElementCount(Board board, List<Color> colors) {
- return board.getNbDefeatTokens();
+ return board.getMilitary().getNbDefeatTokens();
}
};
diff --git a/src/main/java/org/luxons/sevenwonders/game/boards/Military.java b/src/main/java/org/luxons/sevenwonders/game/boards/Military.java
new file mode 100644
index 00000000..08559336
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/boards/Military.java
@@ -0,0 +1,45 @@
+package org.luxons.sevenwonders.game.boards;
+
+import org.luxons.sevenwonders.game.Settings;
+
+public class Military {
+
+ private final Settings settings;
+
+ private int nbShields = 0;
+
+ private int totalPoints = 0;
+
+ private int nbDefeatTokens = 0;
+
+ Military(Settings settings) {
+ this.settings = settings;
+ }
+
+ public int getNbShields() {
+ return nbShields;
+ }
+
+ public void addShields(int nbShields) {
+ this.nbShields += nbShields;
+ }
+
+ public int getTotalPoints() {
+ return totalPoints;
+ }
+
+ public int getNbDefeatTokens() {
+ return nbDefeatTokens;
+ }
+
+ public void victory(int age) {
+ int wonPoints = settings.getWonPointsPerVictoryPerAge().get(age);
+ totalPoints += wonPoints;
+ }
+
+ public void defeat() {
+ int lostPoints = settings.getLostPointsPerDefeat();
+ totalPoints -= lostPoints;
+ nbDefeatTokens++;
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java b/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java
index 8a0299ca..b08e2f59 100644
--- a/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java
@@ -18,7 +18,7 @@ public class MilitaryReinforcements extends InstantOwnBoardEffect {
@Override
public void apply(Board board) {
- board.setNbWarSymbols(board.getNbWarSymbols() + count);
+ board.getMilitary().addShields(count);
}
@Override
diff --git a/src/test/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.java b/src/test/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.java
index c2c6f86d..5f42bc53 100644
--- a/src/test/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.java
+++ b/src/test/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.java
@@ -67,7 +67,9 @@ public class BonusPerBoardElementTest {
@Theory
public void computePoints_countsDefeatTokens(RelativeBoardPosition boardPosition, int nbDefeatTokens, int points, int gold) {
Board board = table.getBoard(0, boardPosition);
- board.setNbDefeatTokens(nbDefeatTokens);
+ for (int i = 0; i < nbDefeatTokens; i++) {
+ board.getMilitary().defeat();
+ }
BonusPerBoardElement bonus = createBonus(BoardElementType.DEFEAT_TOKEN, gold, points);
bonus.setBoards(Collections.singletonList(boardPosition));
@@ -106,7 +108,9 @@ public class BonusPerBoardElementTest {
@Theory
public void apply_countsDefeatTokens(RelativeBoardPosition boardPosition, int nbDefeatTokens, int points, int gold) {
Board board = table.getBoard(0, boardPosition);
- board.setNbDefeatTokens(nbDefeatTokens);
+ for (int i = 0; i < nbDefeatTokens; i++) {
+ board.getMilitary().defeat();
+ }
BonusPerBoardElement bonus = createBonus(BoardElementType.DEFEAT_TOKEN, gold, points);
bonus.setBoards(Collections.singletonList(boardPosition));
diff --git a/src/test/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.java b/src/test/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.java
index fbfc2d6c..d3c2cc03 100644
--- a/src/test/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.java
+++ b/src/test/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.java
@@ -27,12 +27,12 @@ public class MilitaryReinforcementsTest {
@Theory
public void apply_increaseGoldWithRightAmount(int initialShields, int additionalShields, ResourceType type) {
Board board = TestUtils.createBoard(type);
- board.setNbWarSymbols(initialShields);
+ board.getMilitary().addShields(initialShields);
MilitaryReinforcements reinforcements = new MilitaryReinforcements(additionalShields);
reinforcements.apply(board);
- assertEquals(initialShields + additionalShields, board.getNbWarSymbols());
+ assertEquals(initialShields + additionalShields, board.getMilitary().getNbShields());
}
@Theory
bgstack15