Exemplo n.º 1
0
 public boolean insertPlayer(String email, String password, String name, int highscore) {
   Player p = new Player();
   p.setEmail(email);
   p.setPassword(password);
   p.setName(name);
   p.setHighscore(highscore);
   try {
     em.persist(p);
   } catch (PersistenceException e) {
     return (false);
   }
   return true;
 }
Exemplo n.º 2
0
  public boolean updatePlayer(String email, String password, String name, int highscore) {

    Player player = findPlayer(email);
    if (player == null) return false;
    player.setPassword(password);
    player.setName(name);
    player.setHighscore(highscore);
    try {
      em.merge(player);
    } catch (IllegalArgumentException e) {
      return false;
    }
    return true;
  }
Exemplo n.º 3
0
  public Player findPlayerFromGame(String email, int gameId) {
    List<Game> games = main.getGames();
    Game selectedGame = null;
    for (Game game : games) {
      if (game.getGameId() == gameId) {
        selectedGame = game;
      }
    }
    if (selectedGame == null) return (null);

    Set<Player> playerSet = selectedGame.getPlayerscore().keySet();
    List<Player> playerList = new ArrayList<>();
    playerList.addAll(playerSet);
    Player player = null;
    for (Player p : playerList) {
      System.out.println(p.getEmail());
      System.out.println("*****");
      if (p.getEmail().contentEquals(email)) {
        player = p;
      }
    }
    return player;
  }