Package web.servlets

Source Code of web.servlets.CreateNewGame

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package web.servlets;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.scotlandyard.engine.BoardMap;
import org.scotlandyard.engine.GameException;
import org.scotlandyard.engine.User;
import org.scotlandyard.engine.json.JsonFactory;
import org.scotlandyard.impl.engine.GameEngine;

/**
* TODO add a description for this class
*
*
* @author Hussain Al-Mutawa
* @version 2.0
* @since Sun Sep 23, 2011
*/
public class CreateNewGame extends AbstractServlet implements IRequestProcessor  {
  //TODO add documentation about the action performed by getting the output of this servlet

  private /*transient*/ String gameId ;
  private /*transient*/ String mapId  ;
  private /*transient*/ User user;


  @Override
   public Object getOutput(
       final HttpServletRequest request,
        final GameEngine engine) throws Exception {


    user = engine.getUsers().get(getSessionId());

    if(user==null){
      throw new GameException("user can not be null");
    }

    //TODO remove this code to allow creation of
    // more than one game in the future
    if(engine.getLobby().getAvailableGames().size()>=1){
      throw new GameException("Can not create more than one game at the moment, will add this feature later");
    }

    String gameId = request.getParameter("gameId");
    String mapId  = request.getParameter("mapName");

    //out.println(gameId);

    if(gameId==null || "".equals(gameId)){
      throw new GameException("game identifier can not be null");
    }

    if(mapId==null || "".equals(mapId)){
      throw new GameException("map can not be null");
    }

    final BoardMap boardMap = engine.getNewBoardMap(mapId);

    //TODO change this to be dynamic map

    boardMap.prepareMap(getServletContext().getRealPath("/maps/pnth.xml"));


    engine.getNewGame(gameId, user, boardMap);

    return (JsonFactory.toJson("done"));

  }

  @Override
  public synchronized void validateRequest(
      final HttpServletRequest request,
      GameEngine engine) throws Exception {




  }

}
TOP

Related Classes of web.servlets.CreateNewGame

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.