Esempio n. 1
0
  /** Creates new game for a given player and returns the gameId as String */
  @Override
  public String createNewGame(String playerId) {

    PlayerAI cp = new SimplePlayerAI(UUID.randomUUID().toString());
    Logger.info(String.format("Player %s has started a new single player game.", playerId));
    IGame game = createGame(playerId, cp.getId());
    game.addObserver(cp);
    game.notifyObservers();

    return game.getGameID();
  }
Esempio n. 2
0
  @Override
  public void abortGame(String gameId, String playerId) {

    try {
      IGame game = getGame(gameId);

      Logger.info(String.format("Player %s has aborted game %s.", playerId, gameId));
      game.setAborted(playerId);

      // Delete the game if both players have aborted.
      if (game.isFinished()) {
        games.remove(game.getGameID());
        Logger.info(String.format("Game %s has been removed.", gameId));
      } else {
        game.notifyObservers();
      }

    } catch (UnknownPlayerException ex) {
      Logger.error(ex.toString());
    }
  }