Package web.servlets

Source Code of web.servlets.AvailableGames

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

import java.util.ArrayList;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.scotlandyard.engine.Game;
import org.scotlandyard.engine.GameException;
import org.scotlandyard.engine.json.GamesJsonContainer;
import org.scotlandyard.impl.engine.GameEngine;

/**
* This servlet returns
* a list of the games that are available
* in the lobby by the name of the game only
*
* @author Hussain Al-Mutawa
* @version 2.0
* @since Sun Sep 23, 2011
*/
public class AvailableGames extends AbstractServlet  implements IRequestProcessor{

  /**
   * gets list of games in a form of GamesJsonContainer
   */
  @Override
   public Object getOutput(
         final HttpServletRequest request,
        final GameEngine engine) throws GameException {

    final GamesJsonContainer gjc = new GamesJsonContainer();
    gjc.games=new ArrayList<String>();
    for(Game game:GameEngine.instance().getLobby().getAvailableGames()){
      gjc.games.add(game.getIdentifier());
    }

    return (gjc.toJson());
    }

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

  }


}
TOP

Related Classes of web.servlets.AvailableGames

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.