src/main/java/com/webcheckers/ui/PostSpectateCheckTurnRoute.java
/**
     * Handles Spectate checking turn request. Either returns
     * @param request http request
     * @param response http response
     * @return jsonmessage Object
     */
Handles Spectate checking turn request. Either returns
@param request http request
@param response http response
@return jsonmessage Object
Handles Spectate checking turn request . Either returns @param request http request @param response http response @return jsonmessage Object
@Override
    public Object handle(Request request, Response response) {
        final Session httpSession = request.session();
        Gson gson = new Gson();
        Message message;
        Game game = Application.gameCenter.getGameByPlayer(httpSession.attribute("Playing"));
        if (game != null) {
            Piece.PieceColor activeColor = httpSession.attribute("activeColor");
            Piece.PieceColor gameColor = game.getActiveColor();
            if (game.isGameOver()){
                message = Message.info("true");
                String move_json = gson.toJson(message);
                response.body(move_json);
                return move_json;
            }
            if (activeColor == gameColor) {
                message = Message.info("false");
                String move_json = gson.toJson(message);
                response.body(move_json);
                return move_json;
            } else {
                message = Message.info("true");
                String move_json = gson.toJson(message);
                response.body(move_json);
                return move_json;
            }
        }
        message = Message.info("true");
        String move_json = gson.toJson(message);
        response.body(move_json);
        return move_json;
    }
@ Override public Object handle ( Request request , Response response ) { final Session httpSession = request . session ( ) ; Gson gson = new Gson ( ) ; Message message ; Game game = Application . gameCenter . getGameByPlayer ( httpSession . attribute ( "Playing" ) ) ; if ( game != null ) { Piece . PieceColor activeColor = httpSession . attribute ( "activeColor" ) ; Piece . PieceColor gameColor = game . getActiveColor ( ) ; if ( game . isGameOver ( ) ) { message = Message . info ( "true" ) ; String move_json = gson . toJson ( message ) ; response . body ( move_json ) ; return move_json ; } if ( activeColor == gameColor ) { message = Message . info ( "false" ) ; String move_json = gson . toJson ( message ) ; response . body ( move_json ) ; return move_json ; } else { message = Message . info ( "true" ) ; String move_json = gson . toJson ( message ) ; response . body ( move_json ) ; return move_json ; } } message = Message . info ( "true" ) ; String move_json = gson . toJson ( message ) ; response . body ( move_json ) ; return move_json ; }
Handles Spectate checking turn request.
Handles Spectate checking turn request .