Categories: Java | Java ME | How To | Code Examples | Files/Data
This page was last modified 09:06, 27 November 2007.
How to create a high score database in Java ME
From Forum Nokia Wiki
Every game should have a high score system to allow gamers to challenge other gamers or themselves.
Java ME use Record Management System (RMS) to allows developers to save and restore data over differents application sessions. So, for creating a quick Hiscore system saving name of the user and points, you can use the following code.
// We open the recordstore RecordStore highscore = RecordStore.openRecordStore("High Score", true); // To add a new HiScore we use a quick string comma-separated String str = new String("John,3400"); byte [] strb = str.getBytes(); Int id = hiscore.addRecord(strb, 0, strb.length); // To read all hiscores saved on the RMS RecordEnumeration enum = highscore.enumerateRecords(null, null, false); int id; bytes [] record; String str; while (enum.hasNextElement( )) { id = enum.nextRecordId( ); record = enum.getRecord(id); str = new String(record); // Operate with str to extract name and points } highscore.close();
You should use try-catch sentences to catch exceptions on the I/O operation or make a throws.
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| DBMS problem | symbiannil | General Symbian C++ | 4 | 2008-07-03 07:58 |
| using SyncML for user defined database. | abhicreation | General Symbian C++ | 0 | 2007-06-11 14:57 |
| Record store problem | harshalpatil | Mobile Java General | 8 | 2007-05-24 10:25 |
| get IMEI number | jwon23 | Python | 2 | 2006-05-15 10:02 |
| How to convert Symbian S60 2nd edition's created Database into XML? | Tanya | General Symbian C++ | 4 | 2008-03-06 10:38 |
