Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## superwaba.ext.xplat.game
Class HighScores

    java.lang.Object
      |
      +--waba.io.Stream
            |
            +--waba.io.Catalog
                  |
                  +--superwaba.ext.xplat.game.HighScores

public class HighScores
extends Catalog

The game highscores management class.
The highscores are stored in a waba Catalog 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 SW examples folder.
Here is some sample code:

     import superwaba.ext.xplat.game.*;
     import superwaba.ext.xplat.util.props.*;
     ...

     public class Ping extends GameEngine {

     // constructor
     public Ping()
     {
       waba.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.onDevice ? waba.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) {

       HighScores hs=getHighScores();

       // try to add a new score to the highscores

       HighScoreEntry insEntry=hs.add(score,user);

       if (insEntry!=null) {    // is score a highscore ?

         // get access to all highscores
         HighScoreEntry[] entries=hs.getEntries();

         for (int n=0; n<hs.size(); n++) {

           // access the nth highscore entry
           HighScoreEntry entry=entries[n];

           Vm.debug("name: "+entry.name+" score="+Convert.toString(entry.score));
         }

       }

     }

Fields inherited from class waba.io.Catalog
`bag, CREATE, DB_ATTR_APPINFODIRTY, DB_ATTR_BACKUP, DB_ATTR_COPY_PREVENTION, DB_ATTR_OK_TO_INSTALL_NEWER, DB_ATTR_READ_ONLY, DB_ATTR_RESET_AFTER_INSTALL, DB_ATTR_STREAM, READ_ONLY, READ_WRITE, REC_ATTR_DELETE, REC_ATTR_DIRTY, REC_ATTR_SECRET, WRITE_ONLY`

Constructor Summary
`protected` | `HighScores(GameEngine engine)` This class must be instantiated using the GameEngineMainWindow.getHighScores

Method Summary
`HighScoreEntry` | `add(int score, String name)` add a new score to the highscore table.
`boolean` | `close()` closes the highscores database.
`HighScoreEntry[]` | `getEntries()` Retrieve the highscore entries.
`boolean` | `save()` Stores the highscores database.
`int` | `size()` Amount of highscore entries.

Methods inherited from class waba.io.Catalog
`addRecord, addRecord, delete, deleteRecord, getAttributes, getRecordAttributes, getRecordCount, getRecordPos, getRecordSize, inspectRecord, isOpen, listCatalogs, listCatalogs, readBytes, rename, resizeRecord, setAttributes, setRecordAttributes, setRecordPos, skipBytes, writeBytes`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, toString, wait, wait`

Constructor Detail

### HighScores

    protected HighScores(GameEngine engine)

  This class must be instantiated using the GameEngineMainWindow.getHighScores

Method Detail

### size

    public final int size()

  Amount of highscore entries.
  Returns:
    the number of entries in the highscore table.

### getEntries

    public final HighScoreEntry[] getEntries()

  Retrieve the highscore entries.
  Returns:
    an array to the highscore entries.

### add

    public HighScoreEntry add(int score,
                              String name)

  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()

  Stores the highscores database.
  Returns:
    false if no changes to save or an error occurs

### close

    public boolean close()

  closes the highscores database.
  Overrides:
    close in class Catalog
  Returns:
    true if succeeded.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD