summaryrefslogtreecommitdiff
path: root/src/main/java/org/luxons/sevenwonders
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2017-01-12 22:59:21 +0100
committerjbion <joffrey.bion@amadeus.com>2017-01-12 22:59:21 +0100
commit1431bff18c30a4c1205fb19c83c307a3181525ee (patch)
tree55954a23d923c8b1291783b626ddcea8a2268dd1 /src/main/java/org/luxons/sevenwonders
parentAdd multiple ways to pick the side of the wonder (diff)
downloadseven-wonders-1431bff18c30a4c1205fb19c83c307a3181525ee.tar.gz
seven-wonders-1431bff18c30a4c1205fb19c83c307a3181525ee.tar.bz2
seven-wonders-1431bff18c30a4c1205fb19c83c307a3181525ee.zip
Separate CustomizableSettings and actual Settings
Diffstat (limited to 'src/main/java/org/luxons/sevenwonders')
-rw-r--r--src/main/java/org/luxons/sevenwonders/actions/UpdateSettingsAction.java8
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/Lobby.java10
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/Settings.java96
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/api/CustomizableSettings.java85
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/data/GameDefinition.java6
5 files changed, 125 insertions, 80 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/actions/UpdateSettingsAction.java b/src/main/java/org/luxons/sevenwonders/actions/UpdateSettingsAction.java
index deb5e530..822a5a1c 100644
--- a/src/main/java/org/luxons/sevenwonders/actions/UpdateSettingsAction.java
+++ b/src/main/java/org/luxons/sevenwonders/actions/UpdateSettingsAction.java
@@ -2,18 +2,18 @@ package org.luxons.sevenwonders.actions;
import javax.validation.constraints.NotNull;
-import org.luxons.sevenwonders.game.Settings;
+import org.luxons.sevenwonders.game.api.CustomizableSettings;
public class UpdateSettingsAction {
@NotNull
- private Settings settings;
+ private CustomizableSettings settings;
- public Settings getSettings() {
+ public CustomizableSettings getSettings() {
return settings;
}
- public void setSettings(Settings settings) {
+ public void setSettings(CustomizableSettings settings) {
this.settings = settings;
}
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/Lobby.java b/src/main/java/org/luxons/sevenwonders/game/Lobby.java
index 525321b2..c0201438 100644
--- a/src/main/java/org/luxons/sevenwonders/game/Lobby.java
+++ b/src/main/java/org/luxons/sevenwonders/game/Lobby.java
@@ -3,6 +3,7 @@ package org.luxons.sevenwonders.game;
import java.util.ArrayList;
import java.util.List;
+import org.luxons.sevenwonders.game.api.CustomizableSettings;
import org.luxons.sevenwonders.game.data.GameDefinition;
public class Lobby {
@@ -17,7 +18,7 @@ public class Lobby {
private final List<Player> players;
- private Settings settings;
+ private CustomizableSettings settings;
private State state = State.LOBBY;
@@ -27,7 +28,7 @@ public class Lobby {
this.owner = owner;
this.gameDefinition = gameDefinition;
this.players = new ArrayList<>(gameDefinition.getMinPlayers());
- this.settings = new Settings();
+ this.settings = new CustomizableSettings();
players.add(owner);
}
@@ -43,11 +44,11 @@ public class Lobby {
return players;
}
- public Settings getSettings() {
+ public CustomizableSettings getSettings() {
return settings;
}
- public void setSettings(Settings settings) {
+ public void setSettings(CustomizableSettings settings) {
this.settings = settings;
}
@@ -82,7 +83,6 @@ public class Lobby {
throw new PlayerUnderflowException();
}
state = State.PLAYING;
- settings.setNbPlayers(players.size());
return gameDefinition.initGame(id, settings, players);
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/Settings.java b/src/main/java/org/luxons/sevenwonders/game/Settings.java
index cf7d1ea0..cd847d8a 100644
--- a/src/main/java/org/luxons/sevenwonders/game/Settings.java
+++ b/src/main/java/org/luxons/sevenwonders/game/Settings.java
@@ -1,86 +1,68 @@
package org.luxons.sevenwonders.game;
-import java.util.HashMap;
import java.util.Map;
import java.util.Random;
+import org.luxons.sevenwonders.game.api.CustomizableSettings;
import org.luxons.sevenwonders.game.data.definitions.WonderSide;
import org.luxons.sevenwonders.game.data.definitions.WonderSidePickMethod;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-
public class Settings {
- private int nbPlayers = -1;
+ private final Random random;
- private int initialGold = 3;
+ private final int nbPlayers;
- private int discardedCardGold = 3;
+ private final int initialGold;
- private int defaultTradingCost = 2;
+ private final int discardedCardGold;
- private WonderSidePickMethod wonderSidePickMethod = WonderSidePickMethod.EACH_RANDOM;
+ private final int defaultTradingCost;
- private transient WonderSide lastPickedSide = null;
+ private final WonderSidePickMethod wonderSidePickMethod;
- private long randomSeedForTests = -1;
+ private WonderSide lastPickedSide = null;
- private transient Random random;
+ private final int lostPointsPerDefeat;
- private int lostPointsPerDefeat = 1;
+ private final Map<Integer, Integer> wonPointsPerVictoryPerAge;
- private Map<Integer, Integer> wonPointsPerVictoryPerAge = new HashMap<>();
+ public Settings(int nbPlayers) {
+ this(nbPlayers, new CustomizableSettings());
+ }
- public Settings() {
- wonPointsPerVictoryPerAge.put(1, 1);
- wonPointsPerVictoryPerAge.put(2, 3);
- wonPointsPerVictoryPerAge.put(3, 5);
+ public Settings(int nbPlayers, CustomizableSettings customSettings) {
+ long seed = customSettings.getRandomSeedForTests();
+ this.random = seed > 0 ? new Random(seed) : new Random();
+ this.nbPlayers = nbPlayers;
+ this.initialGold = customSettings.getInitialGold();
+ this.discardedCardGold = customSettings.getDiscardedCardGold();
+ this.defaultTradingCost = customSettings.getDefaultTradingCost();
+ this.wonderSidePickMethod = customSettings.getWonderSidePickMethod();
+ this.lostPointsPerDefeat = customSettings.getLostPointsPerDefeat();
+ this.wonPointsPerVictoryPerAge = customSettings.getWonPointsPerVictoryPerAge();
}
- @JsonIgnore
- public int getNbPlayers() {
- if (nbPlayers < 0) {
- throw new IllegalStateException("The number of players has not been initialized");
- }
- return nbPlayers;
+ public Random getRandom() {
+ return random;
}
- public void setNbPlayers(int nbPlayers) {
- this.nbPlayers = nbPlayers;
+ public int getNbPlayers() {
+ return nbPlayers;
}
public int getInitialGold() {
return initialGold;
}
- public void setInitialGold(int initialGold) {
- this.initialGold = initialGold;
- }
-
public int getDiscardedCardGold() {
return discardedCardGold;
}
- public void setDiscardedCardGold(int discardedCardGold) {
- this.discardedCardGold = discardedCardGold;
- }
-
public int getDefaultTradingCost() {
return defaultTradingCost;
}
- public void setDefaultTradingCost(int defaultTradingCost) {
- this.defaultTradingCost = defaultTradingCost;
- }
-
- public WonderSidePickMethod getWonderSidePickMethod() {
- return wonderSidePickMethod;
- }
-
- public void setWonderSidePickMethod(WonderSidePickMethod wonderSidePickMethod) {
- this.wonderSidePickMethod = wonderSidePickMethod;
- }
-
public WonderSide pickWonderSide() {
return lastPickedSide = wonderSidePickMethod.pickSide(getRandom(), lastPickedSide);
}
@@ -89,31 +71,7 @@ public class Settings {
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;
- }
-
- public void setRandomSeedForTests(long randomSeedForTests) {
- this.randomSeedForTests = randomSeedForTests;
- }
-
- @JsonIgnore
- public Random getRandom() {
- if (random == null) {
- random = randomSeedForTests > 0 ? new Random(randomSeedForTests) : new Random();
- }
- return random;
- }
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/api/CustomizableSettings.java b/src/main/java/org/luxons/sevenwonders/game/api/CustomizableSettings.java
new file mode 100644
index 00000000..c303c4b6
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/api/CustomizableSettings.java
@@ -0,0 +1,85 @@
+package org.luxons.sevenwonders.game.api;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.luxons.sevenwonders.game.data.definitions.WonderSidePickMethod;
+
+public class CustomizableSettings {
+
+ private long randomSeedForTests = -1;
+
+ private WonderSidePickMethod wonderSidePickMethod = WonderSidePickMethod.EACH_RANDOM;
+
+ private int initialGold = 3;
+
+ private int discardedCardGold = 3;
+
+ private int defaultTradingCost = 2;
+
+ private int lostPointsPerDefeat = 1;
+
+ private Map<Integer, Integer> wonPointsPerVictoryPerAge = new HashMap<>();
+
+ public CustomizableSettings() {
+ wonPointsPerVictoryPerAge.put(1, 1);
+ wonPointsPerVictoryPerAge.put(2, 3);
+ wonPointsPerVictoryPerAge.put(3, 5);
+ }
+
+ public long getRandomSeedForTests() {
+ return randomSeedForTests;
+ }
+
+ public void setRandomSeedForTests(long randomSeedForTests) {
+ this.randomSeedForTests = randomSeedForTests;
+ }
+
+ public int getInitialGold() {
+ return initialGold;
+ }
+
+ public void setInitialGold(int initialGold) {
+ this.initialGold = initialGold;
+ }
+
+ public int getDiscardedCardGold() {
+ return discardedCardGold;
+ }
+
+ public void setDiscardedCardGold(int discardedCardGold) {
+ this.discardedCardGold = discardedCardGold;
+ }
+
+ public int getDefaultTradingCost() {
+ return defaultTradingCost;
+ }
+
+ public void setDefaultTradingCost(int defaultTradingCost) {
+ this.defaultTradingCost = defaultTradingCost;
+ }
+
+ public WonderSidePickMethod getWonderSidePickMethod() {
+ return wonderSidePickMethod;
+ }
+
+ public void setWonderSidePickMethod(WonderSidePickMethod wonderSidePickMethod) {
+ this.wonderSidePickMethod = wonderSidePickMethod;
+ }
+
+ 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;
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/data/GameDefinition.java b/src/main/java/org/luxons/sevenwonders/game/data/GameDefinition.java
index 05de6162..4c63718b 100644
--- a/src/main/java/org/luxons/sevenwonders/game/data/GameDefinition.java
+++ b/src/main/java/org/luxons/sevenwonders/game/data/GameDefinition.java
@@ -5,11 +5,12 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import org.luxons.sevenwonders.game.cards.Decks;
import org.luxons.sevenwonders.game.Game;
import org.luxons.sevenwonders.game.Player;
import org.luxons.sevenwonders.game.Settings;
+import org.luxons.sevenwonders.game.api.CustomizableSettings;
import org.luxons.sevenwonders.game.boards.Board;
+import org.luxons.sevenwonders.game.cards.Decks;
import org.luxons.sevenwonders.game.data.definitions.DecksDefinition;
import org.luxons.sevenwonders.game.data.definitions.WonderDefinition;
import org.luxons.sevenwonders.game.wonders.Wonder;
@@ -43,7 +44,8 @@ public class GameDefinition {
return MAX_PLAYERS;
}
- public Game initGame(long id, Settings settings, List<Player> orderedPlayers) {
+ public Game initGame(long id, CustomizableSettings customSettings, List<Player> orderedPlayers) {
+ Settings settings = new Settings(orderedPlayers.size(), customSettings);
List<Board> boards = assignBoards(settings, orderedPlayers);
Decks decks = decksDefinition.create(settings);
return new Game(id, settings, orderedPlayers, boards, decks);
bgstack15