public static List<GameDetails> getGameHighScores() throws SQLException {
List<GameDetails> r = new ArrayList<GameDetails>();
ResultSet rs = null;
//connectToDatabase();
//TODO
if (con == null) {
throw new SQLException("Not connected to database");
} else {
// prepare the statement if the connection is different
if (loadAllHighScoresSQLSt == null) {
loadAllHighScoresSQLSt = con.prepareStatement(loadAllHighScoresSQL);
}
// execute the query to get a result set
rs = loadAllHighScoresSQLSt.executeQuery();
double moveSpeed = 0; // data from result set
int firingInterval = 0;
int highScore = 0;
double speed = 0; // target data
int interval = 0;
int score = 0;
// details to add to list
GameDetails details;
// start at the first record
rs.first();
// go through the rows of the record set, add any high scores to list
while (rs.next()) {
// get data
moveSpeed = rs.getDouble("MoveSpeed");
firingInterval = rs.getInt("FiringInterval");
highScore = rs.getInt("HighScore");
// check the move speed + firing interval settings
// if ((moveSpeed != speed) || (firingInterval != interval)) {
// // settings changed so this is a new high score
// // set new targets
// speed = moveSpeed;
// interval = firingInterval;
// score = highScore;
// add details to list
details = new GameDetails(new UserDetails((String) rs.getString("UserName")), new GameSettings(moveSpeed, firingInterval));
r.add(details);
// } else {
// if (highScore == score) {
// // another player has the same high score. add to list
// details = new GameDetails(new UserDetails((String) rs.getString("UserName")), new GameSettings(moveSpeed, firingInterval));
// r.add(details);
// }
}
}
ask me to explain why you put if statement instead without it the if statement as for the gamehighscore
e.g if ((moveSpeed != speed) || (firingInterval != interval))
and
whats is the function do? for gamehighscoretablemodel
public Object getValueAt(int rowIndex, int columnIndex) {
if (columnIndex == 0)
return ((GameDetails)this.highScores.get(rowIndex)).getUs erDetails().getUserName();
if (columnIndex == 1)
return Double.valueOf(((GameDetails)this.highScores.get(r owIndex)).getGameSettings().getMoveSpeed());
if (columnIndex == 2) {
return Integer.valueOf(((GameDetails)this.highScores.get( rowIndex)).getGameSettings().getFiringInterval());
}
return Integer.valueOf(((GameDetails)this.highScores.get( rowIndex)).getHighScore());
}
i know my knowledge in my head but couldn't explain in vocal words