Class HighScores

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    @Deprecated
    public class HighScores
    extends PDBFile
    Deprecated.
    The game highscores management class.

    The highscores are stored in a waba PDBFile object which is linked to the application through the software creatorID. This causes the highscores database deletion when the game with the same creatorID is erased.

    The complete database name is composed by the game name 'appl' and its creatorID, both provided during the engine setup.
    The highscores database name is : ${appl}_HSC.${creatorID}.DATA

    You can find a complete game API sample named 'Ping' in the TotalCross samples folder.
    Here is some sample code:

     import totalcross.game.*;
     import totalcross.util.props.*;
     ...
    
     <i>public class Ping extends <U>GameEngine</U></i> {
    
     // constructor
     public Ping()
     {
       totalcross.sys.Settings.setPalmOSStyle(true);
    
       // define the game API setup attributes
    
       gameName             = "Ping";
    
       // when not run on device, appCreatorId does not always return the same value.
    
       gameCreatorID        = Settings.onJavaSE ? totalcross.sys.Settings.appCreatorId:"PiNg";
    
       gameVersion          = 100;   // v1.00
       gameHighscoresSize   = 7;     // store the best 7 highscores
       gameRefreshPeriod    = 75;    // 75 ms refresh periods
       gameIsDoubleBuffered = true;  // used double buffering to prevent flashing display
       gameDoClearScreen    = true;  // screen is cleared before each frame display
       gameHasUI            = false; // no UI elements, frame displays are optimized
       ...
     }
    
     public void addUserScore(Property.Str user,int score) {
    
       <B>HighScores</B> hs=<U>getHighScores</U>();
    
       // try to add a new score to the highscores
    
       HighScoreEntry insEntry=<B>hs.add</B>(score,user);
    
       if (insEntry!=null) {    // is score a highscore ?
    
         // get access to all highscores
         HighScoreEntry[] entries=<B>hs.getEntries()</B>;
    
         for (int n=0; n<<B>hs.size</B>(); n++) {
    
           // access the nth highscore entry
           HighScoreEntry entry=entries[n];
    
           Vm.debug("name: "+entry.name+" score="+Convert.toString(entry.score));
         }
    
       }
    
     }
     
    • Constructor Detail

      • HighScores

        protected HighScores​(GameEngine engine)
                      throws IOException
        Deprecated.
        This class must be instantiated using the GameEngineMainWindow.getHighScores
        Throws:
        IOException
    • Method Detail

      • size

        public final int size()
        Deprecated.
        Amount of highscore entries.
        Returns:
        the number of entries in the highscore table.
      • getEntries

        public final HighScoreEntry[] getEntries()
        Deprecated.
        Retrieve the highscore entries.
        Returns:
        an array to the highscore entries.
      • add

        public HighScoreEntry add​(int score,
                                  java.lang.String name)
        Deprecated.
        add a new score to the highscore table.
        Parameters:
        score - to add.
        name - of the performer, may be null.
        Returns:
        added entry or null
        See Also:
        HighScoreEntry
      • save

        public boolean save()
        Deprecated.
        Stores the highscores database.
        Returns:
        false if no changes to save or an error occurs
      • close

        public void close()
                   throws IOException
        Deprecated.
        closes the highscores database.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class PDBFile
        Throws:
        IOException