From d36414b05f1cc051652a8baad16c4d6e4c69bab2 Mon Sep 17 00:00:00 2001 From: Joffrey BION Date: Mon, 8 May 2017 09:55:41 +0200 Subject: Rename "prepare card" to "prepare move" Some moves may not be related to preparing a card from the hand. For instance, picking a neighbouring Guild Card to copy is not what I would call "preparing a card". --- .../sevenwonders/actions/PrepareCardAction.java | 25 ---------------------- .../sevenwonders/actions/PrepareMoveAction.java | 25 ++++++++++++++++++++++ .../sevenwonders/controllers/GameController.java | 9 ++++---- .../java/org/luxons/sevenwonders/game/Game.java | 4 ++-- .../org/luxons/sevenwonders/game/GameTest.java | 2 +- 5 files changed, 33 insertions(+), 32 deletions(-) delete mode 100644 backend/src/main/java/org/luxons/sevenwonders/actions/PrepareCardAction.java create mode 100644 backend/src/main/java/org/luxons/sevenwonders/actions/PrepareMoveAction.java (limited to 'backend') diff --git a/backend/src/main/java/org/luxons/sevenwonders/actions/PrepareCardAction.java b/backend/src/main/java/org/luxons/sevenwonders/actions/PrepareCardAction.java deleted file mode 100644 index 629e5806..00000000 --- a/backend/src/main/java/org/luxons/sevenwonders/actions/PrepareCardAction.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.luxons.sevenwonders.actions; - -import javax.validation.constraints.NotNull; - -import org.jsondoc.core.annotation.ApiObject; -import org.jsondoc.core.annotation.ApiObjectField; -import org.luxons.sevenwonders.game.api.PlayerMove; - -@ApiObject(name = "Prepare Card Action", - description = "The action to prepare a card during a game.", - group = "Actions") -public class PrepareCardAction { - - @ApiObjectField - @NotNull - private PlayerMove move; - - public PlayerMove getMove() { - return move; - } - - public void setMove(PlayerMove move) { - this.move = move; - } -} diff --git a/backend/src/main/java/org/luxons/sevenwonders/actions/PrepareMoveAction.java b/backend/src/main/java/org/luxons/sevenwonders/actions/PrepareMoveAction.java new file mode 100644 index 00000000..02899eab --- /dev/null +++ b/backend/src/main/java/org/luxons/sevenwonders/actions/PrepareMoveAction.java @@ -0,0 +1,25 @@ +package org.luxons.sevenwonders.actions; + +import javax.validation.constraints.NotNull; + +import org.jsondoc.core.annotation.ApiObject; +import org.jsondoc.core.annotation.ApiObjectField; +import org.luxons.sevenwonders.game.api.PlayerMove; + +@ApiObject(name = "Prepare Move Action", + description = "The action to prepare the next move during a game.", + group = "Actions") +public class PrepareMoveAction { + + @ApiObjectField + @NotNull + private PlayerMove move; + + public PlayerMove getMove() { + return move; + } + + public void setMove(PlayerMove move) { + this.move = move; + } +} diff --git a/backend/src/main/java/org/luxons/sevenwonders/controllers/GameController.java b/backend/src/main/java/org/luxons/sevenwonders/controllers/GameController.java index 0ec631f6..8680b00e 100644 --- a/backend/src/main/java/org/luxons/sevenwonders/controllers/GameController.java +++ b/backend/src/main/java/org/luxons/sevenwonders/controllers/GameController.java @@ -4,7 +4,7 @@ import java.security.Principal; import org.jsondoc.core.annotation.Api; import org.jsondoc.core.annotation.ApiMethod; -import org.luxons.sevenwonders.actions.PrepareCardAction; +import org.luxons.sevenwonders.actions.PrepareMoveAction; import org.luxons.sevenwonders.game.Game; import org.luxons.sevenwonders.game.api.PlayerTurnInfo; import org.luxons.sevenwonders.game.cards.CardBack; @@ -36,12 +36,13 @@ public class GameController { this.playerRepository = playerRepository; } - @ApiMethod(description = "Prepares the user's card") + @ApiMethod(description = "Prepares the user's next move. When all players have prepared their moves, all moves " + + "are executed.") @MessageMapping("/game/{gameId}/prepare") - public void prepareCard(@DestinationVariable long gameId, PrepareCardAction action, Principal principal) { + public void prepareMove(@DestinationVariable long gameId, PrepareMoveAction action, Principal principal) { Player player = playerRepository.find(principal.getName()); Game game = player.getGame(); - CardBack preparedCardBack = game.prepareCard(player.getIndex(), action.getMove()); + CardBack preparedCardBack = game.prepareMove(player.getIndex(), action.getMove()); PreparedCard preparedCard = new PreparedCard(player, preparedCardBack); logger.info("Game '{}': player {} prepared move {}", gameId, principal.getName(), action.getMove()); diff --git a/backend/src/main/java/org/luxons/sevenwonders/game/Game.java b/backend/src/main/java/org/luxons/sevenwonders/game/Game.java index 4f71d6e6..62cbab88 100644 --- a/backend/src/main/java/org/luxons/sevenwonders/game/Game.java +++ b/backend/src/main/java/org/luxons/sevenwonders/game/Game.java @@ -99,7 +99,7 @@ public class Game { } } - public CardBack prepareCard(int playerIndex, PlayerMove playerMove) throws InvalidMoveException { + public CardBack prepareMove(int playerIndex, PlayerMove playerMove) throws InvalidMoveException { Card card = decks.getCard(playerMove.getCardName()); Move move = playerMove.getType().resolve(playerIndex, card, playerMove); validate(move); @@ -135,8 +135,8 @@ public class Game { } private void rotateHandsIfRelevant() { + // we don't rotate hands if some player can play his last card (with the special ability) if (!hands.maxOneCardRemains()) { - // we don't rotate hands if some player can play his last card (with the special ability) hands.rotate(table.getHandRotationDirection()); } } diff --git a/backend/src/test/java/org/luxons/sevenwonders/game/GameTest.java b/backend/src/test/java/org/luxons/sevenwonders/game/GameTest.java index a7d10394..98247bb2 100644 --- a/backend/src/test/java/org/luxons/sevenwonders/game/GameTest.java +++ b/backend/src/test/java/org/luxons/sevenwonders/game/GameTest.java @@ -30,7 +30,7 @@ public class GameTest { assertEquals(1, turnInfo.getCurrentAge()); assertEquals(7, turnInfo.getHand().size()); PlayerMove move = getFirstAvailableMove(turnInfo); - game.prepareCard(turnInfo.getPlayerIndex(), move); + game.prepareMove(turnInfo.getPlayerIndex(), move); } } -- cgit