diff options
author | Joffrey BION <joffrey.bion@gmail.com> | 2018-04-25 21:46:37 +0200 |
---|---|---|
committer | Joffrey BION <joffrey.bion@gmail.com> | 2018-04-25 21:46:37 +0200 |
commit | 839975bd8762a944e34a367e85ba98d74dee8e5c (patch) | |
tree | ea81680204a27c42e2f5549ecd93eef1bfe004a6 /game-engine/src/main | |
parent | Add tests for BuildWonderMove (diff) | |
download | seven-wonders-839975bd8762a944e34a367e85ba98d74dee8e5c.tar.gz seven-wonders-839975bd8762a944e34a367e85ba98d74dee8e5c.tar.bz2 seven-wonders-839975bd8762a944e34a367e85ba98d74dee8e5c.zip |
Extract min/max players as JSON rules
Diffstat (limited to 'game-engine/src/main')
4 files changed, 35 insertions, 15 deletions
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/data/GameDefinition.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/data/GameDefinition.java index 7604ca6a..0402a26d 100644 --- a/game-engine/src/main/java/org/luxons/sevenwonders/game/data/GameDefinition.java +++ b/game-engine/src/main/java/org/luxons/sevenwonders/game/data/GameDefinition.java @@ -16,31 +16,24 @@ import org.luxons.sevenwonders.game.wonders.Wonder; public class GameDefinition { - /** - * This value is heavily dependent on the JSON data. Any change must be carefully thought through. - */ - private static final int MIN_PLAYERS = 3; + private final GlobalRules rules; - /** - * This value is heavily dependent on the JSON data. Any change must be carefully thought through. - */ - private static final int MAX_PLAYERS = 7; + private final WonderDefinition[] wonders; - private WonderDefinition[] wonders; + private final DecksDefinition decksDefinition; - private DecksDefinition decksDefinition; - - GameDefinition(WonderDefinition[] wonders, DecksDefinition decksDefinition) { + GameDefinition(GlobalRules rules, WonderDefinition[] wonders, DecksDefinition decksDefinition) { + this.rules = rules; this.wonders = wonders; this.decksDefinition = decksDefinition; } public int getMinPlayers() { - return MIN_PLAYERS; + return rules.getMinPlayers(); } public int getMaxPlayers() { - return MAX_PLAYERS; + return rules.getMaxPlayers(); } public Game initGame(long id, CustomizableSettings customSettings, int nbPlayers) { diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/data/GameDefinitionLoader.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/data/GameDefinitionLoader.java index 7a9c5af0..a1bd7b8d 100644 --- a/game-engine/src/main/java/org/luxons/sevenwonders/game/data/GameDefinitionLoader.java +++ b/game-engine/src/main/java/org/luxons/sevenwonders/game/data/GameDefinitionLoader.java @@ -35,6 +35,8 @@ public class GameDefinitionLoader { private static final String BASE_PACKAGE_PATH = '/' + BASE_PACKAGE.replace('.', '/'); + private static final String GLOBAL_RULES_FILE = "global_rules.json"; + private static final String CARDS_FILE = "cards.json"; private static final String WONDERS_FILE = "wonders.json"; @@ -50,7 +52,11 @@ public class GameDefinitionLoader { } private static GameDefinition load() { - return new GameDefinition(loadWonders(), loadDecks()); + return new GameDefinition(loadGlobalRules(), loadWonders(), loadDecks()); + } + + private static GlobalRules loadGlobalRules() { + return readJsonFile(GLOBAL_RULES_FILE, GlobalRules.class); } private static WonderDefinition[] loadWonders() { diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/data/GlobalRules.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/data/GlobalRules.java new file mode 100644 index 00000000..526bebad --- /dev/null +++ b/game-engine/src/main/java/org/luxons/sevenwonders/game/data/GlobalRules.java @@ -0,0 +1,17 @@ +package org.luxons.sevenwonders.game.data; + +@SuppressWarnings("unused") // fields are set by Gson +class GlobalRules { + + private int minPlayers; + + private int maxPlayers; + + int getMinPlayers() { + return minPlayers; + } + + int getMaxPlayers() { + return maxPlayers; + } +} diff --git a/game-engine/src/main/resources/org/luxons/sevenwonders/game/data/global_rules.json b/game-engine/src/main/resources/org/luxons/sevenwonders/game/data/global_rules.json new file mode 100644 index 00000000..9b486fe6 --- /dev/null +++ b/game-engine/src/main/resources/org/luxons/sevenwonders/game/data/global_rules.json @@ -0,0 +1,4 @@ +{ + "minPlayers": 3, + "maxPlayers": 7 +} |