Package org.scotlandyard.engine

Examples of org.scotlandyard.engine.Game


    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){
      Assert.assertTrue(true);
    }


    Assert.assertEquals(game.getDetectives().size(),0);
    Assert.assertNull(game.getMrX());
  }
View Full Code Here


      throws Exception {

    final String playerEmail = engine.getUsers().get(getSessionId()).getEmail();
    final String gameId=request.getParameter("gameId");

    final Game game = engine.getLobby().getGame(gameId);

    String position = game.getPlayerPosition(playerEmail);

    return JsonFactory.toJson(position);
  }
View Full Code Here

    Assert.assertNull(game.getMrX());
  }

  @Test  //TODO add description of what the test should do
  public final void testSetGameStatus() throws GameException{
    final Game game = GameImpl.getNewInstance("g", null, null);
    Assert.assertEquals(game.getGameStatus().toString(),GameStatus.JUST_CREATED.toString());
    game.setGameStatus(GameStatus.FINISHED);
    Assert.assertEquals(game.getGameStatus().toString(),GameStatus.FINISHED.toString());
    GameEngine.instance().getLobby().removeAllGames();
    Assert.assertEquals(GameEngine.instance().getLobby().getAvailableGames().size(),0);
  }
View Full Code Here

  }

  @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

    final String playerEmail = engine.getUsers().get(getSessionId()).getEmail();
    final String gameId=request.getParameter("gameId");
    final String positionReg=request.getParameter("positionReq");
    final String transportationMethod=request.getParameter("transportationMethod");

    final Game game = engine.getLobby().getGame(gameId);

    if(game.isPlayable()==false){
      throw new GameException("the game is still not playable.");
    }

    String position = game.getPlayerPosition(playerEmail);
    Player player=game.getPlayer(playerEmail);

    Token token = player.getTokens(game.getIdentifier())
      .get(TransportationMethod.valueOf(transportationMethod));

    token.consumeTicket();

    player.useTokenToMove(game.getIdentifier(), token, positionReg);


    return JsonFactory.toJson(position);
  }
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.