From b30630782ee35cfed275217324f28285ad39d715 Mon Sep 17 00:00:00 2001 From: jbion Date: Sat, 7 Jul 2018 16:27:47 +0200 Subject: Kotlin mig: effects package --- .../game/effects/BonusPerBoardElement.java | 86 ---------------------- .../luxons/sevenwonders/game/effects/Discount.java | 44 ----------- .../luxons/sevenwonders/game/effects/Effect.java | 15 ---- .../sevenwonders/game/effects/EndGameEffect.java | 11 --- .../sevenwonders/game/effects/GoldIncrease.java | 40 ---------- .../game/effects/InstantOwnBoardEffect.java | 20 ----- .../game/effects/MilitaryReinforcements.java | 40 ---------- .../game/effects/ProductionIncrease.java | 54 -------------- .../game/effects/RawPointsIncrease.java | 40 ---------- .../sevenwonders/game/effects/ScienceProgress.java | 22 ------ .../sevenwonders/game/effects/SpecialAbility.java | 47 ------------ .../game/effects/SpecialAbilityActivation.java | 26 ------- 12 files changed, 445 deletions(-) delete mode 100644 game-engine/src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java delete mode 100644 game-engine/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java delete mode 100644 game-engine/src/main/java/org/luxons/sevenwonders/game/effects/Effect.java delete mode 100644 game-engine/src/main/java/org/luxons/sevenwonders/game/effects/EndGameEffect.java delete mode 100644 game-engine/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java delete mode 100644 game-engine/src/main/java/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.java delete mode 100644 game-engine/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java delete mode 100644 game-engine/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java delete mode 100644 game-engine/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java delete mode 100644 game-engine/src/main/java/org/luxons/sevenwonders/game/effects/ScienceProgress.java delete mode 100644 game-engine/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbility.java delete mode 100644 game-engine/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbilityActivation.java (limited to 'game-engine/src/main/java/org/luxons') diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java deleted file mode 100644 index e9f9fe5f..00000000 --- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java +++ /dev/null @@ -1,86 +0,0 @@ -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 { - - private List boards; - - private int gold; - - private int points; - - private BoardElementType type; - - // only relevant if type=CARD - private List colors; - - public List getBoards() { - return boards; - } - - public void setBoards(List boards) { - this.boards = boards; - } - - public int getGold() { - return gold; - } - - public void setGold(int gold) { - this.gold = gold; - } - - public int getPoints() { - return points; - } - - public void setPoints(int points) { - this.points = points; - } - - public BoardElementType getType() { - return type; - } - - public void setType(BoardElementType type) { - this.type = type; - } - - public List getColors() { - return colors; - } - - public void setColors(List colors) { - this.colors = colors; - } - - @Override - public void apply(Table table, int playerIndex) { - int goldGain = gold * computeNbOfMatchingElementsIn(table, playerIndex); - Board board = table.getBoard(playerIndex); - board.addGold(goldGain); - } - - @Override - public int computePoints(Table table, int playerIndex) { - return points * computeNbOfMatchingElementsIn(table, playerIndex); - } - - 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) { - return type.getElementCount(board, colors); - } -} diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java deleted file mode 100644 index 976ebf35..00000000 --- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.luxons.sevenwonders.game.effects; - -import java.util.ArrayList; -import java.util.List; - -import org.luxons.sevenwonders.game.boards.Board; -import org.luxons.sevenwonders.game.resources.Provider; -import org.luxons.sevenwonders.game.resources.ResourceType; -import org.luxons.sevenwonders.game.resources.TradingRules; - -public class Discount extends InstantOwnBoardEffect { - - private final List resourceTypes = new ArrayList<>(); - - private final List providers = new ArrayList<>(); - - private int discountedPrice = 1; - - public List getResourceTypes() { - return resourceTypes; - } - - public List getProviders() { - return providers; - } - - public int getDiscountedPrice() { - return discountedPrice; - } - - public void setDiscountedPrice(int discountedPrice) { - this.discountedPrice = discountedPrice; - } - - @Override - public void apply(Board board) { - TradingRules rules = board.getTradingRules(); - for (ResourceType type : resourceTypes) { - for (Provider provider : providers) { - rules.setCost(type, provider, discountedPrice); - } - } - } -} diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/Effect.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/Effect.java deleted file mode 100644 index 692eaea0..00000000 --- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/Effect.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.luxons.sevenwonders.game.effects; - -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 - * may affect (or depend on) the adjacent boards. It can have an instantaneous effect on the board, or be postponed to - * the end of game where point calculations take place. - */ -public interface Effect { - - void apply(Table table, int playerIndex); - - int computePoints(Table table, int playerIndex); -} diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/EndGameEffect.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/EndGameEffect.java deleted file mode 100644 index 1bae16a6..00000000 --- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/EndGameEffect.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.luxons.sevenwonders.game.effects; - -import org.luxons.sevenwonders.game.api.Table; - -public abstract class EndGameEffect implements Effect { - - @Override - 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/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java deleted file mode 100644 index 4c1215d4..00000000 --- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.luxons.sevenwonders.game.effects; - -import java.util.Objects; - -import org.luxons.sevenwonders.game.boards.Board; - -public class GoldIncrease extends InstantOwnBoardEffect { - - private final int amount; - - public GoldIncrease(int amount) { - this.amount = amount; - } - - public int getAmount() { - return amount; - } - - @Override - public void apply(Board board) { - board.addGold(amount); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - GoldIncrease that = (GoldIncrease) o; - return amount == that.amount; - } - - @Override - public int hashCode() { - return Objects.hash(amount); - } -} diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.java deleted file mode 100644 index 8f4340cf..00000000 --- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.java +++ /dev/null @@ -1,20 +0,0 @@ -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)); - } - - protected 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/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java deleted file mode 100644 index 7da112f5..00000000 --- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.luxons.sevenwonders.game.effects; - -import java.util.Objects; - -import org.luxons.sevenwonders.game.boards.Board; - -public class MilitaryReinforcements extends InstantOwnBoardEffect { - - private final int count; - - public MilitaryReinforcements(int count) { - this.count = count; - } - - public int getCount() { - return count; - } - - @Override - public void apply(Board board) { - board.getMilitary().addShields(count); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - MilitaryReinforcements that = (MilitaryReinforcements) o; - return count == that.count; - } - - @Override - public int hashCode() { - return Objects.hash(count); - } -} diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java deleted file mode 100644 index 514c65db..00000000 --- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.luxons.sevenwonders.game.effects; - -import java.util.Objects; - -import org.luxons.sevenwonders.game.boards.Board; -import org.luxons.sevenwonders.game.resources.Production; - -public class ProductionIncrease extends InstantOwnBoardEffect { - - private Production production = new Production(); - - private boolean sellable = true; - - public Production getProduction() { - return production; - } - - public void setProduction(Production production) { - this.production = production; - } - - public boolean isSellable() { - return sellable; - } - - public void setSellable(boolean sellable) { - this.sellable = sellable; - } - - @Override - public void apply(Board board) { - board.getProduction().addAll(production); - if (sellable) { - board.getPublicProduction().addAll(production); - } - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - ProductionIncrease that = (ProductionIncrease) o; - return Objects.equals(production, that.production); - } - - @Override - public int hashCode() { - return Objects.hash(production); - } -} diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java deleted file mode 100644 index 9a5d66ed..00000000 --- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.luxons.sevenwonders.game.effects; - -import java.util.Objects; - -import org.luxons.sevenwonders.game.api.Table; - -public class RawPointsIncrease extends EndGameEffect { - - private final int points; - - public RawPointsIncrease(int points) { - this.points = points; - } - - public int getPoints() { - return points; - } - - @Override - public int computePoints(Table table, int playerIndex) { - return points; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - RawPointsIncrease that = (RawPointsIncrease) o; - return points == that.points; - } - - @Override - public int hashCode() { - return Objects.hash(points); - } -} diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/ScienceProgress.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/ScienceProgress.java deleted file mode 100644 index 4e6764ee..00000000 --- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/ScienceProgress.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.luxons.sevenwonders.game.effects; - -import org.luxons.sevenwonders.game.boards.Board; -import org.luxons.sevenwonders.game.boards.Science; - -public class ScienceProgress extends InstantOwnBoardEffect { - - private Science science; - - public Science getScience() { - return science; - } - - public void setScience(Science science) { - this.science = science; - } - - @Override - public void apply(Board board) { - board.getScience().addAll(science); - } -} diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbility.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbility.java deleted file mode 100644 index cdf67f20..00000000 --- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbility.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.luxons.sevenwonders.game.effects; - -import org.luxons.sevenwonders.game.api.Table; -import org.luxons.sevenwonders.game.boards.Board; -import org.luxons.sevenwonders.game.cards.Card; - -public enum SpecialAbility { - - /** - * The player can play the last card of each age instead of discarding it. This card can be played by paying its - * cost, discarded to gain 3 coins or used in the construction of his or her Wonder. - */ - PLAY_LAST_CARD, - - /** - * Once per age, a player can construct a building from his or her hand for free. - */ - ONE_FREE_PER_AGE, - - /** - * The player can look at all cards discarded since the beginning of the game, pick one and build it for free. - */ - PLAY_DISCARDED, - - /** - * The player can, at the end of the game, "copy" a Guild of his or her choice (purple card), built by one of his or - * her two neighboring cities. - */ - COPY_GUILD { - @Override - public int computePoints(Table table, int playerIndex) { - Card copiedGuild = table.getBoard(playerIndex).getCopiedGuild(); - if (copiedGuild == null) { - throw new IllegalStateException("The copied Guild has not been chosen, cannot compute points"); - } - return copiedGuild.getEffects().stream().mapToInt(e -> e.computePoints(table, playerIndex)).sum(); - } - }; - - protected void apply(Board board) { - board.addSpecial(this); - } - - public int computePoints(Table table, int playerIndex) { - return 0; - } -} diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbilityActivation.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbilityActivation.java deleted file mode 100644 index a5953c2f..00000000 --- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbilityActivation.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.luxons.sevenwonders.game.effects; - -import org.luxons.sevenwonders.game.api.Table; - -public class SpecialAbilityActivation implements Effect { - - private final SpecialAbility specialAbility; - - public SpecialAbilityActivation(SpecialAbility specialAbility) { - this.specialAbility = specialAbility; - } - - public SpecialAbility getSpecialAbility() { - return specialAbility; - } - - @Override - public void apply(Table table, int playerIndex) { - specialAbility.apply(table.getBoard(playerIndex)); - } - - @Override - public int computePoints(Table table, int playerIndex) { - return specialAbility.computePoints(table, playerIndex); - } -} -- cgit