From 465b0fe1d5ccbfc661f7aef1da43b53d0468857e Mon Sep 17 00:00:00 2001 From: jbion Date: Sun, 18 Dec 2016 19:48:35 +0100 Subject: Add start game action --- .../sevenwonders/actions/StartGameAction.java | 19 ++++++++++ .../sevenwonders/controllers/LobbyController.java | 42 ++++++++++++++++++---- .../java/org/luxons/sevenwonders/game/Game.java | 35 +++++++++++++++--- .../java/org/luxons/sevenwonders/game/Lobby.java | 7 ++++ .../java/org/luxons/sevenwonders/game/Player.java | 15 +++----- .../sevenwonders/game/api/PlayerTurnInfo.java | 10 ++++++ 6 files changed, 106 insertions(+), 22 deletions(-) create mode 100644 src/main/java/org/luxons/sevenwonders/actions/StartGameAction.java (limited to 'src/main/java/org') diff --git a/src/main/java/org/luxons/sevenwonders/actions/StartGameAction.java b/src/main/java/org/luxons/sevenwonders/actions/StartGameAction.java new file mode 100644 index 00000000..632b80ef --- /dev/null +++ b/src/main/java/org/luxons/sevenwonders/actions/StartGameAction.java @@ -0,0 +1,19 @@ +package org.luxons.sevenwonders.actions; + +import javax.validation.constraints.NotNull; + +import org.luxons.sevenwonders.game.Settings; + +public class StartGameAction { + + @NotNull + private Settings settings; + + public Settings getSettings() { + return settings; + } + + public void setSettings(Settings settings) { + this.settings = settings; + } +} diff --git a/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java b/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java index ea262c4e..37041f32 100644 --- a/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java +++ b/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java @@ -2,12 +2,15 @@ package org.luxons.sevenwonders.controllers; import java.security.Principal; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.luxons.sevenwonders.actions.JoinOrCreateGameAction; +import org.luxons.sevenwonders.actions.StartGameAction; import org.luxons.sevenwonders.game.Game; import org.luxons.sevenwonders.game.Lobby; import org.luxons.sevenwonders.game.Player; +import org.luxons.sevenwonders.game.api.PlayerTurnInfo; import org.luxons.sevenwonders.game.data.GameDefinitionLoader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,6 +19,7 @@ import org.springframework.messaging.handler.annotation.MessageExceptionHandler; import org.springframework.messaging.handler.annotation.MessageMapping; import org.springframework.messaging.handler.annotation.SendTo; import org.springframework.messaging.simp.SimpMessageHeaderAccessor; +import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.messaging.simp.annotation.SendToUser; import org.springframework.stereotype.Controller; import org.springframework.validation.annotation.Validated; @@ -30,6 +34,8 @@ public class LobbyController { private final GameDefinitionLoader gameDefinitionLoader; + private final SimpMessagingTemplate template; + private long lastGameId = 0; private Map lobbies = new HashMap<>(); @@ -37,8 +43,9 @@ public class LobbyController { private Map games = new HashMap<>(); @Autowired - public LobbyController(GameDefinitionLoader gameDefinitionLoader) { + public LobbyController(GameDefinitionLoader gameDefinitionLoader, SimpMessagingTemplate template) { this.gameDefinitionLoader = gameDefinitionLoader; + this.template = template; } @MessageExceptionHandler @@ -93,10 +100,35 @@ public class LobbyController { return lobby; } + @MessageMapping("/start-game") + public void startGame(SimpMessageHeaderAccessor headerAccessor, @Validated StartGameAction action, + Principal principal) { + Lobby lobby = (Lobby)headerAccessor.getSessionAttributes().get(ATTR_LOBBY); + if (lobby == null) { + logger.error("User {} is not in a game", principal.getName()); + template.convertAndSendToUser(principal.getName(), "/queue/errors", "No game to start"); + return; + } + + if (!lobby.isOwner(principal.getName())) { + logger.error("User {} is not the owner of the game '{}'", principal.getName(), lobby.getName()); + template.convertAndSendToUser(principal.getName(), "/queue/errors", "Only the owner can start the game"); + return; + } + + Game game = lobby.startGame(action.getSettings()); + logger.info("Game {} successfully started", game.getId()); + + List playerTurnInfos = game.startTurn(); + for (PlayerTurnInfo playerTurnInfo : playerTurnInfos) { + Player player = playerTurnInfo.getTable().getPlayers().get(playerTurnInfo.getPlayerIndex()); + String userName = player.getUserName(); + template.convertAndSendToUser(userName, "/queue/game/turn", playerTurnInfo); + } + } + private Player createPlayer(String name, Principal principal) { - Player player = new Player(name); - player.setUserName(principal.getName()); - return player; + return new Player(name, principal.getName()); } private Lobby createGame(String name, Player owner) { @@ -114,7 +146,6 @@ public class LobbyController { public GameNotFoundException(String name) { super(name); } - } private class GameNameAlreadyUsedException extends UniqueIdAlreadyUsedException { @@ -123,5 +154,4 @@ public class LobbyController { super(name); } } - } diff --git a/src/main/java/org/luxons/sevenwonders/game/Game.java b/src/main/java/org/luxons/sevenwonders/game/Game.java index f4dac7ef..2a2fab27 100644 --- a/src/main/java/org/luxons/sevenwonders/game/Game.java +++ b/src/main/java/org/luxons/sevenwonders/game/Game.java @@ -37,22 +37,23 @@ public class Game { this.discardedCards = new ArrayList<>(); this.hands = new HashMap<>(); this.preparedMoves = new HashMap<>(); + startNewAge(); } public long getId() { return id; } - public int startNewAge() { + private void startNewAge() { currentAge++; hands = decks.deal(currentAge, table.getNbPlayers()); - return currentAge; } public List startTurn() { return hands.entrySet() .stream() .map(e -> table.createPlayerTurnInfo(e.getKey(), e.getValue())) + .peek(ptu -> ptu.setCurrentAge(currentAge)) .collect(Collectors.toList()); } @@ -69,10 +70,27 @@ public class Game { return preparedMoves.size() == table.getPlayers().size(); } - public void playTurn() { + public List playTurn() { + List playedMoves = mapToList(preparedMoves); + // cards need to be all placed first as some effects depend on just-played cards placePreparedCards(); playPreparedCards(); + preparedMoves.clear(); + + return playedMoves; + } + + private static List mapToList(Map movesPerPlayer) { + List moves = new ArrayList<>(movesPerPlayer.size()); + for (int p = 0; p < movesPerPlayer.size(); p++) { + Move move = movesPerPlayer.get(p); + if (move == null) { + throw new MissingPreparedMoveException(p); + } + moves.add(move); + } + return moves; } private void placePreparedCards() { @@ -85,10 +103,10 @@ public class Game { // TODO pre-upgrade the level of wonder without effect break; case DISCARD: + discardedCards.add(decks.getCard(move.getCardName())); break; } }); - } private void playPreparedCards() { @@ -108,6 +126,13 @@ public class Game { } - public class InvalidMoveException extends RuntimeException { + private static class MissingPreparedMoveException extends RuntimeException { + + public MissingPreparedMoveException(int playerIndex) { + super("Player " + playerIndex + " is not ready to play"); + } + } + + private static class InvalidMoveException extends RuntimeException { } } diff --git a/src/main/java/org/luxons/sevenwonders/game/Lobby.java b/src/main/java/org/luxons/sevenwonders/game/Lobby.java index 7256936c..7fdffef5 100644 --- a/src/main/java/org/luxons/sevenwonders/game/Lobby.java +++ b/src/main/java/org/luxons/sevenwonders/game/Lobby.java @@ -12,6 +12,8 @@ public class Lobby { private final String name; + private final Player owner; + private final List players; private final GameDefinition gameDefinition; @@ -21,6 +23,7 @@ public class Lobby { public Lobby(long id, String name, Player owner, GameDefinition gameDefinition) { this.id = id; this.name = name; + this.owner = owner; this.gameDefinition = gameDefinition; this.players = new ArrayList<>(gameDefinition.getMinPlayers()); players.add(owner); @@ -79,6 +82,10 @@ public class Lobby { return "Lobby{" + "id=" + id + ", name='" + name + '\'' + ", state=" + state + '}'; } + public boolean isOwner(String userName) { + return owner.getUserName().equals(userName); + } + public class GameAlreadyStartedException extends IllegalStateException { } diff --git a/src/main/java/org/luxons/sevenwonders/game/Player.java b/src/main/java/org/luxons/sevenwonders/game/Player.java index fd2f254b..66ce566d 100644 --- a/src/main/java/org/luxons/sevenwonders/game/Player.java +++ b/src/main/java/org/luxons/sevenwonders/game/Player.java @@ -2,30 +2,23 @@ package org.luxons.sevenwonders.game; public class Player { - private String displayName; + private final String displayName; - private String userName; + private final String userName; - public Player(String displayName) { + public Player(String displayName, String userName) { this.displayName = displayName; + this.userName = userName; } public String getDisplayName() { return displayName; } - public void setDisplayName(String displayName) { - this.displayName = displayName; - } - public String getUserName() { return userName; } - public void setUserName(String userName) { - this.userName = userName; - } - @Override public String toString() { return "Player{" + "name='" + displayName + '\'' + ", userName='" + userName + '\'' + '}'; 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 ad9e6da9..b7090ff9 100644 --- a/src/main/java/org/luxons/sevenwonders/game/api/PlayerTurnInfo.java +++ b/src/main/java/org/luxons/sevenwonders/game/api/PlayerTurnInfo.java @@ -8,6 +8,8 @@ public class PlayerTurnInfo { private final Table table; + private int currentAge; + private List hand; private String message; @@ -25,6 +27,14 @@ public class PlayerTurnInfo { return table; } + public int getCurrentAge() { + return currentAge; + } + + public void setCurrentAge(int currentAge) { + this.currentAge = currentAge; + } + public List getHand() { return hand; } -- cgit From 04a1f919c227371426a11ed74e57613ec891dce6 Mon Sep 17 00:00:00 2001 From: jbion Date: Sun, 18 Dec 2016 23:21:50 +0100 Subject: Move session attribute keys to a single file to ensure unicity more easily --- .../luxons/sevenwonders/controllers/LobbyController.java | 16 ++++++++-------- .../luxons/sevenwonders/session/SessionAttributes.java | 8 ++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 src/main/java/org/luxons/sevenwonders/session/SessionAttributes.java (limited to 'src/main/java/org') diff --git a/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java b/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java index 37041f32..7567c330 100644 --- a/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java +++ b/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java @@ -7,11 +7,13 @@ import java.util.Map; import org.luxons.sevenwonders.actions.JoinOrCreateGameAction; import org.luxons.sevenwonders.actions.StartGameAction; +import org.luxons.sevenwonders.errors.UniqueIdAlreadyUsedException; import org.luxons.sevenwonders.game.Game; import org.luxons.sevenwonders.game.Lobby; import org.luxons.sevenwonders.game.Player; import org.luxons.sevenwonders.game.api.PlayerTurnInfo; import org.luxons.sevenwonders.game.data.GameDefinitionLoader; +import org.luxons.sevenwonders.session.SessionAttributes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -30,8 +32,6 @@ public class LobbyController { private static final Logger logger = LoggerFactory.getLogger(LobbyController.class); - public static final String ATTR_LOBBY = "lobby"; - private final GameDefinitionLoader gameDefinitionLoader; private final SimpMessagingTemplate template; @@ -59,7 +59,7 @@ public class LobbyController { @SendTo("/topic/games") public Lobby createGame(SimpMessageHeaderAccessor headerAccessor, @Validated JoinOrCreateGameAction action, Principal principal) { - Lobby lobby = (Lobby)headerAccessor.getSessionAttributes().get(ATTR_LOBBY); + Lobby lobby = (Lobby)headerAccessor.getSessionAttributes().get(SessionAttributes.ATTR_LOBBY); if (lobby != null) { logger.warn("Client already in game '{}', cannot create a new game", lobby.getName()); return lobby; @@ -68,7 +68,7 @@ public class LobbyController { Player player = createPlayer(action.getPlayerName(), principal); lobby = createGame(action.getGameName(), player); - headerAccessor.getSessionAttributes().put(ATTR_LOBBY, lobby); + headerAccessor.getSessionAttributes().put(SessionAttributes.ATTR_LOBBY, lobby); logger.info("Game '{}' (id={}) created by {} ({})", lobby.getName(), lobby.getId(), player.getDisplayName(), player.getUserName()); @@ -79,7 +79,7 @@ public class LobbyController { @SendToUser("/queue/join-game") public Lobby joinGame(SimpMessageHeaderAccessor headerAccessor, @Validated JoinOrCreateGameAction action, Principal principal) { - Lobby lobby = (Lobby)headerAccessor.getSessionAttributes().get(ATTR_LOBBY); + Lobby lobby = (Lobby)headerAccessor.getSessionAttributes().get(SessionAttributes.ATTR_LOBBY); if (lobby != null) { logger.warn("Client already in game '{}', cannot join a different game", lobby.getName()); return lobby; @@ -93,7 +93,7 @@ public class LobbyController { Player newPlayer = createPlayer(action.getPlayerName(), principal); lobby.addPlayer(newPlayer); - headerAccessor.getSessionAttributes().put(ATTR_LOBBY, lobby); + headerAccessor.getSessionAttributes().put(SessionAttributes.ATTR_LOBBY, lobby); logger.warn("Player {} joined game {}", action.getPlayerName(), action.getGameName()); @@ -103,9 +103,9 @@ public class LobbyController { @MessageMapping("/start-game") public void startGame(SimpMessageHeaderAccessor headerAccessor, @Validated StartGameAction action, Principal principal) { - Lobby lobby = (Lobby)headerAccessor.getSessionAttributes().get(ATTR_LOBBY); + Lobby lobby = (Lobby)headerAccessor.getSessionAttributes().get(SessionAttributes.ATTR_LOBBY); if (lobby == null) { - logger.error("User {} is not in a game", principal.getName()); + logger.error("User {} is not in a lobby", principal.getName()); template.convertAndSendToUser(principal.getName(), "/queue/errors", "No game to start"); return; } diff --git a/src/main/java/org/luxons/sevenwonders/session/SessionAttributes.java b/src/main/java/org/luxons/sevenwonders/session/SessionAttributes.java new file mode 100644 index 00000000..8c69d8c3 --- /dev/null +++ b/src/main/java/org/luxons/sevenwonders/session/SessionAttributes.java @@ -0,0 +1,8 @@ +package org.luxons.sevenwonders.session; + +public class SessionAttributes { + + public static final String ATTR_LOBBY = "lobby"; + + public static final String ATTR_GAME = "game"; +} -- cgit From 4a2d35912246a4cb22a06770aa3fe0e5e3e7fc78 Mon Sep 17 00:00:00 2001 From: jbion Date: Mon, 19 Dec 2016 01:51:38 +0100 Subject: Allow cross-origin for frontend server proxy --- src/main/java/org/luxons/sevenwonders/config/WebSocketConfig.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/luxons/sevenwonders/config/WebSocketConfig.java b/src/main/java/org/luxons/sevenwonders/config/WebSocketConfig.java index 81c90c9b..83629d6a 100644 --- a/src/main/java/org/luxons/sevenwonders/config/WebSocketConfig.java +++ b/src/main/java/org/luxons/sevenwonders/config/WebSocketConfig.java @@ -24,7 +24,10 @@ public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { @Override public void registerStompEndpoints(StompEndpointRegistry registry) { - registry.addEndpoint("/seven-wonders-websocket").setHandshakeHandler(handshakeHandler()).withSockJS(); + registry.addEndpoint("/seven-wonders-websocket") + .setHandshakeHandler(handshakeHandler()) + .setAllowedOrigins("http://localhost:3000") // to allow frontend server proxy requests in dev mode + .withSockJS(); } @Bean -- cgit From aa929f6b2615ea66dc96b3daf8c505fa3c2d7388 Mon Sep 17 00:00:00 2001 From: jbion Date: Mon, 19 Dec 2016 02:35:57 +0100 Subject: Improve error output --- .../sevenwonders/controllers/LobbyController.java | 12 +++-- .../controllers/UniqueIdAlreadyUsedException.java | 15 ------- .../luxons/sevenwonders/errors/ErrorFactory.java | 52 ++++++++++++++++++++++ .../org/luxons/sevenwonders/errors/ErrorType.java | 7 +++ .../org/luxons/sevenwonders/errors/UIError.java | 42 +++++++++++++++++ .../errors/UniqueIdAlreadyUsedException.java | 15 +++++++ .../sevenwonders/errors/UserInputException.java | 14 ++++++ .../java/org/luxons/sevenwonders/game/Lobby.java | 2 +- 8 files changed, 140 insertions(+), 19 deletions(-) delete mode 100644 src/main/java/org/luxons/sevenwonders/controllers/UniqueIdAlreadyUsedException.java create mode 100644 src/main/java/org/luxons/sevenwonders/errors/ErrorFactory.java create mode 100644 src/main/java/org/luxons/sevenwonders/errors/ErrorType.java create mode 100644 src/main/java/org/luxons/sevenwonders/errors/UIError.java create mode 100644 src/main/java/org/luxons/sevenwonders/errors/UniqueIdAlreadyUsedException.java create mode 100644 src/main/java/org/luxons/sevenwonders/errors/UserInputException.java (limited to 'src/main/java/org') diff --git a/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java b/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java index 7567c330..e15935d6 100644 --- a/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java +++ b/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java @@ -7,6 +7,8 @@ import java.util.Map; import org.luxons.sevenwonders.actions.JoinOrCreateGameAction; import org.luxons.sevenwonders.actions.StartGameAction; +import org.luxons.sevenwonders.errors.ErrorFactory; +import org.luxons.sevenwonders.errors.UIError; import org.luxons.sevenwonders.errors.UniqueIdAlreadyUsedException; import org.luxons.sevenwonders.game.Game; import org.luxons.sevenwonders.game.Lobby; @@ -36,6 +38,8 @@ public class LobbyController { private final SimpMessagingTemplate template; + private final ErrorFactory errorFactory; + private long lastGameId = 0; private Map lobbies = new HashMap<>(); @@ -43,16 +47,18 @@ public class LobbyController { private Map games = new HashMap<>(); @Autowired - public LobbyController(GameDefinitionLoader gameDefinitionLoader, SimpMessagingTemplate template) { + public LobbyController(GameDefinitionLoader gameDefinitionLoader, SimpMessagingTemplate template, + ErrorFactory errorFactory) { this.gameDefinitionLoader = gameDefinitionLoader; this.template = template; + this.errorFactory = errorFactory; } @MessageExceptionHandler @SendToUser("/queue/errors") - public String handleException(Throwable exception) { + public UIError handleException(Throwable exception) { logger.error("An error occured during message handling", exception); - return exception.getClass().getSimpleName() + ": " + exception.getMessage(); + return errorFactory.createError(exception); } @MessageMapping("/create-game") diff --git a/src/main/java/org/luxons/sevenwonders/controllers/UniqueIdAlreadyUsedException.java b/src/main/java/org/luxons/sevenwonders/controllers/UniqueIdAlreadyUsedException.java deleted file mode 100644 index 56c22655..00000000 --- a/src/main/java/org/luxons/sevenwonders/controllers/UniqueIdAlreadyUsedException.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.luxons.sevenwonders.controllers; - -public class UniqueIdAlreadyUsedException extends RuntimeException { - - private String id; - - public UniqueIdAlreadyUsedException(String id) { - super("'" + id + "'"); - this.id = id; - } - - public String getUsedId() { - return id; - } -} diff --git a/src/main/java/org/luxons/sevenwonders/errors/ErrorFactory.java b/src/main/java/org/luxons/sevenwonders/errors/ErrorFactory.java new file mode 100644 index 00000000..2d3dcd0b --- /dev/null +++ b/src/main/java/org/luxons/sevenwonders/errors/ErrorFactory.java @@ -0,0 +1,52 @@ +package org.luxons.sevenwonders.errors; + +import java.util.List; +import java.util.Locale; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.MessageSource; +import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException; +import org.springframework.stereotype.Component; +import org.springframework.validation.ObjectError; + +@Component +public class ErrorFactory { + + private static final String ERROR_CODE_VALIDATION = "VALIDATION_ERROR"; + + private static final String ERROR_MSG_VALIDATION = "Input invalid"; + + private final MessageSource messageSource; + + @Autowired + public ErrorFactory(MessageSource messageSource) { + this.messageSource = messageSource; + } + + public UIError createError(Throwable exception) { + if (exception instanceof UserInputException) { + return createUserError((UserInputException)exception); + } else if (exception instanceof MethodArgumentNotValidException) { + return createValidationError((MethodArgumentNotValidException)exception); + } else { + return createInternalError(exception); + } + } + + private UIError createUserError(UserInputException exception) { + String messageKey = exception.getMessageResourceKey(); + String message = messageSource.getMessage(messageKey, null, messageKey, Locale.US); + return new UIError(messageKey, message, ErrorType.USER); + } + + private UIError createInternalError(Throwable exception) { + return new UIError(exception.getClass().getSimpleName(), exception.getMessage(), ErrorType.INTERNAL); + } + + private UIError createValidationError(MethodArgumentNotValidException exception) { + List errors = exception.getBindingResult().getAllErrors(); + UIError uiError = new UIError(ERROR_CODE_VALIDATION, ERROR_MSG_VALIDATION, ErrorType.VALIDATION); + uiError.setValidationErrors(errors); + return uiError; + } +} diff --git a/src/main/java/org/luxons/sevenwonders/errors/ErrorType.java b/src/main/java/org/luxons/sevenwonders/errors/ErrorType.java new file mode 100644 index 00000000..71df185f --- /dev/null +++ b/src/main/java/org/luxons/sevenwonders/errors/ErrorType.java @@ -0,0 +1,7 @@ +package org.luxons.sevenwonders.errors; + +public enum ErrorType { + USER, + VALIDATION, + INTERNAL +} diff --git a/src/main/java/org/luxons/sevenwonders/errors/UIError.java b/src/main/java/org/luxons/sevenwonders/errors/UIError.java new file mode 100644 index 00000000..67802f22 --- /dev/null +++ b/src/main/java/org/luxons/sevenwonders/errors/UIError.java @@ -0,0 +1,42 @@ +package org.luxons.sevenwonders.errors; + +import java.util.List; + +import org.springframework.validation.ObjectError; + +public class UIError { + + private final String code; + + private final String message; + + private final ErrorType type; + + private List validationErrors; + + public UIError(String code, String message, ErrorType type) { + this.code = code; + this.message = message; + this.type = type; + } + + public String getCode() { + return code; + } + + public String getMessage() { + return message; + } + + public ErrorType getType() { + return type; + } + + public List getValidationErrors() { + return validationErrors; + } + + public void setValidationErrors(List validationErrors) { + this.validationErrors = validationErrors; + } +} diff --git a/src/main/java/org/luxons/sevenwonders/errors/UniqueIdAlreadyUsedException.java b/src/main/java/org/luxons/sevenwonders/errors/UniqueIdAlreadyUsedException.java new file mode 100644 index 00000000..b1b00453 --- /dev/null +++ b/src/main/java/org/luxons/sevenwonders/errors/UniqueIdAlreadyUsedException.java @@ -0,0 +1,15 @@ +package org.luxons.sevenwonders.errors; + +public class UniqueIdAlreadyUsedException extends RuntimeException { + + private String id; + + public UniqueIdAlreadyUsedException(String id) { + super("'" + id + "'"); + this.id = id; + } + + public String getUsedId() { + return id; + } +} diff --git a/src/main/java/org/luxons/sevenwonders/errors/UserInputException.java b/src/main/java/org/luxons/sevenwonders/errors/UserInputException.java new file mode 100644 index 00000000..11f7f8f2 --- /dev/null +++ b/src/main/java/org/luxons/sevenwonders/errors/UserInputException.java @@ -0,0 +1,14 @@ +package org.luxons.sevenwonders.errors; + +public class UserInputException extends RuntimeException { + + private final String messageResourceKey; + + public UserInputException(String messageResourceKey) { + this.messageResourceKey = messageResourceKey; + } + + public String getMessageResourceKey() { + return messageResourceKey; + } +} diff --git a/src/main/java/org/luxons/sevenwonders/game/Lobby.java b/src/main/java/org/luxons/sevenwonders/game/Lobby.java index 7fdffef5..16d4e8a3 100644 --- a/src/main/java/org/luxons/sevenwonders/game/Lobby.java +++ b/src/main/java/org/luxons/sevenwonders/game/Lobby.java @@ -3,7 +3,7 @@ package org.luxons.sevenwonders.game; import java.util.ArrayList; import java.util.List; -import org.luxons.sevenwonders.controllers.UniqueIdAlreadyUsedException; +import org.luxons.sevenwonders.errors.UniqueIdAlreadyUsedException; import org.luxons.sevenwonders.game.data.GameDefinition; public class Lobby { -- cgit