summaryrefslogtreecommitdiff
path: root/src/main/java/org/luxons/sevenwonders
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2016-12-07 04:52:44 +0100
committerJoffrey BION <joffrey.bion@gmail.com>2016-12-08 02:10:10 +0100
commit3651553d82c66fabf96fd590a248089b4a51e7bd (patch)
tree1cd9415de9cb32164eea888092f25e568152f674 /src/main/java/org/luxons/sevenwonders
parentFirst draft of resource production elements (diff)
downloadseven-wonders-3651553d82c66fabf96fd590a248089b4a51e7bd.tar.gz
seven-wonders-3651553d82c66fabf96fd590a248089b4a51e7bd.tar.bz2
seven-wonders-3651553d82c66fabf96fd590a248089b4a51e7bd.zip
First draft of the game engine: boards, card effects, costs
Diffstat (limited to 'src/main/java/org/luxons/sevenwonders')
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/Settings.java24
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/boards/Board.java79
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/boards/Neighbour.java5
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/boards/Science.java24
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/boards/ScienceType.java5
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/boards/TradingRules.java25
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/cards/Card.java44
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/cards/Color.java5
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/cards/Requirements.java35
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/Discount.java44
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/Effect.java10
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/EndGameEffect.java9
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java21
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/InstantEffect.java10
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java21
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java21
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/ScienceIncrease.java18
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/resources/Production.java2
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/wonders/Wonder.java26
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/wonders/WonderLevel.java27
20 files changed, 454 insertions, 1 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/game/Settings.java b/src/main/java/org/luxons/sevenwonders/game/Settings.java
new file mode 100644
index 00000000..16bce141
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/Settings.java
@@ -0,0 +1,24 @@
+package org.luxons.sevenwonders.game;
+
+public class Settings {
+
+ private int initialGold = 3;
+
+ private int defaultTradingCost = 2;
+
+ public int getInitialGold() {
+ return initialGold;
+ }
+
+ public void setInitialGold(int initialGold) {
+ this.initialGold = initialGold;
+ }
+
+ public int getDefaultTradingCost() {
+ return defaultTradingCost;
+ }
+
+ public void setDefaultTradingCost(int defaultTradingCost) {
+ this.defaultTradingCost = defaultTradingCost;
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/boards/Board.java b/src/main/java/org/luxons/sevenwonders/game/boards/Board.java
new file mode 100644
index 00000000..1744f60b
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/boards/Board.java
@@ -0,0 +1,79 @@
+package org.luxons.sevenwonders.game.boards;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.luxons.sevenwonders.game.Settings;
+import org.luxons.sevenwonders.game.cards.Card;
+import org.luxons.sevenwonders.game.resources.Production;
+import org.luxons.sevenwonders.game.wonders.Wonder;
+
+public class Board {
+
+ private final Wonder wonder;
+
+ private final List<Card> playedCards = new ArrayList<>();
+
+ private final Production production = new Production();
+
+ private final Science science = new Science();
+
+ private final TradingRules tradingRules;
+
+ private int gold;
+
+ private int wonderLevel;
+
+ public Board(Wonder wonder, Settings settings) {
+ this.wonder = wonder;
+ this.wonderLevel = 0;
+ this.gold = settings.getInitialGold();
+ this.tradingRules = new TradingRules(settings.getDefaultTradingCost());
+ production.addFixedResource(wonder.getInitialResource(), 1);
+ }
+
+ public Wonder getWonder() {
+ return wonder;
+ }
+
+ public List<Card> getPlayedCards() {
+ return playedCards;
+ }
+
+ public void addCard(Card card) {
+ playedCards.add(card);
+ }
+
+ public Production getProduction() {
+ return production;
+ }
+
+ public TradingRules getTradingRules() {
+ return tradingRules;
+ }
+
+ public Science getScience() {
+ return science;
+ }
+
+ public int getGold() {
+ return gold;
+ }
+
+ public void setGold(int amount) {
+ this.gold = amount;
+ }
+
+ public int getWonderLevel() {
+ return wonderLevel;
+ }
+
+ public void upgradeWonderLevel() {
+ int maxLevel = wonder.getLevels().size();
+ if (maxLevel == wonderLevel) {
+ throw new IllegalStateException("This wonder has already reached its maximum level");
+ }
+ this.wonderLevel++;
+ wonder.getLevels().get(wonderLevel).getEffect().apply(this, null, null);
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/boards/Neighbour.java b/src/main/java/org/luxons/sevenwonders/game/boards/Neighbour.java
new file mode 100644
index 00000000..63611173
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/boards/Neighbour.java
@@ -0,0 +1,5 @@
+package org.luxons.sevenwonders.game.boards;
+
+public enum Neighbour {
+ LEFT, RIGHT;
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/boards/Science.java b/src/main/java/org/luxons/sevenwonders/game/boards/Science.java
new file mode 100644
index 00000000..2eb0117a
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/boards/Science.java
@@ -0,0 +1,24 @@
+package org.luxons.sevenwonders.game.boards;
+
+import java.util.EnumMap;
+import java.util.Map;
+
+public class Science {
+
+ private Map<ScienceType, Integer> quantities = new EnumMap<>(ScienceType.class);
+
+ private int jokers;
+
+ public void add(ScienceType type, int quantity) {
+ quantities.merge(type, quantity, (x, y) -> x + y);
+ }
+
+ public void addJoker(int quantity) {
+ jokers += quantity;
+ }
+
+ public void addAll(Science science) {
+ science.quantities.forEach(this::add);
+ jokers += science.jokers;
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/boards/ScienceType.java b/src/main/java/org/luxons/sevenwonders/game/boards/ScienceType.java
new file mode 100644
index 00000000..06408b9e
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/boards/ScienceType.java
@@ -0,0 +1,5 @@
+package org.luxons.sevenwonders.game.boards;
+
+public enum ScienceType {
+ COMPASS, WHEEL, TABLET
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/boards/TradingRules.java b/src/main/java/org/luxons/sevenwonders/game/boards/TradingRules.java
new file mode 100644
index 00000000..96131775
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/boards/TradingRules.java
@@ -0,0 +1,25 @@
+package org.luxons.sevenwonders.game.boards;
+
+import java.util.EnumMap;
+import java.util.Map;
+
+import org.luxons.sevenwonders.game.resources.ResourceType;
+
+public class TradingRules {
+
+ private final Map<ResourceType, Map<Neighbour, Integer>> costs = new EnumMap<>(ResourceType.class);
+
+ private final int defaultCost;
+
+ public TradingRules(int defaultCost) {
+ this.defaultCost = defaultCost;
+ }
+
+ public int getCost(ResourceType type, Neighbour neighbour) {
+ return costs.computeIfAbsent(type, t -> new EnumMap<>(Neighbour.class)).getOrDefault(neighbour, defaultCost);
+ }
+
+ public void setCost(ResourceType type, Neighbour neighbour, int cost) {
+ costs.computeIfAbsent(type, t -> new EnumMap<>(Neighbour.class)).put(neighbour, cost);
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/cards/Card.java b/src/main/java/org/luxons/sevenwonders/game/cards/Card.java
new file mode 100644
index 00000000..27763b2d
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/cards/Card.java
@@ -0,0 +1,44 @@
+package org.luxons.sevenwonders.game.cards;
+
+import org.luxons.sevenwonders.game.boards.Board;
+import org.luxons.sevenwonders.game.effects.Effect;
+
+public class Card {
+
+ private final String name;
+
+ private final Color color;
+
+ private final Requirements requirements;
+
+ private final Effect effect;
+
+ public Card(String name, Color color, Requirements requirements, Effect effect) {
+ this.name = name;
+ this.color = color;
+ this.requirements = requirements;
+ this.effect = effect;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Color getColor() {
+ return color;
+ }
+
+ public Requirements getRequirements() {
+ return requirements;
+ }
+
+ public Effect getEffect() {
+ return effect;
+ }
+
+ public void play(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) {
+ board.addCard(this);
+ requirements.pay(board);
+ effect.apply(board, leftNeighbourBoard, rightNeighbourBoard);
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/cards/Color.java b/src/main/java/org/luxons/sevenwonders/game/cards/Color.java
new file mode 100644
index 00000000..87d5b5b1
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/cards/Color.java
@@ -0,0 +1,5 @@
+package org.luxons.sevenwonders.game.cards;
+
+public enum Color {
+ BROWN, GREY, YELLOW, BLUE, GREEN, RED, PURPLE;
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/cards/Requirements.java b/src/main/java/org/luxons/sevenwonders/game/cards/Requirements.java
new file mode 100644
index 00000000..e6335a58
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/cards/Requirements.java
@@ -0,0 +1,35 @@
+package org.luxons.sevenwonders.game.cards;
+
+import org.luxons.sevenwonders.game.boards.Board;
+import org.luxons.sevenwonders.game.resources.Resources;
+
+public class Requirements {
+
+ private int goldCost;
+
+ private Resources resources = new Resources();
+
+ public int getGoldCost() {
+ return goldCost;
+ }
+
+ public void setGoldCost(int goldCost) {
+ this.goldCost = goldCost;
+ }
+
+ public Resources getResources() {
+ return resources;
+ }
+
+ public void setResources(Resources resources) {
+ this.resources = resources;
+ }
+
+ public boolean isAffordedBy(Board board) {
+ return board.getGold() >= goldCost && board.getProduction().contains(resources);
+ }
+
+ public void pay(Board board) {
+ board.setGold(board.getGold() - goldCost);
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java b/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java
new file mode 100644
index 00000000..8fce19d4
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java
@@ -0,0 +1,44 @@
+package org.luxons.sevenwonders.game.effects;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.luxons.sevenwonders.game.boards.Neighbour;
+import org.luxons.sevenwonders.game.boards.Board;
+import org.luxons.sevenwonders.game.boards.TradingRules;
+import org.luxons.sevenwonders.game.resources.ResourceType;
+
+public class Discount extends InstantEffect {
+
+ private final List<ResourceType> resourceTypes = new ArrayList<>();
+
+ private final List<Neighbour> neighbours = new ArrayList<>();
+
+ private int discountedPrice;
+
+ public List<ResourceType> getResourceTypes() {
+ return resourceTypes;
+ }
+
+ public List<Neighbour> getNeighbours() {
+ return neighbours;
+ }
+
+ public int getDiscountedPrice() {
+ return discountedPrice;
+ }
+
+ public void setDiscountedPrice(int discountedPrice) {
+ this.discountedPrice = discountedPrice;
+ }
+
+ @Override
+ public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) {
+ TradingRules rules = board.getTradingRules();
+ for (ResourceType type : resourceTypes) {
+ for (Neighbour neighbour : neighbours) {
+ rules.setCost(type, neighbour, discountedPrice);
+ }
+ }
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/Effect.java b/src/main/java/org/luxons/sevenwonders/game/effects/Effect.java
new file mode 100644
index 00000000..86a6ae8c
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/Effect.java
@@ -0,0 +1,10 @@
+package org.luxons.sevenwonders.game.effects;
+
+import org.luxons.sevenwonders.game.boards.Board;
+
+public abstract class Effect {
+
+ public abstract void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard);
+
+ public abstract int computePoints(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard);
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/EndGameEffect.java b/src/main/java/org/luxons/sevenwonders/game/effects/EndGameEffect.java
new file mode 100644
index 00000000..e7a08e5c
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/EndGameEffect.java
@@ -0,0 +1,9 @@
+package org.luxons.sevenwonders.game.effects;
+
+import org.luxons.sevenwonders.game.boards.Board;
+
+public abstract class EndGameEffect extends Effect {
+
+ public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) {
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java b/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java
new file mode 100644
index 00000000..8e11073e
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java
@@ -0,0 +1,21 @@
+package org.luxons.sevenwonders.game.effects;
+
+import org.luxons.sevenwonders.game.boards.Board;
+
+public class GoldIncrease extends InstantEffect {
+
+ private int amount;
+
+ public int getAmount() {
+ return amount;
+ }
+
+ public void setAmount(int amount) {
+ this.amount = amount;
+ }
+
+ @Override
+ public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) {
+ board.setGold(board.getGold() + amount);
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/InstantEffect.java b/src/main/java/org/luxons/sevenwonders/game/effects/InstantEffect.java
new file mode 100644
index 00000000..9f2e09ff
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/InstantEffect.java
@@ -0,0 +1,10 @@
+package org.luxons.sevenwonders.game.effects;
+
+import org.luxons.sevenwonders.game.boards.Board;
+
+public abstract class InstantEffect extends Effect {
+
+ public int computePoints(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) {
+ return 0;
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java b/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java
new file mode 100644
index 00000000..3b3a24a2
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java
@@ -0,0 +1,21 @@
+package org.luxons.sevenwonders.game.effects;
+
+import org.luxons.sevenwonders.game.boards.Board;
+import org.luxons.sevenwonders.game.resources.Production;
+
+public class ProductionIncrease extends InstantEffect {
+
+ private Production production = new Production();
+
+ public Production getProduction() {
+ return production;
+ }
+
+ public void setProduction(Production production) {
+ this.production = production;
+ }
+
+ public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) {
+ board.getProduction().addAll(production);
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java b/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java
new file mode 100644
index 00000000..4238e891
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java
@@ -0,0 +1,21 @@
+package org.luxons.sevenwonders.game.effects;
+
+import org.luxons.sevenwonders.game.boards.Board;
+
+public class RawPointsIncrease extends EndGameEffect {
+
+ private int points;
+
+ public int getPoints() {
+ return points;
+ }
+
+ public void setPoints(int points) {
+ this.points = points;
+ }
+
+ @Override
+ public int computePoints(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) {
+ return points;
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/ScienceIncrease.java b/src/main/java/org/luxons/sevenwonders/game/effects/ScienceIncrease.java
new file mode 100644
index 00000000..4e3944cf
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/ScienceIncrease.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 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/resources/Production.java b/src/main/java/org/luxons/sevenwonders/game/resources/Production.java
index 5463bea1..f4d46b59 100644
--- a/src/main/java/org/luxons/sevenwonders/game/resources/Production.java
+++ b/src/main/java/org/luxons/sevenwonders/game/resources/Production.java
@@ -23,7 +23,7 @@ public class Production {
alternativeResources.add(optionSet);
}
- void addAll(Resources resources) {
+ public void addAll(Resources resources) {
fixedResources.addAll(resources);
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/wonders/Wonder.java b/src/main/java/org/luxons/sevenwonders/game/wonders/Wonder.java
new file mode 100644
index 00000000..3a3d0e97
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/wonders/Wonder.java
@@ -0,0 +1,26 @@
+package org.luxons.sevenwonders.game.wonders;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.luxons.sevenwonders.game.resources.ResourceType;
+
+public class Wonder {
+
+ private final ResourceType initialResource;
+
+ private final List<WonderLevel> levels;
+
+ public Wonder(ResourceType initialResource, WonderLevel... levels) {
+ this.initialResource = initialResource;
+ this.levels = Arrays.asList(levels);
+ }
+
+ public ResourceType getInitialResource() {
+ return initialResource;
+ }
+
+ public List<WonderLevel> getLevels() {
+ return levels;
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/wonders/WonderLevel.java b/src/main/java/org/luxons/sevenwonders/game/wonders/WonderLevel.java
new file mode 100644
index 00000000..23571149
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/wonders/WonderLevel.java
@@ -0,0 +1,27 @@
+package org.luxons.sevenwonders.game.wonders;
+
+import org.luxons.sevenwonders.game.cards.Requirements;
+import org.luxons.sevenwonders.game.effects.Effect;
+
+public class WonderLevel {
+
+ private Requirements requirements;
+
+ private Effect effect;
+
+ public Requirements getRequirements() {
+ return requirements;
+ }
+
+ public void setRequirements(Requirements requirements) {
+ this.requirements = requirements;
+ }
+
+ public Effect getEffect() {
+ return effect;
+ }
+
+ public void setEffect(Effect effect) {
+ this.effect = effect;
+ }
+}
bgstack15