jgame
Class Highscore

java.lang.Object
  extended by jgame.Highscore

public class Highscore
extends java.lang.Object

Class for handling highscores. A highscore consists of a score, a name, and optionally, a number of information fields such as level, etc.


Field Summary
 java.lang.String[] fields
           
 java.lang.String name
           
 int score
           
 
Constructor Summary
Highscore(int score, java.lang.String name)
          Construct regular highscore
Highscore(int score, java.lang.String name, java.lang.String field1)
          Construct highscore with one extra field
Highscore(int score, java.lang.String name, java.lang.String field1, java.lang.String field2)
          Construct highscore with extra fields
Highscore(int score, java.lang.String name, java.lang.String field1, java.lang.String field2, java.lang.String field3)
          Construct highscore with extra fields
 
Method Summary
static int findPos(Highscore[] highscores, int newscore)
          Find position (array index) of given score in highscore list, -1 means not in highscores.
static Highscore[] insert(Highscore[] highscores, Highscore newscore)
          Try to insert new highscore in given highscore list.
static Highscore[] load(java.io.InputStream in)
           
static void save(Highscore[] highscores, java.io.OutputStream out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

score

public int score

name

public java.lang.String name

fields

public java.lang.String[] fields
Constructor Detail

Highscore

public Highscore(int score,
                 java.lang.String name)
Construct regular highscore


Highscore

public Highscore(int score,
                 java.lang.String name,
                 java.lang.String field1)
Construct highscore with one extra field


Highscore

public Highscore(int score,
                 java.lang.String name,
                 java.lang.String field1,
                 java.lang.String field2)
Construct highscore with extra fields


Highscore

public Highscore(int score,
                 java.lang.String name,
                 java.lang.String field1,
                 java.lang.String field2,
                 java.lang.String field3)
Construct highscore with extra fields

Method Detail

findPos

public static int findPos(Highscore[] highscores,
                          int newscore)
Find position (array index) of given score in highscore list, -1 means not in highscores.

Parameters:
highscores - sorted highscore list
Returns:
0 means first position, etc. -1 means not in list

insert

public static Highscore[] insert(Highscore[] highscores,
                                 Highscore newscore)
Try to insert new highscore in given highscore list. Do nothing if it's too low. Leaves old array untouched.


load

public static Highscore[] load(java.io.InputStream in)
                        throws java.io.IOException
Throws:
java.io.IOException

save

public static void save(Highscore[] highscores,
                        java.io.OutputStream out)
                 throws java.io.IOException
Throws:
java.io.IOException