summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/Game.java43
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/api/Action.java19
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/api/PlayerTurnInfo.java10
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/boards/Board.java13
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/data/definitions/EffectsDefinition.java8
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbility.java (renamed from src/main/java/org/luxons/sevenwonders/game/effects/SpecialAction.java)10
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbilityTrigger.java (renamed from src/main/java/org/luxons/sevenwonders/game/effects/SpecialActionTrigger.java)12
7 files changed, 97 insertions, 18 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/game/Game.java b/src/main/java/org/luxons/sevenwonders/game/Game.java
index 71fea9e5..81e9266a 100644
--- a/src/main/java/org/luxons/sevenwonders/game/Game.java
+++ b/src/main/java/org/luxons/sevenwonders/game/Game.java
@@ -6,6 +6,8 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
+import org.luxons.sevenwonders.game.api.Action;
+import org.luxons.sevenwonders.game.api.HandCard;
import org.luxons.sevenwonders.game.api.PlayerMove;
import org.luxons.sevenwonders.game.api.PlayerTurnInfo;
import org.luxons.sevenwonders.game.api.PreparedCard;
@@ -14,6 +16,7 @@ import org.luxons.sevenwonders.game.boards.Board;
import org.luxons.sevenwonders.game.cards.Card;
import org.luxons.sevenwonders.game.cards.Decks;
import org.luxons.sevenwonders.game.cards.Hands;
+import org.luxons.sevenwonders.game.effects.SpecialAbility;
import org.luxons.sevenwonders.game.moves.Move;
public class Game {
@@ -70,11 +73,27 @@ public class Game {
private PlayerTurnInfo createPlayerTurnInfo(Player player) {
PlayerTurnInfo pti = new PlayerTurnInfo(player, table);
- pti.setHand(hands.createHand(table, player.getIndex()));
+ List<HandCard> hand = hands.createHand(table, player.getIndex());
+ pti.setHand(hand);
pti.setCurrentAge(currentAge);
+ Action action = determineAction(hand, table.getBoard(player.getIndex()));
+ pti.setAction(action);
+ pti.setMessage(action.getMessage());
return pti;
}
+ private Action determineAction(List<HandCard> hand, Board board) {
+ if (hand.isEmpty()) {
+ return Action.WAIT;
+ } else if (hand.size() == 1 && board.hasSpecial(SpecialAbility.PLAY_LAST_CARD)) {
+ return Action.PLAY_LAST;
+ } else if (hand.size() == 2 && board.hasSpecial(SpecialAbility.PLAY_LAST_CARD)) {
+ return Action.PLAY_2;
+ } else {
+ return Action.PLAY;
+ }
+ }
+
public PreparedCard prepareCard(String userName, PlayerMove playerMove) throws InvalidMoveException {
Player player = getPlayer(userName);
Card card = decks.getCard(playerMove.getCardName());
@@ -116,7 +135,8 @@ public class Game {
if (endOfAgeReached()) {
executeEndOfAgeEvents();
startNewAge();
- } else {
+ } else if (!hands.maxOneCardRemains()) {
+ // we don't rotate hands if some player can play his last card (with the special ability)
hands.rotate(getHandRotationOffset());
}
}
@@ -129,8 +149,8 @@ public class Game {
placePreparedCards(playedMoves);
// same goes for the discarded cards during the last turn, which should be available for special actions
- if (lastTurnOfAge()) {
- discardedCards.addAll(hands.gatherAndClear());
+ if (hands.maxOneCardRemains()) {
+ discardLastCardsOfHands();
}
activatePlayedCards(playedMoves);
@@ -158,8 +178,19 @@ public class Game {
});
}
- private boolean lastTurnOfAge() {
- return hands.maxOneCardRemains();
+ private void discardLastCardsOfHands() {
+ for (Player p : players) {
+ Board board = table.getBoard(p.getIndex());
+ if (!board.hasSpecial(SpecialAbility.PLAY_LAST_CARD)) {
+ discardHand(p.getIndex());
+ }
+ }
+ }
+
+ private void discardHand(int playerIndex) {
+ List<Card> hand = hands.get(playerIndex);
+ discardedCards.addAll(hand);
+ hand.clear();
}
private void removeFromHand(int playerIndex, Card card) {
diff --git a/src/main/java/org/luxons/sevenwonders/game/api/Action.java b/src/main/java/org/luxons/sevenwonders/game/api/Action.java
new file mode 100644
index 00000000..786ab668
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/api/Action.java
@@ -0,0 +1,19 @@
+package org.luxons.sevenwonders.game.api;
+
+public enum Action {
+ PLAY("Pick the card you want to play."),
+ PLAY_2("Pick the card you want to play first. Note that you have the ability to play these 2 last cards. "
+ + "You will choose how to play the last one during your next turn."),
+ PLAY_LAST("You have the special ability to play your last card. Choose how you want to play it."),
+ WAIT("Please wait for other players to perform extra actions.");
+
+ private final String message;
+
+ Action(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+}
diff --git a/src/main/java/org/luxons/sevenwonders/game/api/PlayerTurnInfo.java b/src/main/java/org/luxons/sevenwonders/game/api/PlayerTurnInfo.java
index 1566b862..14d4a9e8 100644
--- a/src/main/java/org/luxons/sevenwonders/game/api/PlayerTurnInfo.java
+++ b/src/main/java/org/luxons/sevenwonders/game/api/PlayerTurnInfo.java
@@ -12,6 +12,8 @@ public class PlayerTurnInfo {
private int currentAge;
+ private Action action;
+
private List<HandCard> hand;
private String message;
@@ -45,6 +47,14 @@ public class PlayerTurnInfo {
this.hand = hand;
}
+ public Action getAction() {
+ return action;
+ }
+
+ public void setAction(Action action) {
+ this.action = action;
+ }
+
public String getMessage() {
return message;
}
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 d6cfd8e1..b8893ca3 100644
--- a/src/main/java/org/luxons/sevenwonders/game/boards/Board.java
+++ b/src/main/java/org/luxons/sevenwonders/game/boards/Board.java
@@ -1,12 +1,15 @@
package org.luxons.sevenwonders.game.boards;
import java.util.ArrayList;
+import java.util.EnumSet;
import java.util.List;
+import java.util.Set;
import org.luxons.sevenwonders.game.Player;
import org.luxons.sevenwonders.game.Settings;
import org.luxons.sevenwonders.game.cards.Card;
import org.luxons.sevenwonders.game.cards.Color;
+import org.luxons.sevenwonders.game.effects.SpecialAbility;
import org.luxons.sevenwonders.game.resources.Production;
import org.luxons.sevenwonders.game.resources.TradingRules;
import org.luxons.sevenwonders.game.wonders.Wonder;
@@ -27,6 +30,8 @@ public class Board {
private final Military military;
+ private final Set<SpecialAbility> specialAbilities = EnumSet.noneOf(SpecialAbility.class);
+
private int gold;
public Board(Wonder wonder, Player player, Settings settings) {
@@ -97,6 +102,14 @@ public class Board {
return military;
}
+ public void addSpecial(SpecialAbility specialAbility) {
+ specialAbilities.add(specialAbility);
+ }
+
+ public boolean hasSpecial(SpecialAbility specialAbility) {
+ return specialAbilities.contains(specialAbility);
+ }
+
static class InsufficientFundsException extends RuntimeException {
InsufficientFundsException(int current, int required) {
super(String.format("Current balance is %d gold, but %d are required", current, required));
diff --git a/src/main/java/org/luxons/sevenwonders/game/data/definitions/EffectsDefinition.java b/src/main/java/org/luxons/sevenwonders/game/data/definitions/EffectsDefinition.java
index 836fecc6..2df07db4 100644
--- a/src/main/java/org/luxons/sevenwonders/game/data/definitions/EffectsDefinition.java
+++ b/src/main/java/org/luxons/sevenwonders/game/data/definitions/EffectsDefinition.java
@@ -12,8 +12,8 @@ import org.luxons.sevenwonders.game.effects.MilitaryReinforcements;
import org.luxons.sevenwonders.game.effects.ProductionIncrease;
import org.luxons.sevenwonders.game.effects.RawPointsIncrease;
import org.luxons.sevenwonders.game.effects.ScienceProgress;
-import org.luxons.sevenwonders.game.effects.SpecialAction;
-import org.luxons.sevenwonders.game.effects.SpecialActionTrigger;
+import org.luxons.sevenwonders.game.effects.SpecialAbility;
+import org.luxons.sevenwonders.game.effects.SpecialAbilityTrigger;
@SuppressWarnings("unused") // the fields are injected by Gson
public class EffectsDefinition implements Definition<List<Effect>> {
@@ -32,7 +32,7 @@ public class EffectsDefinition implements Definition<List<Effect>> {
private RawPointsIncrease points;
- private SpecialAction action;
+ private SpecialAbility action;
@Override
public List<Effect> create(Settings settings) {
@@ -59,7 +59,7 @@ public class EffectsDefinition implements Definition<List<Effect>> {
effects.add(points);
}
if (action != null) {
- effects.add(new SpecialActionTrigger(action));
+ effects.add(new SpecialAbilityTrigger(action));
}
return effects;
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAction.java b/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbility.java
index 83cc1956..f5e0a0e7 100644
--- a/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAction.java
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbility.java
@@ -1,6 +1,8 @@
package org.luxons.sevenwonders.game.effects;
-public enum SpecialAction {
+import org.luxons.sevenwonders.game.boards.Board;
+
+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.
@@ -10,7 +12,7 @@ public enum SpecialAction {
/**
* Once per age, a player can construct a building from his or her hand for free.
*/
- ONE_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.
@@ -22,4 +24,8 @@ public enum SpecialAction {
* her two neighboring cities.
*/
COPY_GUILD;
+
+ protected void apply(Board board) {
+ board.addSpecial(this);
+ }
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/SpecialActionTrigger.java b/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbilityTrigger.java
index 22188a83..e68e71e9 100644
--- a/src/main/java/org/luxons/sevenwonders/game/effects/SpecialActionTrigger.java
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbilityTrigger.java
@@ -2,16 +2,16 @@ package org.luxons.sevenwonders.game.effects;
import org.luxons.sevenwonders.game.api.Table;
-public class SpecialActionTrigger implements Effect {
+public class SpecialAbilityTrigger implements Effect {
- private final SpecialAction specialAction;
+ private final SpecialAbility specialAbility;
- public SpecialActionTrigger(SpecialAction specialAction) {
- this.specialAction = specialAction;
+ public SpecialAbilityTrigger(SpecialAbility specialAbility) {
+ this.specialAbility = specialAbility;
}
- public SpecialAction getSpecialAction() {
- return specialAction;
+ public SpecialAbility getSpecialAbility() {
+ return specialAbility;
}
@Override
bgstack15