Package totalcross.game
Class HighScores
- java.lang.Object
-
- totalcross.io.Stream
-
- totalcross.io.PDBFile
-
- totalcross.game.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}.DATAYou 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)); } } }
-
-
Field Summary
-
Fields inherited from class totalcross.io.PDBFile
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_RELEASE
-
Fields inherited from class totalcross.io.Stream
skipBuffer
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedHighScores(GameEngine engine)Deprecated.This class must be instantiated using the GameEngineMainWindow.getHighScores
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description HighScoreEntryadd(int score, java.lang.String name)Deprecated.add a new score to the highscore table.voidclose()Deprecated.closes the highscores database.HighScoreEntry[]getEntries()Deprecated.Retrieve the highscore entries.booleansave()Deprecated.Stores the highscores database.intsize()Deprecated.Amount of highscore entries.-
Methods inherited from class totalcross.io.PDBFile
addRecord, addRecord, delete, deleteRecord, finalize, getAttributes, getName, getRecordAttributes, getRecordCount, getRecordOffset, getRecordPos, getRecordSize, inspectRecord, listPDBs, listPDBs, readBytes, rename, resizeRecord, searchBytes, setAttributes, setRecordAttributes, setRecordOffset, setRecordPos, skipBytes, writeBytes
-
Methods inherited from class totalcross.io.Stream
asInputStream, asOutputStream, asStream, asStream, wrapInputStream, wrapInputStreamToStream, write, writeBytes, writeBytes, writeBytes
-
-
-
-
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 IOExceptionDeprecated.closes the highscores database.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classPDBFile- Throws:
IOException
-
-