コード例 #1
0
ファイル: TeamDAO.java プロジェクト: brunoisy/Betrayal
  /*
  remet les points de chaque team à 0, et assigne players/team joueurs à chaque team
   */
  public void assignTeams() {
    for (int i = 1; i <= Game.TEAMS; i++) {
      find(i).setPoints(0);
    }
    try {
      ResultSet result =
          this.connect
              .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)
              .executeQuery("SELECT te_id FROM teams");

      int[] shuffledArray = Game.shuffleArray();

      PlayerDAO playerDAO = (PlayerDAO) DAOFactory.getPlayerDAO();
      for (int i = 0; result.next(); i = i + Game.PLAYERS / Game.TEAMS) {
        for (int j = 0; j < Game.PLAYERS / Game.TEAMS; j++) {
          playerDAO.find(shuffledArray[i + j]).setTeamID(result.getInt("te_id"));
        }
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
ファイル: TeamDAO.java プロジェクト: brunoisy/Betrayal
  public ArrayList<Player> getPlayerList(Team team) {

    ArrayList<Player> players = new ArrayList<>();

    try {
      Statement state =
          this.connect.createStatement(
              ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

      ResultSet result =
          state.executeQuery("SELECT pl_id FROM players WHERE te_id =" + team.getID());

      PlayerDAO playerDAO = (PlayerDAO) DAOFactory.getPlayerDAO();

      while (result.next()) {
        players.add(playerDAO.find(result.getInt(1)));
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }

    return players;
  }