diff options
author | jbion <joffrey.bion@amadeus.com> | 2016-12-22 00:26:20 +0100 |
---|---|---|
committer | jbion <joffrey.bion@amadeus.com> | 2016-12-22 00:26:20 +0100 |
commit | 606709b1347170f303f55e15c98f845d7a2f1e3d (patch) | |
tree | 423a20da0f70add2077ad3db594ed68990e36eb2 /src/main/java/org | |
parent | Remove unused "nb of guild cards" setting (diff) | |
download | seven-wonders-606709b1347170f303f55e15c98f845d7a2f1e3d.tar.gz seven-wonders-606709b1347170f303f55e15c98f845d7a2f1e3d.tar.bz2 seven-wonders-606709b1347170f303f55e15c98f845d7a2f1e3d.zip |
Huge refac to pass the Table instead of left/right/self boards
Diffstat (limited to 'src/main/java/org')
25 files changed, 163 insertions, 155 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/game/Game.java b/src/main/java/org/luxons/sevenwonders/game/Game.java index d9dec5fd..e9962e10 100644 --- a/src/main/java/org/luxons/sevenwonders/game/Game.java +++ b/src/main/java/org/luxons/sevenwonders/game/Game.java @@ -17,6 +17,8 @@ public class Game { private final Settings settings; + private final List<Player> players; + private final Table table; private final Decks decks; @@ -32,7 +34,8 @@ public class Game { public Game(long id, Settings settings, List<Player> players, List<Board> boards, Decks decks) { this.id = id; this.settings = settings; - this.table = new Table(players, boards); + this.players = players; + this.table = new Table(boards); this.decks = decks; this.discardedCards = new ArrayList<>(); this.hands = new HashMap<>(); @@ -44,12 +47,8 @@ public class Game { return id; } - public List<Player> getPlayers() { - return table.getPlayers(); - } - public boolean containsUser(String userName) { - return getPlayers().stream().anyMatch(p -> p.getUserName().equals(userName)); + return players.stream().anyMatch(p -> p.getUserName().equals(userName)); } private void startNewAge() { @@ -65,17 +64,15 @@ public class Game { .collect(Collectors.toList()); } - public void prepareCard(int playerIndex, Move move) throws InvalidMoveException { - validateMove(playerIndex, move); - preparedMoves.put(playerIndex, move); - } - - private void validateMove(int playerIndex, Move move) throws InvalidMoveException { - // TODO throw if invalid + public void prepareCard(Move move) throws InvalidMoveException { + if (!move.isValid(table)) { + throw new InvalidMoveException(); + } + preparedMoves.put(move.getPlayerIndex(), move); } public boolean areAllPlayersReady() { - return preparedMoves.size() == table.getPlayers().size(); + return preparedMoves.size() == players.size(); } public List<Move> playTurn() { @@ -131,7 +128,6 @@ public class Game { break; } }); - } private static class MissingPreparedMoveException extends RuntimeException { diff --git a/src/main/java/org/luxons/sevenwonders/game/api/HandCard.java b/src/main/java/org/luxons/sevenwonders/game/api/HandCard.java index 743a48db..80c09549 100644 --- a/src/main/java/org/luxons/sevenwonders/game/api/HandCard.java +++ b/src/main/java/org/luxons/sevenwonders/game/api/HandCard.java @@ -1,19 +1,24 @@ package org.luxons.sevenwonders.game.api; +import org.luxons.sevenwonders.game.boards.Board; import org.luxons.sevenwonders.game.cards.Card; public class HandCard { private final Card data; - private boolean chainable; + private final boolean chainable; - private boolean free; + private final boolean free; - private boolean playable; + private final boolean playable; - public HandCard(Card card) { + public HandCard(Card card, Table table, int playerIndex) { + Board board = table.getBoard(playerIndex); this.data = card; + this.chainable = card.isChainableOn(board); + this.free = card.isAffordedBy(board) && card.getRequirements().getGold() == 0; + this.playable = card.isPlayable(table, playerIndex); } public Card getData() { @@ -24,23 +29,12 @@ public class HandCard { return chainable; } - public void setChainable(boolean chainable) { - this.chainable = chainable; - } - public boolean isFree() { return free; } - public void setFree(boolean free) { - this.free = free; - } - public boolean isPlayable() { return playable; } - public void setPlayable(boolean playable) { - this.playable = playable; - } } diff --git a/src/main/java/org/luxons/sevenwonders/game/api/Table.java b/src/main/java/org/luxons/sevenwonders/game/api/Table.java index 44813ee9..9d33c779 100644 --- a/src/main/java/org/luxons/sevenwonders/game/api/Table.java +++ b/src/main/java/org/luxons/sevenwonders/game/api/Table.java @@ -3,8 +3,8 @@ package org.luxons.sevenwonders.game.api; import java.util.List; import java.util.stream.Collectors; -import org.luxons.sevenwonders.game.Player; import org.luxons.sevenwonders.game.boards.Board; +import org.luxons.sevenwonders.game.boards.RelativeBoardPosition; import org.luxons.sevenwonders.game.cards.Card; /** @@ -15,29 +15,25 @@ public class Table { private final int nbPlayers; - private final List<Player> players; - private final List<Board> boards; - public Table(List<Player> players, List<Board> boards) { - this.nbPlayers = players.size(); - this.players = players; + public Table(List<Board> boards) { + this.nbPlayers = boards.size(); this.boards = boards; - if (players.size() != boards.size()) { - throw new IllegalArgumentException( - String.format("There are %d boards for %d players, it doesn't make sense", boards.size(), - players.size())); - } - } - - public List<Player> getPlayers() { - return players; } public List<Board> getBoards() { return boards; } + public Board getBoard(int playerIndex) { + return boards.get(playerIndex); + } + + public Board getBoard(int playerIndex, RelativeBoardPosition position) { + return boards.get(position.getIndexFrom(playerIndex, nbPlayers)); + } + public int getNbPlayers() { return nbPlayers; } @@ -53,17 +49,12 @@ public class Table { } public void activateCard(int playerIndex, Card card) { - Board board = boards.get(playerIndex); - Board left = boards.get(wrapIndex(playerIndex - 1)); - Board right = boards.get(wrapIndex(playerIndex + 1)); - card.applyTo(board, left, right); + card.applyTo(this, playerIndex); } public void activateCurrentWonderStage(int playerIndex) { Board board = boards.get(playerIndex); - Board left = boards.get(wrapIndex(playerIndex - 1)); - Board right = boards.get(wrapIndex(playerIndex + 1)); - board.activateCurrentWonderLevel(left, right); + board.activateCurrentWonderLevel(this, playerIndex); } public void discard(int playerIndex, int goldBonus) { @@ -71,10 +62,6 @@ public class Table { board.setGold(board.getGold() + goldBonus); } - private int wrapIndex(int index) { - return Math.floorMod(index, nbPlayers); - } - public PlayerTurnInfo createPlayerTurnInfo(int playerIndex, List<Card> cards) { PlayerTurnInfo pti = new PlayerTurnInfo(playerIndex, this); pti.setHand(createHand(playerIndex, cards)); @@ -82,17 +69,6 @@ public class Table { } private List<HandCard> createHand(int playerIndex, List<Card> cards) { - return cards.stream().map(c -> createHandCard(playerIndex, c)).collect(Collectors.toList()); - } - - private HandCard createHandCard(int playerIndex, Card card) { - Board board = boards.get(playerIndex); - Board left = boards.get(wrapIndex(playerIndex - 1)); - Board right = boards.get(wrapIndex(playerIndex + 1)); - HandCard handCard = new HandCard(card); - handCard.setChainable(card.isChainableOn(board)); - handCard.setFree(card.isAffordedBy(board) && card.getRequirements().getGold() == 0); - handCard.setPlayable(card.isPlayable(board, left, right)); - return handCard; + return cards.stream().map(c -> new HandCard(c, this, playerIndex)).collect(Collectors.toList()); } } 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 1ac70daf..c509ee3b 100644 --- a/src/main/java/org/luxons/sevenwonders/game/boards/Board.java +++ b/src/main/java/org/luxons/sevenwonders/game/boards/Board.java @@ -3,7 +3,9 @@ package org.luxons.sevenwonders.game.boards; import java.util.ArrayList; import java.util.List; +import org.luxons.sevenwonders.game.Player; import org.luxons.sevenwonders.game.Settings; +import org.luxons.sevenwonders.game.api.Table; import org.luxons.sevenwonders.game.cards.Card; import org.luxons.sevenwonders.game.cards.Color; import org.luxons.sevenwonders.game.resources.Production; @@ -13,6 +15,8 @@ public class Board { private final Wonder wonder; + private final Player player; + private final List<Card> playedCards = new ArrayList<>(); private final Production production = new Production(); @@ -29,8 +33,9 @@ public class Board { private int nbDefeatTokens; - public Board(Wonder wonder, Settings settings) { + public Board(Wonder wonder, Player player, Settings settings) { this.wonder = wonder; + this.player = player; this.wonderLevel = 0; this.gold = settings.getInitialGold(); this.tradingRules = new TradingRules(settings.getDefaultTradingCost()); @@ -41,6 +46,10 @@ public class Board { return wonder; } + public Player getPlayer() { + return player; + } + public List<Card> getPlayedCards() { return playedCards; } @@ -89,12 +98,8 @@ public class Board { this.wonderLevel++; } - public void activateCurrentWonderLevel(Board leftNeighbourBoard, Board rightNeighbourBoard) { - activateWonderLevel(wonderLevel, leftNeighbourBoard, rightNeighbourBoard); - } - - public void activateWonderLevel(int level, Board leftNeighbourBoard, Board rightNeighbourBoard) { - wonder.getLevels().get(level).activate(this, leftNeighbourBoard, rightNeighbourBoard); + public void activateCurrentWonderLevel(Table table, int playerIndex) { + wonder.getLevels().get(wonderLevel).activate(table, playerIndex); } public int getNbWarSymbols() { diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/BoardElementType.java b/src/main/java/org/luxons/sevenwonders/game/boards/BoardElementType.java index 34cab4a4..5c029331 100644 --- a/src/main/java/org/luxons/sevenwonders/game/effects/BoardElementType.java +++ b/src/main/java/org/luxons/sevenwonders/game/boards/BoardElementType.java @@ -1,29 +1,28 @@ -package org.luxons.sevenwonders.game.effects; +package org.luxons.sevenwonders.game.boards; import java.util.List; -import org.luxons.sevenwonders.game.boards.Board; import org.luxons.sevenwonders.game.cards.Color; public enum BoardElementType { CARD { @Override - int getElementCount(Board board, List<Color> colors) { + public int getElementCount(Board board, List<Color> colors) { return board.getNbCardsOfColor(colors); } }, WONDER_LEVEL { @Override - int getElementCount(Board board, List<Color> colors) { + public int getElementCount(Board board, List<Color> colors) { return board.getWonderLevel(); } }, DEFEAT_TOKEN { @Override - int getElementCount(Board board, List<Color> colors) { + public int getElementCount(Board board, List<Color> colors) { return board.getNbDefeatTokens(); } }; - abstract int getElementCount(Board board, List<Color> colors); + public abstract int getElementCount(Board board, List<Color> colors); } diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/Provider.java b/src/main/java/org/luxons/sevenwonders/game/boards/Provider.java index a586dcca..bacd1e73 100644 --- a/src/main/java/org/luxons/sevenwonders/game/effects/Provider.java +++ b/src/main/java/org/luxons/sevenwonders/game/boards/Provider.java @@ -1,4 +1,4 @@ -package org.luxons.sevenwonders.game.effects; +package org.luxons.sevenwonders.game.boards; public enum Provider { LEFT_PLAYER, RIGHT_PLAYER diff --git a/src/main/java/org/luxons/sevenwonders/game/boards/RelativeBoardPosition.java b/src/main/java/org/luxons/sevenwonders/game/boards/RelativeBoardPosition.java new file mode 100644 index 00000000..16b2f3a9 --- /dev/null +++ b/src/main/java/org/luxons/sevenwonders/game/boards/RelativeBoardPosition.java @@ -0,0 +1,28 @@ +package org.luxons.sevenwonders.game.boards; + +public enum RelativeBoardPosition { + LEFT { + @Override + public int getIndexFrom(int playerIndex, int nbPlayers) { + return wrapIndex(playerIndex - 1, nbPlayers); + } + }, + SELF { + @Override + public int getIndexFrom(int playerIndex, int nbPlayers) { + return playerIndex; + } + }, + RIGHT { + @Override + public int getIndexFrom(int playerIndex, int nbPlayers) { + return wrapIndex(playerIndex + 1, nbPlayers); + } + }; + + public abstract int getIndexFrom(int playerIndex, int nbPlayers); + + int wrapIndex(int index, int nbPlayers) { + return Math.floorMod(index, nbPlayers); + } +} diff --git a/src/main/java/org/luxons/sevenwonders/game/boards/TradingRules.java b/src/main/java/org/luxons/sevenwonders/game/boards/TradingRules.java index ac13c354..97b60ea0 100644 --- a/src/main/java/org/luxons/sevenwonders/game/boards/TradingRules.java +++ b/src/main/java/org/luxons/sevenwonders/game/boards/TradingRules.java @@ -3,7 +3,6 @@ package org.luxons.sevenwonders.game.boards; import java.util.EnumMap; import java.util.Map; -import org.luxons.sevenwonders.game.effects.Provider; import org.luxons.sevenwonders.game.resources.ResourceType; public class TradingRules { diff --git a/src/main/java/org/luxons/sevenwonders/game/cards/Card.java b/src/main/java/org/luxons/sevenwonders/game/cards/Card.java index fe160857..e2d1d940 100644 --- a/src/main/java/org/luxons/sevenwonders/game/cards/Card.java +++ b/src/main/java/org/luxons/sevenwonders/game/cards/Card.java @@ -2,6 +2,7 @@ package org.luxons.sevenwonders.game.cards; import java.util.List; +import org.luxons.sevenwonders.game.api.Table; import org.luxons.sevenwonders.game.boards.Board; import org.luxons.sevenwonders.game.effects.Effect; @@ -64,17 +65,19 @@ public class Card { return requirements.isAffordedBy(board); } - public boolean isPlayable(Board board, Board left, Board right) { - return !board.isPlayed(name) && (isChainableOn(board) || requirements.isAffordedBy(board, left, right)); + public boolean isPlayable(Table table, int playerIndex) { + Board board = table.getBoard(playerIndex); + return !board.isPlayed(name) && (isChainableOn(board) || requirements.isAffordedBy(table, playerIndex)); } - public void applyTo(Board board, Board left, Board right) { + public void applyTo(Table table, int playerIndex) { // TODO add paid resources cost deduction - if (!isChainableOn(board)) { + Board playerBoard = table.getBoard(playerIndex); + if (!isChainableOn(playerBoard)) { // TODO add paid resources exemption - requirements.pay(board); + requirements.pay(playerBoard); } - effects.forEach(e -> e.apply(board, left, right)); + effects.forEach(e -> e.apply(table, playerIndex)); } @Override diff --git a/src/main/java/org/luxons/sevenwonders/game/cards/Requirements.java b/src/main/java/org/luxons/sevenwonders/game/cards/Requirements.java index 644eefd6..e729fedc 100644 --- a/src/main/java/org/luxons/sevenwonders/game/cards/Requirements.java +++ b/src/main/java/org/luxons/sevenwonders/game/cards/Requirements.java @@ -1,5 +1,6 @@ package org.luxons.sevenwonders.game.cards; +import org.luxons.sevenwonders.game.api.Table; import org.luxons.sevenwonders.game.boards.Board; import org.luxons.sevenwonders.game.resources.Resources; @@ -29,7 +30,8 @@ public class Requirements { return board.getGold() >= gold && board.getProduction().contains(resources); } - boolean isAffordedBy(Board board, Board left, Board right) { + boolean isAffordedBy(Table table, int playerIndex) { + Board board = table.getBoard(playerIndex); if (isAffordedBy(board)) { return true; } 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 a14411bd..5ab1a13f 100644 --- a/src/main/java/org/luxons/sevenwonders/game/data/GameDefinition.java +++ b/src/main/java/org/luxons/sevenwonders/game/data/GameDefinition.java @@ -1,9 +1,9 @@ package org.luxons.sevenwonders.game.data; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; import org.luxons.sevenwonders.game.Decks; import org.luxons.sevenwonders.game.Game; @@ -12,6 +12,7 @@ import org.luxons.sevenwonders.game.Settings; import org.luxons.sevenwonders.game.boards.Board; import org.luxons.sevenwonders.game.data.definitions.DecksDefinition; import org.luxons.sevenwonders.game.data.definitions.WonderDefinition; +import org.luxons.sevenwonders.game.wonders.Wonder; public class GameDefinition { @@ -43,18 +44,22 @@ public class GameDefinition { } public Game initGame(long id, Settings settings, List<Player> orderedPlayers) { - List<Board> boards = pickRandomBoards(settings); + List<Board> boards = assignBoards(settings, orderedPlayers); Decks decks = decksDefinition.create(settings); return new Game(id, settings, orderedPlayers, boards, decks); } - private List<Board> pickRandomBoards(Settings settings) { + private List<Board> assignBoards(Settings settings, List<Player> orderedPlayers) { List<WonderDefinition> randomizedWonders = Arrays.asList(wonders); Collections.shuffle(randomizedWonders, settings.getRandom()); - return Arrays.stream(wonders) - .map(def -> def.create(settings)) - .map(w -> new Board(w, settings)) - .limit(settings.getNbPlayers()) - .collect(Collectors.toList()); + + List<Board> boards = new ArrayList<>(orderedPlayers.size()); + for (Player player : orderedPlayers) { + WonderDefinition def = randomizedWonders.remove(0); + Wonder w = def.create(settings); + Board b = new Board(w, player, settings); + boards.add(b); + } + return boards; } } diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java b/src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java index 37db3532..05794702 100644 --- a/src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java +++ b/src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java @@ -2,7 +2,10 @@ package org.luxons.sevenwonders.game.effects; import java.util.List; +import org.luxons.sevenwonders.game.api.Table; import org.luxons.sevenwonders.game.boards.Board; +import org.luxons.sevenwonders.game.boards.BoardElementType; +import org.luxons.sevenwonders.game.boards.RelativeBoardPosition; import org.luxons.sevenwonders.game.cards.Color; public class BonusPerBoardElement implements Effect { @@ -59,28 +62,22 @@ public class BonusPerBoardElement implements Effect { } @Override - public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { - int goldGain = gold * computeNbOfMatchingElementsIn(board, leftNeighbourBoard, rightNeighbourBoard); + public void apply(Table table, int playerIndex) { + int goldGain = gold * computeNbOfMatchingElementsIn(table, playerIndex); + Board board = table.getBoard(playerIndex); board.setGold(board.getGold() + goldGain); } @Override - public int computePoints(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { - return points * computeNbOfMatchingElementsIn(board, leftNeighbourBoard, rightNeighbourBoard); + public int computePoints(Table table, int playerIndex) { + return points * computeNbOfMatchingElementsIn(table, playerIndex); } - private int computeNbOfMatchingElementsIn(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { - int totalCount = 0; - if (boards.contains(RelativeBoardPosition.SELF)) { - totalCount += computeNbOfMatchingElementsIn(board); - } - if (boards.contains(RelativeBoardPosition.LEFT)) { - totalCount += computeNbOfMatchingElementsIn(leftNeighbourBoard); - } - if (boards.contains(RelativeBoardPosition.RIGHT)) { - totalCount += computeNbOfMatchingElementsIn(rightNeighbourBoard); - } - return totalCount; + private int computeNbOfMatchingElementsIn(Table table, int playerIndex) { + return boards.stream() + .map(pos -> table.getBoard(playerIndex, pos)) + .mapToInt(this::computeNbOfMatchingElementsIn) + .sum(); } private int computeNbOfMatchingElementsIn(Board board) { diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java b/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java index 9b5d071f..a943b027 100644 --- a/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java +++ b/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java @@ -4,10 +4,11 @@ import java.util.ArrayList; import java.util.List; import org.luxons.sevenwonders.game.boards.Board; +import org.luxons.sevenwonders.game.boards.Provider; import org.luxons.sevenwonders.game.boards.TradingRules; import org.luxons.sevenwonders.game.resources.ResourceType; -public class Discount extends InstantEffect { +public class Discount extends InstantOwnBoardEffect { private final List<ResourceType> resourceTypes = new ArrayList<>(); @@ -32,7 +33,7 @@ public class Discount extends InstantEffect { } @Override - public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { + public void apply(Board board) { TradingRules rules = board.getTradingRules(); for (ResourceType type : resourceTypes) { for (Provider provider : providers) { diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/Effect.java b/src/main/java/org/luxons/sevenwonders/game/effects/Effect.java index 1d2189a2..692eaea0 100644 --- a/src/main/java/org/luxons/sevenwonders/game/effects/Effect.java +++ b/src/main/java/org/luxons/sevenwonders/game/effects/Effect.java @@ -1,6 +1,6 @@ package org.luxons.sevenwonders.game.effects; -import org.luxons.sevenwonders.game.boards.Board; +import org.luxons.sevenwonders.game.api.Table; /** * Represents an effect than can be applied to a player's board when playing a card or building his wonder. The effect @@ -9,7 +9,7 @@ import org.luxons.sevenwonders.game.boards.Board; */ public interface Effect { - void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard); + void apply(Table table, int playerIndex); - int computePoints(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard); + int computePoints(Table table, int playerIndex); } diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/EndGameEffect.java b/src/main/java/org/luxons/sevenwonders/game/effects/EndGameEffect.java index c2edc99b..1bae16a6 100644 --- a/src/main/java/org/luxons/sevenwonders/game/effects/EndGameEffect.java +++ b/src/main/java/org/luxons/sevenwonders/game/effects/EndGameEffect.java @@ -1,11 +1,11 @@ package org.luxons.sevenwonders.game.effects; -import org.luxons.sevenwonders.game.boards.Board; +import org.luxons.sevenwonders.game.api.Table; public abstract class EndGameEffect implements Effect { @Override - public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { + public void apply(Table table, int playerIndex) { // EndGameEffects don't do anything when applied to the board, they simply give more points in the end } } diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java b/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java index 8a319ab6..5d4e5817 100644 --- a/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java +++ b/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java @@ -4,7 +4,7 @@ import java.util.Objects; import org.luxons.sevenwonders.game.boards.Board; -public class GoldIncrease extends InstantEffect { +public class GoldIncrease extends InstantOwnBoardEffect { private final int amount; @@ -17,7 +17,7 @@ public class GoldIncrease extends InstantEffect { } @Override - public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { + public void apply(Board board) { 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 deleted file mode 100644 index e6e5aced..00000000 --- a/src/main/java/org/luxons/sevenwonders/game/effects/InstantEffect.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.luxons.sevenwonders.game.effects; - -import org.luxons.sevenwonders.game.boards.Board; - -public abstract class InstantEffect implements Effect { - - @Override - public int computePoints(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { - // InstantEffects are only important when applied to the board, they don't give extra points in the end - return 0; - } -} diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.java b/src/main/java/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.java new file mode 100644 index 00000000..79216c93 --- /dev/null +++ b/src/main/java/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.java @@ -0,0 +1,20 @@ +package org.luxons.sevenwonders.game.effects; + +import org.luxons.sevenwonders.game.api.Table; +import org.luxons.sevenwonders.game.boards.Board; + +public abstract class InstantOwnBoardEffect implements Effect { + + @Override + public void apply(Table table, int playerIndex) { + apply(table.getBoard(playerIndex)); + } + + public abstract void apply(Board board); + + @Override + public int computePoints(Table table, int playerIndex) { + // InstantEffects are only important when applied to the board, they don't give extra points in the end + return 0; + } +} 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 ad1497dd..8a0299ca 100644 --- a/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java +++ b/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java @@ -4,7 +4,7 @@ import java.util.Objects; import org.luxons.sevenwonders.game.boards.Board; -public class MilitaryReinforcements extends InstantEffect { +public class MilitaryReinforcements extends InstantOwnBoardEffect { private final int count; @@ -17,7 +17,7 @@ public class MilitaryReinforcements extends InstantEffect { } @Override - public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { + public void apply(Board board) { board.setNbWarSymbols(board.getNbWarSymbols() + count); } diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java b/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java index 22355a91..ff2a59c7 100644 --- a/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java +++ b/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java @@ -5,7 +5,7 @@ import java.util.Objects; import org.luxons.sevenwonders.game.boards.Board; import org.luxons.sevenwonders.game.resources.Production; -public class ProductionIncrease extends InstantEffect { +public class ProductionIncrease extends InstantOwnBoardEffect { private Production production = new Production(); @@ -17,7 +17,7 @@ public class ProductionIncrease extends InstantEffect { this.production = production; } - public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { + public void apply(Board board) { 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 index 76ab30b0..0d117cec 100644 --- a/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java +++ b/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java @@ -2,7 +2,7 @@ package org.luxons.sevenwonders.game.effects; import java.util.Objects; -import org.luxons.sevenwonders.game.boards.Board; +import org.luxons.sevenwonders.game.api.Table; public class RawPointsIncrease extends EndGameEffect { @@ -17,7 +17,7 @@ public class RawPointsIncrease extends EndGameEffect { } @Override - public int computePoints(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { + public int computePoints(Table table, int playerIndex) { return points; } diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/RelativeBoardPosition.java b/src/main/java/org/luxons/sevenwonders/game/effects/RelativeBoardPosition.java deleted file mode 100644 index 9b640539..00000000 --- a/src/main/java/org/luxons/sevenwonders/game/effects/RelativeBoardPosition.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.luxons.sevenwonders.game.effects; - -public enum RelativeBoardPosition { - LEFT, SELF, RIGHT -} diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/ScienceProgress.java b/src/main/java/org/luxons/sevenwonders/game/effects/ScienceProgress.java index 3eee7a9b..4e6764ee 100644 --- a/src/main/java/org/luxons/sevenwonders/game/effects/ScienceProgress.java +++ b/src/main/java/org/luxons/sevenwonders/game/effects/ScienceProgress.java @@ -3,7 +3,7 @@ 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 { +public class ScienceProgress extends InstantOwnBoardEffect { private Science science; @@ -16,7 +16,7 @@ public class ScienceProgress extends InstantEffect { } @Override - public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { + public void apply(Board board) { board.getScience().addAll(science); } } diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/SpecialActionTrigger.java b/src/main/java/org/luxons/sevenwonders/game/effects/SpecialActionTrigger.java index aef06741..22188a83 100644 --- a/src/main/java/org/luxons/sevenwonders/game/effects/SpecialActionTrigger.java +++ b/src/main/java/org/luxons/sevenwonders/game/effects/SpecialActionTrigger.java @@ -1,6 +1,6 @@ package org.luxons.sevenwonders.game.effects; -import org.luxons.sevenwonders.game.boards.Board; +import org.luxons.sevenwonders.game.api.Table; public class SpecialActionTrigger implements Effect { @@ -15,12 +15,12 @@ public class SpecialActionTrigger implements Effect { } @Override - public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { - + public void apply(Table table, int playerIndex) { + // TODO do something to activate the special action } @Override - public int computePoints(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { + public int computePoints(Table table, int playerIndex) { return 0; } } diff --git a/src/main/java/org/luxons/sevenwonders/game/wonders/WonderLevel.java b/src/main/java/org/luxons/sevenwonders/game/wonders/WonderLevel.java index 8f8d6a55..00b7d984 100644 --- a/src/main/java/org/luxons/sevenwonders/game/wonders/WonderLevel.java +++ b/src/main/java/org/luxons/sevenwonders/game/wonders/WonderLevel.java @@ -2,7 +2,7 @@ package org.luxons.sevenwonders.game.wonders; import java.util.List; -import org.luxons.sevenwonders.game.boards.Board; +import org.luxons.sevenwonders.game.api.Table; import org.luxons.sevenwonders.game.cards.Requirements; import org.luxons.sevenwonders.game.effects.Effect; @@ -28,7 +28,7 @@ public class WonderLevel { this.effects = effects; } - public void activate(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) { - effects.forEach(e -> e.apply(board, leftNeighbourBoard, rightNeighbourBoard)); + public void activate(Table table, int playerIndex) { + effects.forEach(e -> e.apply(table, playerIndex)); } } |