summaryrefslogtreecommitdiff
path: root/src/main/java/org/luxons
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2017-01-14 03:45:24 +0100
committerJoffrey BION <joffrey.bion@gmail.com>2017-01-14 03:45:24 +0100
commit687aebaaed106897d169f50110f3d42ace285542 (patch)
treef6a8a482994a4149173a2e918eb5f91423783b10 /src/main/java/org/luxons
parentAdd actual points computation from copied guild (diff)
downloadseven-wonders-687aebaaed106897d169f50110f3d42ace285542.tar.gz
seven-wonders-687aebaaed106897d169f50110f3d42ace285542.tar.bz2
seven-wonders-687aebaaed106897d169f50110f3d42ace285542.zip
Add support for '1 free per age' special ability
Diffstat (limited to 'src/main/java/org/luxons')
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/Game.java20
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/api/Table.java19
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/boards/Board.java12
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/cards/HandRotationDirection.java5
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/moves/MoveType.java6
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/moves/PlayFreeCardMove.java39
6 files changed, 84 insertions, 17 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/game/Game.java b/src/main/java/org/luxons/sevenwonders/game/Game.java
index 94bd039a..bc9c3b17 100644
--- a/src/main/java/org/luxons/sevenwonders/game/Game.java
+++ b/src/main/java/org/luxons/sevenwonders/game/Game.java
@@ -15,7 +15,6 @@ import org.luxons.sevenwonders.game.api.Table;
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.HandRotationDirection;
import org.luxons.sevenwonders.game.cards.Hands;
import org.luxons.sevenwonders.game.effects.SpecialAbility;
import org.luxons.sevenwonders.game.moves.Move;
@@ -41,8 +40,6 @@ public class Game {
private Hands hands;
- private int currentAge = 0;
-
public Game(long id, Settings settings, List<Player> players, List<Board> boards, Decks decks) {
this.id = id;
this.settings = settings;
@@ -67,8 +64,8 @@ public class Game {
}
private void startNewAge() {
- currentAge++;
- hands = decks.deal(currentAge, table.getNbPlayers());
+ table.increaseCurrentAge();
+ hands = decks.deal(table.getCurrentAge(), table.getNbPlayers());
}
public List<PlayerTurnInfo> getTurnInfo() {
@@ -79,8 +76,6 @@ public class Game {
PlayerTurnInfo pti = new PlayerTurnInfo(player, table);
List<HandCard> hand = hands.createHand(table, player.getIndex());
pti.setHand(hand);
- pti.setCurrentAge(currentAge);
- pti.setHandRotationDirection(getHandRotationDirection());
Action action = determineAction(hand, table.getBoard(player.getIndex()));
pti.setAction(action);
pti.setMessage(action.getMessage());
@@ -138,7 +133,7 @@ public class Game {
}
} else if (!hands.maxOneCardRemains()) {
// we don't rotate hands if some player can play his last card (with the special ability)
- hands.rotate(getHandRotationDirection());
+ hands.rotate(table.getHandRotationDirection());
}
}
@@ -207,16 +202,11 @@ public class Game {
}
private void executeEndOfAgeEvents() {
- table.resolveMilitaryConflicts(currentAge);
- }
-
- private HandRotationDirection getHandRotationDirection() {
- // clockwise at age 1, and alternating
- return currentAge % 2 == 0 ? HandRotationDirection.LEFT : HandRotationDirection.RIGHT;
+ table.resolveMilitaryConflicts();
}
private boolean endOfGameReached() {
- return endOfAgeReached() && currentAge == LAST_AGE;
+ return endOfAgeReached() && table.getCurrentAge() == LAST_AGE;
}
public ScoreBoard computeScore() {
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 a87ea6ae..8b831527 100644
--- a/src/main/java/org/luxons/sevenwonders/game/api/Table.java
+++ b/src/main/java/org/luxons/sevenwonders/game/api/Table.java
@@ -4,6 +4,7 @@ import java.util.List;
import org.luxons.sevenwonders.game.boards.Board;
import org.luxons.sevenwonders.game.boards.RelativeBoardPosition;
+import org.luxons.sevenwonders.game.cards.HandRotationDirection;
import org.luxons.sevenwonders.game.moves.Move;
/**
@@ -16,6 +17,8 @@ public class Table {
private final List<Board> boards;
+ private int currentAge = 0;
+
private List<Move> lastPlayedMoves;
public Table(List<Board> boards) {
@@ -47,11 +50,23 @@ public class Table {
this.lastPlayedMoves = lastPlayedMoves;
}
- public void resolveMilitaryConflicts(int age) {
+ public int getCurrentAge() {
+ return currentAge;
+ }
+
+ public void increaseCurrentAge() {
+ this.currentAge++;
+ }
+
+ public HandRotationDirection getHandRotationDirection() {
+ return HandRotationDirection.forAge(currentAge);
+ }
+
+ public void resolveMilitaryConflicts() {
for (int i = 0; i < nbPlayers; i++) {
Board board1 = getBoard(i);
Board board2 = getBoard((i + 1) % nbPlayers);
- resolveConflict(board1, board2, age);
+ resolveConflict(board1, board2, currentAge);
}
}
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 31bb6c9f..ab557d38 100644
--- a/src/main/java/org/luxons/sevenwonders/game/boards/Board.java
+++ b/src/main/java/org/luxons/sevenwonders/game/boards/Board.java
@@ -2,7 +2,9 @@ package org.luxons.sevenwonders.game.boards;
import java.util.ArrayList;
import java.util.EnumSet;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.luxons.sevenwonders.game.Player;
@@ -35,6 +37,8 @@ public class Board {
private final Set<SpecialAbility> specialAbilities = EnumSet.noneOf(SpecialAbility.class);
+ private Map<Integer, Boolean> consumedFreeCards = new HashMap<>();
+
private Card copiedGuild;
private int gold;
@@ -118,6 +122,14 @@ public class Board {
return specialAbilities.contains(specialAbility);
}
+ public boolean canPlayFreeCard(int age) {
+ return hasSpecial(SpecialAbility.ONE_FREE_PER_AGE) && !consumedFreeCards.getOrDefault(age, false);
+ }
+
+ public void consumeFreeCard(int age) {
+ consumedFreeCards.put(age, true);
+ }
+
public void setCopiedGuild(Card copiedGuild) {
if (copiedGuild.getColor() != Color.PURPLE) {
throw new IllegalArgumentException("The given card '" + copiedGuild + "' is not a Guild card");
diff --git a/src/main/java/org/luxons/sevenwonders/game/cards/HandRotationDirection.java b/src/main/java/org/luxons/sevenwonders/game/cards/HandRotationDirection.java
index 2055ea4e..4d33a8db 100644
--- a/src/main/java/org/luxons/sevenwonders/game/cards/HandRotationDirection.java
+++ b/src/main/java/org/luxons/sevenwonders/game/cards/HandRotationDirection.java
@@ -12,4 +12,9 @@ public enum HandRotationDirection {
public int getIndexOffset() {
return indexOffset;
}
+
+ public static HandRotationDirection forAge(int age) {
+ // clockwise at age 1, and alternating
+ return age % 2 == 0 ? HandRotationDirection.LEFT : HandRotationDirection.RIGHT;
+ }
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/moves/MoveType.java b/src/main/java/org/luxons/sevenwonders/game/moves/MoveType.java
index 4887c6f1..bf64344d 100644
--- a/src/main/java/org/luxons/sevenwonders/game/moves/MoveType.java
+++ b/src/main/java/org/luxons/sevenwonders/game/moves/MoveType.java
@@ -10,6 +10,12 @@ public enum MoveType {
return new PlayCardMove(playerIndex, card, move);
}
},
+ PLAY_FREE {
+ @Override
+ public Move resolve(int playerIndex, Card card, PlayerMove move) {
+ return new PlayFreeCardMove(playerIndex, card, move);
+ }
+ },
UPGRADE_WONDER {
@Override
public Move resolve(int playerIndex, Card card, PlayerMove move) {
diff --git a/src/main/java/org/luxons/sevenwonders/game/moves/PlayFreeCardMove.java b/src/main/java/org/luxons/sevenwonders/game/moves/PlayFreeCardMove.java
new file mode 100644
index 00000000..fb28b09c
--- /dev/null
+++ b/src/main/java/org/luxons/sevenwonders/game/moves/PlayFreeCardMove.java
@@ -0,0 +1,39 @@
+package org.luxons.sevenwonders.game.moves;
+
+import java.util.List;
+
+import org.luxons.sevenwonders.game.Settings;
+import org.luxons.sevenwonders.game.api.PlayerMove;
+import org.luxons.sevenwonders.game.api.Table;
+import org.luxons.sevenwonders.game.boards.Board;
+import org.luxons.sevenwonders.game.cards.Card;
+
+public class PlayFreeCardMove extends CardFromHandMove {
+
+ PlayFreeCardMove(int playerIndex, Card card, PlayerMove move) {
+ super(playerIndex, card, move);
+ }
+
+ @Override
+ public boolean isValid(Table table, List<Card> playerHand) {
+ if (!super.isValid(table, playerHand)) {
+ return false;
+ }
+ Board board = table.getBoard(getPlayerIndex());
+ return board.canPlayFreeCard(table.getCurrentAge());
+ }
+
+ @Override
+ public void place(Table table, List<Card> discardedCards, Settings settings) {
+ Board board = table.getBoard(getPlayerIndex());
+ board.addCard(getCard());
+ }
+
+ @Override
+ public void activate(Table table, List<Card> discardedCards, Settings settings) {
+ // only apply effects, without paying the cost
+ getCard().getEffects().forEach(e -> e.apply(table, getPlayerIndex()));
+ Board board = table.getBoard(getPlayerIndex());
+ board.consumeFreeCard(table.getCurrentAge());
+ }
+}
bgstack15