Package org.scotlandyard.engine

Examples of org.scotlandyard.engine.GameException


  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");
    }
    // add the game to the list of available games
    GameEngine.instance().getLobby().addGame(game);
    return game;
View Full Code Here


  }

  @Override
  public void addDetective(final Detective detective) throws GameException {
    if (detective == null) {
      throw new GameException("Can not add a null detective to the list");
    }
    if (this.getPlayer(detective.getEmail()) != null) {
      throw new GameException("Can not join a game twice");
    }
    detectives.put(detective.getEmail(), detective);
    playerTokens.put(detective, new EnumMap<TransportationMethod, Token>(
        TransportationMethod.class));
  }
View Full Code Here

  }


  public Player getWhoOccupiesPosition(final Coordinate coordinate) throws GameException {
    if(coordinate==null){
      throw new GameException("coordinate has not been initialized");
    }
    if(this.getBoardMap()==null){
      throw new GameException("the current board map for the game has not been initialized");
    }
    if(coordinate.getBoardMap()==null){
      throw new GameException("the board map of the coordinate has not been initialized yet");
    }
    if(!coordinate.getBoardMap().equals(this.getBoardMap())){
      throw new GameException("the board map of the coordinate ["+coordinate.getBoardMap().toString()+"] is"+
                  "the same as the board map of the game ["+this.getBoardMap().toString()+"]");
    }
    Player temp = null;
    for(Player player:this.getPlayers()){
      if(player.getPosition(this)!=null && player.getPosition(this).equals(coordinate)){
View Full Code Here

  @Override
  public boolean removePlayer(final Player player) throws GameException{
    final MrX temp =null;
    if(player==null){
      throw new GameException("can not remove null player");
    }
    if (mrX!=null && mrX.getEmail().equals(player.getEmail())) {
      mrX=temp;
    } else {
      if(detectives.remove(player.getEmail())==null){
        throw new GameException("this player does not exist to be removed");
      }
    }
    playerPositions.remove(player);
    playerTokens.remove(player);
View Full Code Here

  }

  @Override
  public void setMrX(final Player player) throws GameException {
    if (player != null && this.getPlayer(player.getEmail()) != null) {
      throw new GameException("Can not join a game twice");
    }
    if (mrX != null) {
      throw new GameException(
          "Mr X is already set, and shall not be changed");
    }
    mrX = (MrX) player;
  }
View Full Code Here

  @Override
  public void setPlayerPosition(final PlayerPosition playerPosition)
      throws GameException {
    if(playerPosition.getPlayer()==null){
      throw new GameException("player must be set");
    }
    if(playerPosition.getPosition()==null){
      throw new GameException("position can not be null");
    }
    if(playerPosition.getPosition().getBoardMap()==null){
      throw new GameException("position map must be set first");
    }
    if(!playerPosition.getPosition().getBoardMap().equals(this.getBoardMap())){
      throw new GameException("the map of the position ["+playerPosition.getPosition().getBoardMap().getName()+"] is different from the map of the game ["+this.getBoardMap().getName()+"]");
    }

    final Coordinate coordinate = playerPosition.getPosition();
    final Player player = this.getWhoOccupiesPosition(coordinate);

    if(player!=null){
      if(!getMrX().equals(player)){
        throw new GameException("this position has been already occupied by other detective");

      }else if(getMrX().equals(player) && !getMrX().equals(playerPosition.getPlayer())){
        //has Mr X been caught?
        this.playerPositions.put(playerPosition.getPlayer(), playerPosition);
        this.setGameStatus(GameStatus.FINISHED);
        throw new GameException("Game is finished, detective ["+playerPosition.getPlayer().getName()+"] has captured Mr X");
      }
    }
    playerPosition.getPlayer().setPosition(this, playerPosition.getPosition());
    this.playerPositions.put(playerPosition.getPlayer(), playerPosition);
View Full Code Here


  @Override
  public void setPlayerPosition(final String playerEmail, final String coordinateLabel) throws GameException{
    if(gameStatus!=GameStatus.JUST_CREATED){
      throw new GameException("this method can be used to set players positions before the game has started only");
    }
    if(getPlayer(playerEmail)==null){
      throw new GameException("can not find player ["+playerEmail+"]");
    }
    if(this.getBoardMap()==null){
      throw new GameException("the map has not been set yet");
    }
    final Coordinate coordinate = this.getBoardMap().getCoordinate(coordinateLabel);
    if(coordinate==null){
      throw new GameException("can not find coordinate ["+coordinateLabel+"]");
    }
    final PlayerPosition playerPosition=new PlayerPositionImpl(this, this.getPlayer(playerEmail), this.boardMap.getCoordinate(coordinateLabel));
    this.setPlayerPosition(playerPosition);
  }
View Full Code Here

   * @param user
   * @throws GameException
   */
  public void loginUser(final User user) throws GameException{
    if(user==null){
      throw new GameException("can not add user who is null");
    }
    if(this.getUser(user.getEmail())!=null){
      throw new GameException("this user is already added to the list");
    }
    this.users.put(user.getEmail(), user);
  }
View Full Code Here

   * @throws GameException
   */
  public String startGame(final Game game) throws GameException{
       
        if(game==null){
            throw new GameException("Game can not be found");
        }
       
        if(game.getMrX()==null){
          throw new GameException("Game must have MrX to start");
        }
       
        if(game.getDetectives().size()==0){
          throw new GameException("Game must have at least one detective");
        }
       
       
        game.setGameStatus(GameStatus.STARTED);
       
View Full Code Here

   * @throws GameException if the name is not specified
   */
  private BoardMapImpl(final String mapName) throws GameException{
    super();
    if(mapName==null){
      throw new GameException("map name must be specified");
    }
    name = mapName;
    links = new HashSet<Link>();
    coordinates = new HashMap<String, Coordinate>();
  }
View Full Code Here

TOP

Related Classes of org.scotlandyard.engine.GameException

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.