public class HighScores extends PDBFile
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));
}
}
}
CREATE, CREATE_EMPTY, 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_WRITE, REC_ATTR_DELETE, REC_ATTR_DIRTY, REC_ATTR_SECRET, REC_RELEASEskipBuffer| Modifier | Constructor and Description |
|---|---|
protected |
HighScores(GameEngine engine)
This class must be instantiated using the
GameEngineMainWindow.getHighScores
|
| Modifier and Type | Method and Description |
|---|---|
HighScoreEntry |
add(int score,
java.lang.String name)
add a new score to the highscore table.
|
void |
close()
closes the highscores database.
|
HighScoreEntry[] |
getEntries()
Retrieve the highscore entries.
|
boolean |
save()
Stores the highscores database.
|
int |
size()
Amount of highscore entries.
|
addRecord, addRecord, delete, deleteRecord, finalize, getAttributes, getName, getRecordAttributes, getRecordCount, getRecordOffset, getRecordPos, getRecordSize, inspectRecord, listPDBs, listPDBs, readBytes, rename, resizeRecord, searchBytes, setAttributes, setRecordAttributes, setRecordOffset, setRecordPos, skipBytes, writeBytesasInputStream, asOutputStream, asStream, asStream, wrapInputStream, wrapInputStreamToStream, write, writeBytes, writeBytes, writeBytesprotected HighScores(GameEngine engine) throws IOException
IOExceptionpublic final int size()
public final HighScoreEntry[] getEntries()
public HighScoreEntry add(int score, java.lang.String name)
score - to add.name - of the performer, may be null.HighScoreEntrypublic boolean save()
public void close()
throws IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class PDBFileIOException