* @param action - The Action object to be performed.
*/
public static void performAction(final Action action) {
final String actionType = action.getActionType();
final String value = action.getValue();
Game game = action.getGame();
final HttpSession session = action.getSession();
if ("startgame".equals(actionType)) {
game.setPlaying(true);
game.startGame();
}
if ("setmap".equals(actionType)) {
game = SessionListener.getSessionTracker().getGameTracker().createNewGame((String) session.getAttribute("email"));
game.setMap(new Map(value));
session.setAttribute("game", game);
}
if ("setmapname".equals(actionType)) {
game.getMap().setMapName(value);
}
if ("setgamecreator".equals(actionType)) {
game.setCreatorName(value);
game.tellLobby();
}
if ("joingame".equals(actionType)) {
game = SessionListener.getSessionTracker().getGameTracker().getGameMadeByCreator(value);
game.addUserToGame((String) session.getAttribute("email"));
session.setAttribute("game", game);
}
if("takeTurn".equals(actionType)) {
try {
game.playerTakesTurn(value);
} catch (ParserConfigurationException ex) {
System.err.print(ex);
} catch (SAXException ex) {
System.err.print(ex);
} catch (IOException ex) {
System.err.print(ex);
}
}
if ("startDoubleMove".equals(actionType)) {
game.startDoubleTurn();
}
if ("cancelDoubleMove".equals(actionType)) {
game.cancelDoubleTurn();
}
if("cannotMove".equals(actionType)) {
game.getPlayers().get(Integer.parseInt(value)).setCanMove(false);
}
if("checkGameEnd".equals(actionType)) {
game.checkPlayersLose();
}
if("leaveGame".equals(actionType)) {
if (game != null) {
for (Player player : game.getPlayers()) {
if (player.getPlayerEmail().equals(value)) {
player.leaveGame();
if (game.getWhosTurn() == game.getPlayers().indexOf(player)) {
game.determineWhosTurnItIsNext();
}
}
}
session.setAttribute("game", null);
if (!game.isFinished()) {
game.checkEnd();
}
}
}
}