コード例 #1
0
  /**
   * play a letter and check the match values, so if the user wins, the user receives an email with
   * the information of the match played
   *
   * @param position
   * @param letter
   * @return
   */
  public PlayLetterInfoTuple playLetter(int position, char letter) {
    Log.debug(TAG, "play letter: " + letter);
    boolean success = match.play(position, letter);
    if (match.isFinished() && match.isWon()) {
      NotificationService notificationService = null;
      try {
        notificationService =
            (NotificationService)
                ServiceLocator.getInstance().find(ServiceLocator.SERVICE_NOTIFICATION);
      } catch (Exception e) {
        e.printStackTrace();
      }

      if (notificationService != null) {
        notificationService.notifyWonMatch(
            player.getName() + " " + player.getSurname(),
            player.getEmail(),
            match.getWordName(),
            match.getScore(),
            match.getNumErrors());
      }
    }
    return new PlayLetterInfoTuple(
        success, match.isFinished(), match.isWon(), match.getScore(), match.getNumErrors());
  }
コード例 #2
0
  /**
   * given the name of a category, it creates a match with its player, word and letterboxes
   *
   * @param categoryName
   * @return
   * @throws PlayerNotExistsException if the logged user is an admin
   */
  public MatchInfoTuple createMatch(String categoryName) throws PlayerNotExistsException {
    Log.debug(TAG, "create match for category: " + categoryName);
    DAOFactory daoFactory = PostgresDAOFactory.getInstance();

    // retrieve the player that is to be assigned to the new match
    PlayerDAO playerDAO = daoFactory.getPlayerDAO();
    try {
      player = playerDAO.get(username);
    } catch (PlayerNotExistsException e) {
      // the logged user is an admin user
      throw new PlayerNotExistsException();
    }

    // retrieve the category of the word that the match will have
    CategoryDAO categoryDAO = daoFactory.getCategoryDAO();
    Category category = null;
    try {
      category = categoryDAO.get(categoryName);
    } catch (CategoryNotExistsException e) {
      // this should never be the case, since a valid and existing
      // category is chosen from the UI (it is a precondition)
      e.printStackTrace();
    }

    // retrieve the global game parameters
    ParamsDAO paramsDAO = daoFactory.getParamsDAO();
    WordGuessParams params = paramsDAO.getParams();

    Word word = category.getRandomWord();

    try {
      match = new Match(params, player, word);
    } catch (Exception e) {
      e.printStackTrace();
    }
    if (match != null) {
      return match.getMatchInfoTuple();
    } else {
      return null;
    }
  }
コード例 #3
0
 /** @return the word of the match */
 public String getMatchWord() {
   String matchWord = match.getWordName();
   Log.debug(TAG, "match word: " + matchWord);
   return matchWord;
 }