Пример #1
0
 private static String getVerifiedPlayerName(String newName, String oldName) {
   if (newName == null || !StringUtils.isAlphanumericSpace(newName)) {
     newName = (StringUtils.isBlank(oldName) ? "Human" : oldName);
   } else if (StringUtils.isWhitespace(newName)) {
     newName = "Human";
   } else {
     newName = newName.trim();
   }
   return newName;
 }
Пример #2
0
 @Override
 public void focusLost(final FocusEvent e) {
   final Object source = e.getSource();
   if (source instanceof FTextField) { // the text box
     final FTextField nField = (FTextField) source;
     final String newName = nField.getText().trim();
     if (index == 0
         && !StringUtils.isBlank(newName)
         && StringUtils.isAlphanumericSpace(newName)
         && prefs.getPref(FPref.PLAYER_NAME) != newName) {
       prefs.setPref(FPref.PLAYER_NAME, newName);
       prefs.save();
     }
     lobby.firePlayerChangeListener(index);
   }
 }
Пример #3
0
 @Override
 public void handleEvent(FEvent e) {
   final Object source = e.getSource();
   if (source instanceof FTextField) { // the text box
     FTextField nField = (FTextField) source;
     String newName = nField.getText().trim();
     if (index == 0
         && !StringUtils.isBlank(newName)
         && StringUtils.isAlphanumericSpace(newName)
         && prefs.getPref(FPref.PLAYER_NAME) != newName) {
       prefs.setPref(FPref.PLAYER_NAME, newName);
       prefs.save();
       if (allowNetworking) {
         screen.firePlayerChangeListener(index);
       }
     }
   }
 }
Пример #4
0
  private void newGame(
      Connection connection, String fromNickname, String searchTerms, HandlerContext handlerContext)
      throws IOException {
    boolean isRandom = RANDOM.equalsIgnoreCase(searchTerms);
    if (isRandom) {
      searchTerms = getRandomWord(handlerContext);
    } else if (!StringUtils.isAlphanumericSpace(searchTerms)) {
      connection.send(
          Command.PRIVMSG,
          fromNickname,
          "No punctuation allowed in the search terms.  Try another one.");
      return;
    }
    try {
      mSearchResultCount = queryGoogle(handlerContext, connection, searchTerms);
    } catch (IOException e) {
      Log.w(TAG, "newGame Could not query Google", e);
      connection.send(Command.PRIVMSG, fromNickname, "Oops something went wrong...");
      return;
    }
    if (mSearchResultCount == 0) {
      connection.send(
          Command.PRIVMSG, fromNickname, "This search has no results!  Try another one.");
      resetGame();
      return;
    }
    mSearchTerms = searchTerms;
    mGameCreatedBy = fromNickname;

    if (isRandom) {
      connection.send(Command.PRIVMSG, fromNickname, "New game started with a random word search.");
    } else {
      connection.send(
          Command.PRIVMSG,
          fromNickname,
          "New game started with the search \"" + searchTerms + "\".");
    }
  }