From 066e4159dc4aadf63eb4d3b8c61da1f85158020b Mon Sep 17 00:00:00 2001 From: Joffrey BION Date: Wed, 7 Dec 2016 23:36:33 +0100 Subject: Add game data loading skeleton --- .../luxons/sevenwonders/game/data/GameData.java | 60 ++++++++++++++++++++++ .../sevenwonders/game/data/GameDataLoader.java | 49 ++++++++++++++++++ .../sevenwonders/game/effects/ScienceIncrease.java | 18 ------- .../sevenwonders/game/effects/ScienceProgress.java | 18 +++++++ .../luxons/sevenwonders/game/wonders/Wonder.java | 27 ++++++++-- .../luxons/sevenwonders/game/cards/CardTest.java | 6 +-- .../sevenwonders/game/effects/EffectTest.java | 6 +-- 7 files changed, 157 insertions(+), 27 deletions(-) create mode 100644 src/main/java/org/luxons/sevenwonders/game/data/GameData.java create mode 100644 src/main/java/org/luxons/sevenwonders/game/data/GameDataLoader.java delete mode 100644 src/main/java/org/luxons/sevenwonders/game/effects/ScienceIncrease.java create mode 100644 src/main/java/org/luxons/sevenwonders/game/effects/ScienceProgress.java (limited to 'src') diff --git a/src/main/java/org/luxons/sevenwonders/game/data/GameData.java b/src/main/java/org/luxons/sevenwonders/game/data/GameData.java new file mode 100644 index 00000000..70a64eef --- /dev/null +++ b/src/main/java/org/luxons/sevenwonders/game/data/GameData.java @@ -0,0 +1,60 @@ +package org.luxons.sevenwonders.game.data; + +import java.util.ArrayList; +import java.util.List; + +import org.luxons.sevenwonders.game.cards.Card; +import org.luxons.sevenwonders.game.wonders.Wonder; + +public class GameData { + + private int nbAges = 3; + + private int minPlayers = 3; + + private int maxPlayers = 7; + + private List wonders = new ArrayList<>(); + + private List> cardsPerAge = new ArrayList<>(); + + public int getNbAges() { + return nbAges; + } + + public void setNbAges(int nbAges) { + this.nbAges = nbAges; + } + + public int getMinPlayers() { + return minPlayers; + } + + public void setMinPlayers(int minPlayers) { + this.minPlayers = minPlayers; + } + + public int getMaxPlayers() { + return maxPlayers; + } + + public void setMaxPlayers(int maxPlayers) { + this.maxPlayers = maxPlayers; + } + + public List getWonders() { + return wonders; + } + + public void setWonders(List wonders) { + this.wonders = wonders; + } + + public List getCards(int age) { + return cardsPerAge.get(age - 1); // 0-based + } + + public void setCards(int age, List cards) { + cardsPerAge.set(age - 1, cards); // 0-based + } +} diff --git a/src/main/java/org/luxons/sevenwonders/game/data/GameDataLoader.java b/src/main/java/org/luxons/sevenwonders/game/data/GameDataLoader.java new file mode 100644 index 00000000..3047b900 --- /dev/null +++ b/src/main/java/org/luxons/sevenwonders/game/data/GameDataLoader.java @@ -0,0 +1,49 @@ +package org.luxons.sevenwonders.game.data; + +import java.util.ArrayList; +import java.util.List; + +import org.luxons.sevenwonders.game.cards.Card; +import org.luxons.sevenwonders.game.cards.Color; +import org.luxons.sevenwonders.game.cards.Requirements; +import org.luxons.sevenwonders.game.effects.GoldIncrease; +import org.luxons.sevenwonders.game.effects.RawPointsIncrease; +import org.luxons.sevenwonders.game.effects.ScienceProgress; +import org.luxons.sevenwonders.game.resources.ResourceType; +import org.luxons.sevenwonders.game.wonders.Wonder; + +public class GameDataLoader { + + private static final String wondersFile = "wonders.json"; + + public static GameData load() { + GameData data = new GameData(); + data.setWonders(loadWonders()); + for (int age = 1; age <= data.getNbAges(); age++) { + data.setCards(age, loadCards(age)); + } + return data; + } + + private static List loadWonders() { + List wonders = new ArrayList<>(); + // TODO load actual file + wonders.add(new Wonder("TestWonder W", ResourceType.WOOD)); + wonders.add(new Wonder("TestWonder S", ResourceType.STONE)); + wonders.add(new Wonder("TestWonder O", ResourceType.ORE)); + wonders.add(new Wonder("TestWonder C", ResourceType.CLAY)); + wonders.add(new Wonder("TestWonder G", ResourceType.GLASS)); + wonders.add(new Wonder("TestWonder L", ResourceType.LOOM)); + wonders.add(new Wonder("TestWonder P", ResourceType.PAPYRUS)); + return wonders; + } + + private static List loadCards(int age) { + List wonders = new ArrayList<>(); + // TODO load actual file + wonders.add(new Card("TestCard Yellow", Color.YELLOW, new Requirements(), new GoldIncrease())); + wonders.add(new Card("TestCard Blue", Color.BLUE, new Requirements(), new RawPointsIncrease())); + wonders.add(new Card("TestCard Green", Color.GREEN, new Requirements(), new ScienceProgress())); + return wonders; + } +} diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/ScienceIncrease.java b/src/main/java/org/luxons/sevenwonders/game/effects/ScienceIncrease.java deleted file mode 100644 index 4e3944cf..00000000 --- a/src/main/java/org/luxons/sevenwonders/game/effects/ScienceIncrease.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.luxons.sevenwonders.game.effects; - -import org.luxons.sevenwonders.game.boards.Board; -import org.luxons.sevenwonders.game.boards.Science; - -public class ScienceIncrease extends InstantEffect { - - private Science science; - - public void setScience(Science science) { - this.science = science; - } - - @Override - public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { - board.getScience().addAll(science); - } -} diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/ScienceProgress.java b/src/main/java/org/luxons/sevenwonders/game/effects/ScienceProgress.java new file mode 100644 index 00000000..8feba09d --- /dev/null +++ b/src/main/java/org/luxons/sevenwonders/game/effects/ScienceProgress.java @@ -0,0 +1,18 @@ +package org.luxons.sevenwonders.game.effects; + +import org.luxons.sevenwonders.game.boards.Board; +import org.luxons.sevenwonders.game.boards.Science; + +public class ScienceProgress extends InstantEffect { + + private Science science; + + public void setScience(Science science) { + this.science = science; + } + + @Override + public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { + board.getScience().addAll(science); + } +} diff --git a/src/main/java/org/luxons/sevenwonders/game/wonders/Wonder.java b/src/main/java/org/luxons/sevenwonders/game/wonders/Wonder.java index 3a3d0e97..27d06435 100644 --- a/src/main/java/org/luxons/sevenwonders/game/wonders/Wonder.java +++ b/src/main/java/org/luxons/sevenwonders/game/wonders/Wonder.java @@ -7,20 +7,41 @@ import org.luxons.sevenwonders.game.resources.ResourceType; public class Wonder { - private final ResourceType initialResource; + private String name; - private final List levels; + private ResourceType initialResource; - public Wonder(ResourceType initialResource, WonderLevel... levels) { + private List levels; + + public Wonder() { + } + + public Wonder(String name, ResourceType initialResource, WonderLevel... levels) { this.initialResource = initialResource; this.levels = Arrays.asList(levels); } + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + public ResourceType getInitialResource() { return initialResource; } + public void setInitialResource(ResourceType initialResource) { + this.initialResource = initialResource; + } + public List getLevels() { return levels; } + + public void setLevels(List levels) { + this.levels = levels; + } } diff --git a/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java b/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java index db11c466..db4eb049 100644 --- a/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java +++ b/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java @@ -24,9 +24,9 @@ public class CardTest { @Before public void initBoard() { Settings settings = new Settings(); - board = new Board(new Wonder(ResourceType.WOOD), settings); - leftBoard = new Board(new Wonder(ResourceType.STONE), settings); - rightBoard = new Board(new Wonder(ResourceType.PAPYRUS), settings); + board = new Board(new Wonder("TestWonder", ResourceType.WOOD), settings); + leftBoard = new Board(new Wonder("TestWonder", ResourceType.STONE), settings); + rightBoard = new Board(new Wonder("TestWonder", ResourceType.PAPYRUS), settings); Requirements treeFarmRequirements = new Requirements(); treeFarmRequirements.setGoldCost(1); diff --git a/src/test/java/org/luxons/sevenwonders/game/effects/EffectTest.java b/src/test/java/org/luxons/sevenwonders/game/effects/EffectTest.java index 51a7a192..25dfcf38 100644 --- a/src/test/java/org/luxons/sevenwonders/game/effects/EffectTest.java +++ b/src/test/java/org/luxons/sevenwonders/game/effects/EffectTest.java @@ -32,9 +32,9 @@ public class EffectTest { Settings settings = new Settings(); settings.setInitialGold(INITIAL_GOLD); - board = new Board(new Wonder(ResourceType.WOOD), settings); - leftBoard = new Board(new Wonder(ResourceType.STONE), settings); - rightBoard = new Board(new Wonder(ResourceType.PAPYRUS), settings); + board = new Board(new Wonder("TestWonder", ResourceType.WOOD), settings); + leftBoard = new Board(new Wonder("TestWonder", ResourceType.STONE), settings); + rightBoard = new Board(new Wonder("TestWonder", ResourceType.PAPYRUS), settings); resources1Stone1Wood = new Resources(); resources1Stone1Wood.add(ResourceType.STONE, 1); -- cgit