Package scotlandyard.servlets.games

Source Code of scotlandyard.servlets.games.get_turn_number_json

package scotlandyard.servlets.games;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import scotlandyard.engine.impl.Engine;
import scotlandyard.engine.spec.IGame;

/**
* gets the number of the current turn as json, this servlet
* can be used to know if the other player has
* made a move or not in order to update the map
* @author Hussain Al-Mutawa
* @version 3.0
*/
public class get_turn_number_json extends HttpServlet {

  private static final long serialVersionUID = -3213082817453747984L;
  private String game_id;
  public get_turn_number_json() {
    super();
  }
 
  public get_turn_number_json(String gameId) {
    super();
    this.game_id = gameId;
  }  
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    final PrintWriter out = response.getWriter();
    try{
                    response.setHeader("Content-Type", "text/plain");
          if(request.getParameter("selected_game")!=null){
            game_id  = request.getParameter("selected_game");
          }
          if(game_id==null || "".equals(game_id)){throw new Exception("Game id is missing");}

          final IGame game = Engine.instance().games.get(game_id);
          if(game==null){throw new Exception("GAME is unknow");}
         
          out.print("{\"msg\" :  "+ game.getCurrentTurn() +"}");
         
    }catch(Exception e){
      out.print("{\"msg\" : \"EXCEPTION : "+(e.getMessage()+"").replace("\"", "'")+"\", \"className\" : \""+getClass().getName()+"\"}");
    }
  }

}
TOP

Related Classes of scotlandyard.servlets.games.get_turn_number_json

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.