Package org.scotlandyard.impl.engine

Examples of org.scotlandyard.impl.engine.GameEngine


*/
public class ResetEngineTest {

  @Test  // TODO add test description
  public final void testGetOutput() throws Exception{
    final GameEngine engine=GameEngine.instance();
   
    assertEquals(
        "testing the number of maps before adding anything",
        0,
        engine.getBoardMaps().size()
        );
   
    assertEquals(
        "testing the number of games before adding anything",
        0,
        engine.getLobby().getAvailableGames().size()
        );
   
    assertEquals(
        "testing the number of users before adding anything",
        0,
        engine.getUsers().size()
        );
    GameImpl.getNewInstance("game1", null, null);
    GameImpl.getNewInstance("game2", null, null);
    UserImpl.getNewInstance("user", "email");
    BoardMapImpl.getNewInstance("map");

    assertEquals(
        "testing the number of maps after adding new values",
        1,
        engine.getBoardMaps().size()
        );
   
    assertEquals(
        "testing the number of games after adding new values",
        2,
        engine.getLobby().getAvailableGames().size()
        );
   
    assertEquals(
        "testing the number of users after adding new values",
        1,
        engine.getUsers().size()
        );
   
    String json = (String)new ResetGameEngine().processRequest(null, engine);
   
    assertEquals(
        "testing the output json object is not an exception",
        "The engine has been reset",
        JsonFactory.fromJson(json).message
        );
    assertEquals(
        "testing the number of maps after reseting the engine",
        0,
        engine.getBoardMaps().size()
        );
   
    assertEquals(
        "testing the number of games after reseting the engine",
        0,
        engine.getLobby().getAvailableGames().size()
        );
   
    assertEquals(
        "testing the number of users after reseting the engine",
        0,
        engine.getUsers().size()
        );
  }
View Full Code Here


*/
public class GamePlayersTest {

  @Test//TODO add description here
  public final void testProcessRequest() throws Exception{
    final GameEngine engine = GameEngine.instance();
    final MockParametersMap map = new MockParametersMap();
   
    BoardMap boardMap = BoardMapImpl.getNewInstance("pnth");
    boardMap.prepareMap("web/maps/pnth.xml");
    User user = UserImpl.getNewInstance("Hussain", "hussain@game.com");
View Full Code Here

        response.setHeader("Pragma","no-cache");
        response.setDateHeader ("Expires", -1);


        //try{
      final GameEngine engine = GameEngine.instance();//(GameEngine)this.getServletContext().getAttribute("GameEngine");
      if (engine == null) {
        throw new ServletException("Game Engine has not been initialized, you may refresh the page to get it done. Or come backe later");
      }
      this.sessionId=request.getSession().getId();
        try {
View Full Code Here

    fail(OUTPUT); // TODO testGetTurn
  }

  @Test  //TODO add description of what the test should do
  public final void testRemove() throws GameException{
    final GameEngine engine = GameEngine.instance();
    User user1,user2;
    user1 = new UserImpl("user1","user1");
    user2 = new UserImpl("user2","user2");
    Assert.assertEquals(engine.getUsers().size(), 0);
    engine.loginUser(user1);
    engine.loginUser(user2);


    Assert.assertEquals(engine.getLobby().getAvailableGames().size(), 0);

    final Game game = GameImpl.getNewInstance("game1", user1, boardMap);
    Assert.assertEquals(engine.getLobby().getAvailableGames().size(), 1);

    final Player player1 = new Detective(user1);
    final Player player2 = new MrX(user2);

    Assert.assertEquals(engine.getUsers().size(), 2);
    Assert.assertEquals(game.getDetectives().size(), 0);
    game.setMrX(player2);


    try{
      engine.startGame(game);
      Assert.assertFalse(true);
    }catch(Exception ex){
      Assert.assertTrue(true);
    }

    try{
      game.addDetective((Detective)player2);
      Assert.assertFalse(true);
    }catch(Exception ex){
      Assert.assertTrue(true);
    }

    game.addDetective((Detective)player1);

    Assert.assertNotNull(game.getPlayer(user1.getEmail()));
    Assert.assertNotNull(game.getPlayer(user2.getEmail()));

    Assert.assertEquals(game.getDetectives().size(), 1);
    Assert.assertEquals(game.getPlayers().size(),2);

    Assert.assertTrue(engine.logoutUser(user1.getEmail()));
    Assert.assertFalse(engine.logoutUser(user1.getEmail()));

    Assert.assertEquals(game.getPlayers().size(),1);

    try{
      engine.startGame(game);
      Assert.assertFalse(true);
    }catch(Exception ex){
      Assert.assertTrue(true);
    }

    engine.getUsers().put(user1.getEmail(), user1);

    try{
      game.setMrX(player1); // should not allow to override existing mrX
      Assert.assertFalse(true);
    }catch(Exception ex){
      Assert.assertTrue(true);
    }

    Assert.assertEquals(game.getDetectives().size(), 0);
    game.addDetective((Detective)player1);
    Assert.assertEquals(game.getDetectives().size(), 1);

    Assert.assertEquals(game.getPlayers().size(), 2);

    Assert.assertSame(game.getMrX(),player2);
    Assert.assertTrue(game.getDetectives().contains(player1));

    Assert.assertFalse(game.getDetectives().contains(player2));

    try{
      game.addDetective((Detective)player2); //should not allow player to be both mrx and detective in the same game
      Assert.assertFalse(true);
    }catch(Exception ex){
      Assert.assertTrue(true);
    }

    try{
      game.addDetective((Detective)player1); //should not allow player to be added as detective twice
      Assert.assertFalse(true);
    }catch(Exception ex){
      Assert.assertTrue(true);
    }

    Assert.assertEquals(game.getDetectives().size(),1);
    Assert.assertEquals(game.getPlayers().size(),2);


    engine.startGame(game);

    Assert.assertEquals(engine.startGame(game), "done");
    Assert.assertEquals(game.getGameStatus().toString(),GameStatus.STARTED.toString());

    Assert.assertTrue(game.removePlayer(user1.getEmail()));
    Assert.assertTrue(game.removePlayer(user2.getEmail()));
    try{
View Full Code Here

TOP

Related Classes of org.scotlandyard.impl.engine.GameEngine

Copyright © 2018 www.massapicom. 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.