diff options
author | Joffrey BION <joffrey.bion@gmail.com> | 2017-04-16 19:39:57 +0200 |
---|---|---|
committer | Joffrey BION <joffrey.bion@gmail.com> | 2017-04-16 19:39:57 +0200 |
commit | d697ab4facb295e3555d884250d010ceb7b8fc74 (patch) | |
tree | 3222cd5751e431280bd6e0509f52563ac834af67 /backend/src/main/java/org | |
parent | Reword confusing exception message (diff) | |
download | seven-wonders-d697ab4facb295e3555d884250d010ceb7b8fc74.tar.gz seven-wonders-d697ab4facb295e3555d884250d010ceb7b8fc74.tar.bz2 seven-wonders-d697ab4facb295e3555d884250d010ceb7b8fc74.zip |
Simplify Requirements.isAffordedBy() signature
Diffstat (limited to 'backend/src/main/java/org')
3 files changed, 25 insertions, 5 deletions
diff --git a/backend/src/main/java/org/luxons/sevenwonders/game/cards/Requirements.java b/backend/src/main/java/org/luxons/sevenwonders/game/cards/Requirements.java index 942b64b7..d0444233 100644 --- a/backend/src/main/java/org/luxons/sevenwonders/game/cards/Requirements.java +++ b/backend/src/main/java/org/luxons/sevenwonders/game/cards/Requirements.java @@ -30,6 +30,14 @@ public class Requirements { this.resources = resources; } + /** + * Returns whether the given board can pay for these requirements on its own. + * + * @param board + * the board to check + * + * @return true if the given board fulfills these requirements without any transaction with its neighbours + */ boolean isAffordedBy(Board board) { return hasRequiredGold(board) && producesRequiredResources(board); } @@ -44,11 +52,20 @@ public class Requirements { } Resources leftToPay = resources.minus(board.getProduction().getFixedResources()); // TODO take into account resources buyable from neighbours - return true; + return false; } - public boolean isAffordedBy(Table table, int playerIndex, List<BoughtResources> boughtResources) { - Board board = table.getBoard(playerIndex); + /** + * Returns whether the given player can pay for these requirements, if he buys the specified resources. + * + * @param board + * the board to check + * @param boughtResources + * the resources the player intends to buy + * + * @return true if the given board fulfills these requirements + */ + public boolean isAffordedBy(Board board, List<BoughtResources> boughtResources) { if (!hasRequiredGold(board)) { return false; } diff --git a/backend/src/main/java/org/luxons/sevenwonders/game/moves/PlayCardMove.java b/backend/src/main/java/org/luxons/sevenwonders/game/moves/PlayCardMove.java index affebc4a..07022564 100644 --- a/backend/src/main/java/org/luxons/sevenwonders/game/moves/PlayCardMove.java +++ b/backend/src/main/java/org/luxons/sevenwonders/game/moves/PlayCardMove.java @@ -19,7 +19,8 @@ public class PlayCardMove extends CardFromHandMove { if (!super.isValid(table, playerHand)) { return false; } - return getCard().getRequirements().isAffordedBy(table, getPlayerIndex(), getBoughtResources()); + Board board = table.getBoard(getPlayerIndex()); + return getCard().getRequirements().isAffordedBy(board, getBoughtResources()); } @Override diff --git a/backend/src/main/java/org/luxons/sevenwonders/game/wonders/WonderStage.java b/backend/src/main/java/org/luxons/sevenwonders/game/wonders/WonderStage.java index fc3fc573..af93d909 100644 --- a/backend/src/main/java/org/luxons/sevenwonders/game/wonders/WonderStage.java +++ b/backend/src/main/java/org/luxons/sevenwonders/game/wonders/WonderStage.java @@ -3,6 +3,7 @@ package org.luxons.sevenwonders.game.wonders; import java.util.List; import org.luxons.sevenwonders.game.api.Table; +import org.luxons.sevenwonders.game.boards.Board; import org.luxons.sevenwonders.game.cards.CardBack; import org.luxons.sevenwonders.game.cards.Requirements; import org.luxons.sevenwonders.game.effects.Effect; @@ -37,7 +38,8 @@ public class WonderStage { } public boolean isBuildable(Table table, int playerIndex, List<BoughtResources> boughtResources) { - return requirements.isAffordedBy(table, playerIndex, boughtResources); + Board board = table.getBoard(playerIndex); + return requirements.isAffordedBy(board, boughtResources); } void build(CardBack cardBack) { |