Package org.scotlandyard.engine

Examples of org.scotlandyard.engine.Game


*/
public final class GameImpl extends SetOperations implements Game {

  public static Game getNewInstance(final String identifier,
      final User creator, final BoardMap boardMap) throws GameException {
    final Game game = new GameImpl(identifier, creator, boardMap);

    if (creator!=null && GameEngine.instance().getUser(creator.getEmail()) == null) {
      throw new GameException(
          "the user can not create a game before login is made");
    }
View Full Code Here


    final MockParametersMap map = new MockParametersMap();
   
    BoardMap boardMap = BoardMapImpl.getNewInstance("pnth");
    boardMap.prepareMap("web/maps/pnth.xml");
    User user = UserImpl.getNewInstance("Hussain", "hussain@game.com");
    Game game = GameImpl.getNewInstance("new game", user,boardMap);
   
    Detective detective = new Detective(user);
    game.addDetective(detective);
   
    game.setPlayerPosition(detective.getEmail(), boardMap.getCoordinates().iterator().next().getLabel());
   
    GamePlayersJsonContainer container = new GamePlayersJsonContainer(game);
   
    assertNull(
        "mr x has not been initialized",
        container.mrx
        );
   
    assertNotNull(
      "check if the container has been initialized correctly",
      container.detectives
      );
   
    assertEquals(
        "testing if the container contains one detective",
        1,
        container.detectives.size()
      );
   
    //System.out.println(container.toJson());
   
    map.put("gameId", game.getIdentifier());
   
    final String json = (String)new GamePlayers().processRequest(map, engine);
    final GamePlayersJsonContainer gpjc = new GamePlayersJsonContainer().fromJson(json);
    assertEquals(gpjc.detectives.size(),1);
  }
View Full Code Here

  }

  @Test  //TODO add description of what the test should do
  public final void testAddDetective() throws GameException{
    final User creator = new UserImpl("user1", "user1@game.com");
    Game game;
    try{
      game = GameImpl.getNewInstance("game1", creator, boardMap);
      Assert.assertTrue(false);
    }catch(GameException ex){
      Assert.assertTrue(true);
    }
    Assert.assertEquals(GameEngine.instance().getLobby().getAvailableGames().size(),0);
    GameEngine.instance().loginUser(creator);
    Assert.assertNotNull(GameEngine.instance().getUser(creator.getEmail()));
    Assert.assertEquals(GameEngine.instance().getUser(creator.getEmail()), creator);
    game = GameImpl.getNewInstance("game1", creator, boardMap);
    Assert.assertEquals(GameEngine.instance().getLobby().getAvailableGames().size(),1);
    Assert.assertEquals(game.getDetectives().size(),0);
    Assert.assertEquals(game.getPlayers().size(),0);
    final Player player = Detective.getNewInstance(game, creator);
    Assert.assertEquals(game.getDetectives().size(),1);
    Assert.assertEquals(game.getPlayers().size(),1);
    Assert.assertEquals(game.getPlayer(creator.getEmail()),player);
    Assert.assertEquals(game.getPlayer(player.getEmail()),player);
    Assert.assertEquals(creator.getEmail(),player.getEmail());
    Assert.assertEquals(creator.getName(),player.getName());
    Assert.assertNotNull(creator);
    Assert.assertNotNull(creator.getEmail());
    Assert.assertNull(game.getMrX());
    GameEngine.instance().logoutUser(creator.getEmail());
    try{
      game.removePlayer(creator.getEmail());
      Assert.assertFalse(true);
    }catch(GameException ex){
      Assert.assertTrue(true);
    }
    GameEngine.instance().getLobby().removeGame(game.getIdentifier());
    Assert.assertEquals(GameEngine.instance().getLobby().getAvailableGames().size(),0);
    GameEngine.instance().getBoardMaps().clear();

  }
View Full Code Here

    }

    String playerEmail = GameEngine.instance().getUsers().get(getSessionId()).getEmail();


    final Game game =  engine.getLobby().getGame(gameId);
    if(!game.removePlayer(playerEmail)){
      throw new GameException("Player could not be removed");
    }

  }
View Full Code Here

  @Test  //TODO add description of what the test should do
  public final void testGetBoardMap() throws GameException {
    Assert.assertEquals(GameEngine.instance().getLobby().getAvailableGames().size(), 0);
    Assert.assertEquals(GameEngine.instance().getBoardMaps().size(), 0);
    final Game game = GameImpl.getNewInstance(GAME, null, null);
    Assert.assertNull(game.getBoardMap());
    final BoardMap boardMap = BoardMapImpl.getNewInstance("pnth");
    game.setBoardMap(boardMap);
    Assert.assertNotNull(game.getBoardMap());
    Assert.assertSame(boardMap,game.getBoardMap());
    Assert.assertEquals(game.getBoardMap().getName(), boardMap.getName());
    game.setBoardMap(null);
    Assert.assertNull(game.getBoardMap());
    Assert.assertEquals(GameEngine.instance().getLobby().getAvailableGames().size(), 1);
    Assert.assertEquals(GameEngine.instance().getBoardMaps().size(), 1);
    GameEngine.instance().getBoardMaps().remove(boardMap.getName());
    GameEngine.instance().getLobby().removeGame(game.getIdentifier());
    Assert.assertEquals(GameEngine.instance().getLobby().getAvailableGames().size(), 0);
    Assert.assertEquals(GameEngine.instance().getBoardMaps().size(), 0);

  }
View Full Code Here

  }

  @Test  //TODO add description of what the test should do
  public final void testGetCreator() throws GameException{
    Assert.assertEquals(GameEngine.instance().getUsers().size(),0);
    Game game = GameImpl.getNewInstance("new", null, null);
    Assert.assertNull(game.getCreator());
    game = GameImpl.getNewInstance("another", UserImpl.getNewInstance("s", "s"), null);
    Assert.assertNotNull(game.getCreator());
    Assert.assertEquals(game.getCreator().getName(),"s");
    GameEngine.instance().getLobby().removeAllGames();
    Assert.assertEquals(GameEngine.instance().getLobby().getAvailableGames().size(),0);
    Assert.assertEquals(GameEngine.instance().getUsers().size(),1);
    GameEngine.instance().getUsers().clear();
    Assert.assertEquals(GameEngine.instance().getUsers().size(),0);
View Full Code Here

  @Test(expected=GameException.class)//TODO add description of what the test should do
  public final void testGetDetectives() throws GameException{
    Assert.assertEquals(GameEngine.instance().getLobby().getAvailableGames().size(), 0);
    Assert.assertEquals(GameEngine.instance().getUsers().size(), 0);
    final Game game = GameImpl.getNewInstance(GAME, null, null);
    Assert.assertEquals(GameEngine.instance().getLobby().getAvailableGames().size(), 1);
    Assert.assertEquals(game.getDetectives().size(), 0);
    final Player player = new Detective(UserImpl.getNewInstance("s", "s"));
    Assert.assertEquals(GameEngine.instance().getUsers().size(), 1);
    game.addDetective((Detective)player);
    Assert.assertEquals(game.getDetectives().size(), 1);
    Assert.assertEquals(game.getPlayers().size(), 1);
    Assert.assertEquals(game.getPlayer("s"), player);
    Assert.assertTrue(game.removePlayer(player));
    Assert.assertEquals(game.getPlayers().size(), 0);
    Assert.assertEquals(game.getDetectives().size(), 0);
    GameEngine.instance().getLobby().removeAllGames();
    GameEngine.instance().getUsers().clear();
    Assert.assertEquals(GameEngine.instance().getUsers().size(), 0);
    game.removePlayer(player)// should throw an exception
  }
View Full Code Here

    fail(OUTPUT); // TODO testGetGameStatus
  }

  @Test  //TODO add description of what the test should do
  public final void testGetIdentifier() throws GameException{
    final Game game = GameImpl.getNewInstance(GAME, null, null);
    Assert.assertEquals(game.getIdentifier(),GAME);
    GameEngine.instance().getLobby().removeAllGames();
    Assert.assertEquals(GameEngine.instance().getLobby().getAvailableGames().size(), 0);
  }
View Full Code Here

  @Test//TODO add description here
  public final void testMethods() throws GameException {
    boardMap = BoardMapImpl.getNewInstance(MAPNAME);
    game = GameImpl.getNewInstance("2", creator, boardMap);
    final Game game2 = GameImpl.getNewInstance("3", creator, boardMap);
    final Coordinate coor = new CoordinateImpl(boardMap, 1.1, 2.2);
    final Coordinate coor1 = new CoordinateImpl(boardMap, 1.6, 2.6);
    //Token token = new TokenImpl(detective, TransportationMethod.BUS);
    final Link route = new LinkImpl(boardMap, TransportationMethod.BUS, coor, coor1);
    //token.setNumberOfTickets(10);

    detective.setTokens(game, TransportationMethod.BUS, 10);
    final Token token = detective.getTokens(game).get(TransportationMethod.BUS);

    Assert.assertEquals(detective.getNumberOfTickets(game, TransportationMethod.BUS),10);

    detective.setPosition(game, coor);
    detective.useTokenToMove(game, token, route);

    Assert.assertEquals(detective.getNumberOfTickets(game, TransportationMethod.BUS),9);
    Assert.assertEquals(token.getNumberOfTokens(),9);


    detective.useTokenToMove(game, token, route);

    // aren't these conflicting?
//    2Token token = new TokenImpl(detective, TransportationMethod.BUS);
//    token.setNumberOfTickets(10);
//    detective.setTokens(game, TransportationMethod.BUS, 10);

    Assert.assertEquals(detective.toString(),"player1");

    Assert.assertEquals(detective.getNumberOfTickets(game, TransportationMethod.BUS),8);
    Assert.assertEquals(token.getNumberOfTokens(),8);
    Assert.assertTrue(detective.toString().equals("player1"));

    for(int x=8;x>0;x--){
      detective.useTokenToMove(game, token, route);
    }

    try{
      detective.useTokenToMove(game, token, route);
      Assert.assertTrue(false);
    }catch(GameException ex){
      Assert.assertTrue(true);
    }


    Assert.assertEquals(detective.compareTo(detective),0);


    game.addDetective((Detective) detective);
    game2.addDetective((Detective) detective);


    final Set<Game> currentgameslist = new HashSet<Game>();
    currentgameslist.add(game);
    currentgameslist.add(game2);
View Full Code Here

  @Test(expected=GameException.class)
  public final void testGetMrX() throws GameException{
    Assert.assertEquals(GameEngine.instance().getLobby().getAvailableGames().size(), 0);
    Assert.assertEquals(GameEngine.instance().getUsers().size(), 0);
    final Game game = GameImpl.getNewInstance(GAME, null, null);
    Assert.assertEquals(GameEngine.instance().getLobby().getAvailableGames().size(), 1);
    Assert.assertNull(game.getMrX());
    final Player player = new MrX(UserImpl.getNewInstance("s", "s"));
    Assert.assertEquals(GameEngine.instance().getUsers().size(), 1);
    game.setMrX((MrX)player);
    Assert.assertEquals(game.getDetectives().size(), 0);
    Assert.assertEquals(game.getPlayers().size(), 1);
    Assert.assertEquals(game.getPlayer("s"), player);
    Assert.assertTrue(game.removePlayer(player));
    Assert.assertEquals(game.getPlayers().size(), 0);
    GameEngine.instance().getLobby().removeAllGames();
    GameEngine.instance().getUsers().clear();
    Assert.assertEquals(GameEngine.instance().getUsers().size(), 0);

    game.removePlayer(player)// should throw an exception
  }
View Full Code Here

TOP

Related Classes of org.scotlandyard.engine.Game

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.