Package org.scotlandyard.engine

Examples of org.scotlandyard.engine.User


   *
   * @param email
   * @return
   */
  public User getUser(final String email){
    User users = null;
    for(final User user : this.users.values()){
      if(user.getEmail().equals(email)){
        users = user;
      }
    }
View Full Code Here


     * @param email
     * @return
     * @throws GameException if the user email exists in the engine already
     */
    public static User getNewInstance(final String name,final String email) throws GameException{
      final User user = new UserImpl(name, email);
      GameEngine.instance().loginUser(user);
      return user;
    }
View Full Code Here

    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");
    Game game = GameImpl.getNewInstance("new game", user,boardMap);
   
    Detective detective = new Detective(user);
    game.addDetective(detective);
   
View Full Code Here

  private transient Coordinate position1;

  @Before//TODO add description here
  public void setUp() throws Exception {
    GameEngine.instance().clearRecords();
    final User user1=UserImpl.getNewInstance("hussain", "hussain.mutawa");
    final User user2=UserImpl.getNewInstance("ali", "ali.mutawa");
    final BoardMap boardMap = BoardMapImpl.getNewInstance("pnth");
    boardMap.prepareMap("web/maps/pnth.xml");
    game = GameImpl.getNewInstance("game1", user1, boardMap);
    mrx=MrX.getNewInstance(game, user1);
    detective=Detective.getNewInstance(game,user2);
View Full Code Here

    GameEngine.instance().getUsers().clear();
  }

  @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());
View Full Code Here

  }

  @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{
      game.removePlayer(user2.getEmail());
      Assert.assertFalse(true);
    }catch(GameException ex){
View Full Code Here

    Assert.assertEquals(GameEngine.instance().getLobby().getAvailableGames().size(),0);
  }

  @Test  //TODO add description of what the test should do
  public final void testSetMrX() throws GameException{
    final User creator = UserImpl.getNewInstance("c", "c");
    final Game game = GameImpl.getNewInstance("d", creator, null);
    Assert.assertNull(game.getMrX());
    final Player mrX = MrX.getNewInstance(game, creator);
    Assert.assertNotNull(game.getMrX());
    Assert.assertSame(game.getMrX(),mrX);
View Full Code Here

  private transient final PlayerPosition playerPosition1,playerPosition2;

  //TODO add description here
  public PlayerPositionTest() throws GameException, ParserConfigurationException, SAXException, IOException{
    GameEngine.instance().clearRecords();
    final User user1=UserImpl.getNewInstance("hussain", "hussain.mutawa");
    final User user2=UserImpl.getNewInstance("ali", "ali.mutawa");
    final BoardMap boardMap = BoardMapImpl.getNewInstance("pnth");
    boardMap.prepareMap("web/maps/pnth.xml");
    game = GameImpl.getNewInstance("game1", user1, boardMap);
    mrx=MrX.getNewInstance(game, user1);
    detective=Detective.getNewInstance(game,user2);
View Full Code Here

TOP

Related Classes of org.scotlandyard.engine.User

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.