src/main/java/com/webcheckers/ui/GetGameRoute.java
/**
   * Render the WebCheckers Game route.
   *
   * @param request  the HTTP request
   * @param response the HTTP response
   * @return the rendered HTML for the Game page
   */
Render the WebCheckers Game route.
@param request  the HTTP request
@param response the HTTP response
@return the rendered HTML for the Game page
Render the WebCheckers Game route . @param request the HTTP request @param response the HTTP response @return the rendered HTML for the Game page
@Override
  public Object handle(Request request, Response response) throws InterruptedException{
    LOG.finer("GetGameRoute is invoked.");
    final Session httpSession = request.session();
    Map<String, Object> vm = new HashMap<>();
    Player player = httpSession.attribute(SessionAttributes.PLAYER);
    Game game = Application.gameCenter.getGameByPlayer(httpSession.attribute(SessionAttributes.PLAYER));
    Gson gson = new Gson();
    if (game != null) {
      vm.put("title", "Game page!");
      vm.put("currentUser", player);
      vm.put("redPlayer", game.getRedPlayer());
      vm.put("whitePlayer", game.getWhitePlayer());
      vm.put("viewMode", Game.ViewMode.PLAY);
      vm.put("board", game.getBoardView());
      vm.put("activeColor", game.getActiveColor());
      final Map<String, Object> modeOptions = new HashMap<>(2);
      modeOptions.put("isGameOver", true);
      if (game.getIsResigned() == httpSession.attribute(SessionAttributes.PLAYER)){
        modeOptions.put("gameOverMessage", "You resigned. BOO.");
        game.gameOver();
        vm.put("modeOptionsAsJSON", gson.toJson(modeOptions));
        return templateEngine.render(new ModelAndView(vm, "game.ftl"));
      } else if (game.getIsResigned() != null){
        modeOptions.put("gameOverMessage", "Other Player resigned. You Win.");
        game.gameOver();
        vm.put("modeOptionsAsJSON", gson.toJson(modeOptions));
        Application.gameCenter.endGame(game);
        return templateEngine.render(new ModelAndView(vm, "game.ftl"));
      }
      if (game.isGameOver()){
        if (player.equals(game.getWinner())){
          modeOptions.put("gameOverMessage", "you win");
        }
        vm.put("modeOptionsAsJSON", gson.toJson(modeOptions));
        return templateEngine.render(new ModelAndView(vm, "game.ftl"));
      }
      else{
        vm.put("message", WELCOME_MSG);
        return templateEngine.render(new ModelAndView(vm, "game.ftl"));
      }
    }
    else{
      response.redirect("/");
      return null;
    }
  }
@ Override public Object handle ( Request request , Response response ) throws InterruptedException { LOG . finer ( "GetGameRoute is invoked." ) ; final Session httpSession = request . session ( ) ; Map < String , Object > vm = new HashMap < > ( ) ; Player player = httpSession . attribute ( SessionAttributes . PLAYER ) ; Game game = Application . gameCenter . getGameByPlayer ( httpSession . attribute ( SessionAttributes . PLAYER ) ) ; Gson gson = new Gson ( ) ; if ( game != null ) { vm . put ( "title" , "Game page!" ) ; vm . put ( "currentUser" , player ) ; vm . put ( "redPlayer" , game . getRedPlayer ( ) ) ; vm . put ( "whitePlayer" , game . getWhitePlayer ( ) ) ; vm . put ( "viewMode" , Game . ViewMode . PLAY ) ; vm . put ( "board" , game . getBoardView ( ) ) ; vm . put ( "activeColor" , game . getActiveColor ( ) ) ; final Map < String , Object > modeOptions = new HashMap < > ( 2 ) ; modeOptions . put ( "isGameOver" , true ) ; if ( game . getIsResigned ( ) == httpSession . attribute ( SessionAttributes . PLAYER ) ) { modeOptions . put ( "gameOverMessage" , "You resigned. BOO." ) ; game . gameOver ( ) ; vm . put ( "modeOptionsAsJSON" , gson . toJson ( modeOptions ) ) ; return templateEngine . render ( new ModelAndView ( vm , "game.ftl" ) ) ; } else if ( game . getIsResigned ( ) != null ) { modeOptions . put ( "gameOverMessage" , "Other Player resigned. You Win." ) ; game . gameOver ( ) ; vm . put ( "modeOptionsAsJSON" , gson . toJson ( modeOptions ) ) ; Application . gameCenter . endGame ( game ) ; return templateEngine . render ( new ModelAndView ( vm , "game.ftl" ) ) ; } if ( game . isGameOver ( ) ) { if ( player . equals ( game . getWinner ( ) ) ) { modeOptions . put ( "gameOverMessage" , "you win" ) ; } vm . put ( "modeOptionsAsJSON" , gson . toJson ( modeOptions ) ) ; return templateEngine . render ( new ModelAndView ( vm , "game.ftl" ) ) ; } else { vm . put ( "message" , WELCOME_MSG ) ; return templateEngine . render ( new ModelAndView ( vm , "game.ftl" ) ) ; } } else { response . redirect ( "/" ) ; return null ; } }
Render the WebCheckers Game route.
Render the WebCheckers Game route .