Java High Score List
Results 1 to 2 of 2

Thread: Java High Score List

  1. #1
    Custom User
    Join Date
    Oct 2001
    Posts
    503

    Java High Score List

    I wrote some code that will allow you to create and store (in a text file) a high score list that I wrote for a uni exemption project (a minesweeper game); I was hoping that someone could give me some feedback on it.

    I'm fairly certain that there's some methods that I probably don't need in it, I'm not too concerned about that at the moment, but any other feedback would be really useful. The high score system uses two classes: the Score class which holds an individual score; and the ScoreList which holds an array of Score objects. I'm not sure if this is the best way to do it, but it worked, and I didn't notice it hogging up too many resources or anything :P.

    If anyone decides that the system isn't too terrible, you're free to use it (though I doubt somehow if that'll happen). I'll even include my HighScore class which shows the high score list in a simple window (you'll notice that the ScoreList class doesn't provide much functionality for getting the scores back out of the list :P).

    Here's a sample usage:

    Code:
    ScoreList myList = new ScoreList();
    
    if(!myList.getScoresFromFile("score.lst"))
    {
      System.out.println("No current high scores");
    }
    
    // you've got a new high score and you want to add it to the list
    if(!myList.add(name,Score.EASY,20))
      System.out.println("Couldn't add score");
    
    // write scores to file
    myList.writeScoresToFile("score.lst"));
    Note that the constants used in the Score class (BugMain.EASY, etc.) are just the times given for a game on a particular skill level. You can substitute them for any value that is greater than the time that the user has taken.

    Sorry if that all sounds too complicated

    ac

  2. #2
    Custom User
    Join Date
    Oct 2001
    Posts
    503

    Java High Score List

    I wrote some code that will allow you to create and store (in a text file) a high score list that I wrote for a uni exemption project (a minesweeper game); I was hoping that someone could give me some feedback on it.

    I'm fairly certain that there's some methods that I probably don't need in it, I'm not too concerned about that at the moment, but any other feedback would be really useful. The high score system uses two classes: the Score class which holds an individual score; and the ScoreList which holds an array of Score objects. I'm not sure if this is the best way to do it, but it worked, and I didn't notice it hogging up too many resources or anything :P.

    If anyone decides that the system isn't too terrible, you're free to use it (though I doubt somehow if that'll happen). I'll even include my HighScore class which shows the high score list in a simple window (you'll notice that the ScoreList class doesn't provide much functionality for getting the scores back out of the list :P).

    Here's a sample usage:

    Code:
    ScoreList myList = new ScoreList();
    
    if(!myList.getScoresFromFile("score.lst"))
    {
      System.out.println("No current high scores");
    }
    
    // you've got a new high score and you want to add it to the list
    if(!myList.add(name,Score.EASY,20))
      System.out.println("Couldn't add score");
    
    // write scores to file
    myList.writeScoresToFile("score.lst"));
    Note that the constants used in the Score class (BugMain.EASY, etc.) are just the times given for a game on a particular skill level. You can substitute them for any value that is greater than the time that the user has taken.

    Sorry if that all sounds too complicated

    ac

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides