diff options
Diffstat (limited to 'src/main/java')
4 files changed, 33 insertions, 5 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/game/Game.java b/src/main/java/org/luxons/sevenwonders/game/Game.java index 9f1529a2..94bd039a 100644 --- a/src/main/java/org/luxons/sevenwonders/game/Game.java +++ b/src/main/java/org/luxons/sevenwonders/game/Game.java @@ -15,6 +15,7 @@ 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; @@ -79,6 +80,7 @@ public class Game { 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()); @@ -136,7 +138,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(getHandRotationOffset()); + hands.rotate(getHandRotationDirection()); } } @@ -208,9 +210,9 @@ public class Game { table.resolveMilitaryConflicts(currentAge); } - private int getHandRotationOffset() { + private HandRotationDirection getHandRotationDirection() { // clockwise at age 1, and alternating - return currentAge % 2 == 0 ? -1 : 1; + return currentAge % 2 == 0 ? HandRotationDirection.LEFT : HandRotationDirection.RIGHT; } private boolean endOfGameReached() { 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 14d4a9e8..1ff6f541 100644 --- a/src/main/java/org/luxons/sevenwonders/game/api/PlayerTurnInfo.java +++ b/src/main/java/org/luxons/sevenwonders/game/api/PlayerTurnInfo.java @@ -3,6 +3,7 @@ package org.luxons.sevenwonders.game.api; import java.util.List; import org.luxons.sevenwonders.game.Player; +import org.luxons.sevenwonders.game.cards.HandRotationDirection; public class PlayerTurnInfo { @@ -12,6 +13,8 @@ public class PlayerTurnInfo { private int currentAge; + private HandRotationDirection handRotationDirection; + private Action action; private List<HandCard> hand; @@ -39,6 +42,14 @@ public class PlayerTurnInfo { this.currentAge = currentAge; } + public HandRotationDirection getHandRotationDirection() { + return handRotationDirection; + } + + public void setHandRotationDirection(HandRotationDirection handRotationDirection) { + this.handRotationDirection = handRotationDirection; + } + public List<HandCard> getHand() { return hand; } diff --git a/src/main/java/org/luxons/sevenwonders/game/cards/HandRotationDirection.java b/src/main/java/org/luxons/sevenwonders/game/cards/HandRotationDirection.java new file mode 100644 index 00000000..2055ea4e --- /dev/null +++ b/src/main/java/org/luxons/sevenwonders/game/cards/HandRotationDirection.java @@ -0,0 +1,15 @@ +package org.luxons.sevenwonders.game.cards; + +public enum HandRotationDirection { + LEFT(-1), RIGHT(1); + + private final int indexOffset; + + HandRotationDirection(int i) { + this.indexOffset = i; + } + + public int getIndexOffset() { + return indexOffset; + } +} diff --git a/src/main/java/org/luxons/sevenwonders/game/cards/Hands.java b/src/main/java/org/luxons/sevenwonders/game/cards/Hands.java index 4d09c53b..4a8bc143 100644 --- a/src/main/java/org/luxons/sevenwonders/game/cards/Hands.java +++ b/src/main/java/org/luxons/sevenwonders/game/cards/Hands.java @@ -33,10 +33,10 @@ public class Hands { .collect(Collectors.toList()); } - public Hands rotate(int offset) { + public Hands rotate(HandRotationDirection direction) { Map<Integer, List<Card>> newHands = new HashMap<>(hands.size()); for (int i = 0; i < nbPlayers; i++) { - int newIndex = Math.floorMod(i + offset, nbPlayers); + int newIndex = Math.floorMod(i + direction.getIndexOffset(), nbPlayers); newHands.put(newIndex, hands.get(i)); } return new Hands(newHands, nbPlayers); |