Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Explainning the function of gamehighscore

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Explainning the function of gamehighscore

    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


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,618
    Thanks
    50
    Thanked 2,235 Times in 2,207 Posts

    Default Re: Explainning the function of gamehighscore

    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. class function
    By huddo in forum Object Oriented Programming
    Replies: 9
    Last Post: June 12th, 2012, 07:26 PM
  2. Static Function
    By vinaysa86 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: June 8th, 2012, 08:23 AM
  3. Function in Function?
    By junxiqqq in forum Java Theory & Questions
    Replies: 5
    Last Post: May 18th, 2012, 08:05 PM
  4. need help with a function...
    By fallout87 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: November 2nd, 2011, 05:42 AM
  5. Function of difference between two numbers
    By uplink600 in forum Java Theory & Questions
    Replies: 2
    Last Post: May 13th, 2009, 05:57 AM

Tags for this Thread