Java high score table help

Started by
4 comments, last by Antheus 17 years ago
Hi. I have made a simple tetris clone with Java as an applet and now I wish to add high score functionality. I have looked everywhere, but I can't figure out where to begin doing this! I have heard databases mentioned, but haven't the slightest clue about them. Please help. Thanks. [Edited by - Sean77771 on April 6, 2007 3:21:46 PM]
Advertisement
Nah, databases are overkill.

What is tetris high-score table?

10 times a pair of <Name> <number>

In code, your high score table will be represented with a list of 10 objects.
class HighScoreEntry : implements Comparable {string name;int score;// Comparable interface implementation}
and then couple that with high-score class
class HighScoreTable{  List<HighScoreEntry> entries;  public void load(string filename) ...  public void save(string filename) ...}
Then just add the methods for inserting or removing the high scores.

The Comparable interface is optional, it allows you to use Java's native sorting routines to maintain the list, but isn't really necessary.

The load and save methods implement writing the contents to a file.

You could also implement Serializable interface on both classes, and then just use ObjectWriter/ObjectReader (I might have mixed up the names a bit) to just dump the object and let Java handle the persistance.

As applet, you'll need to look into permissions on where you can store the file. Applets generally don't allow messing with local system much.
Ok, thanks that helps, but I am still having problems with permissions. Since it's an applet, I can't seem to read/write from files on local machine and can't figure out where I can read/write them from.
One way is to sign the jar and grant these permissions.

The other is to store the high-scores as a cookie. In that case you may need to encode your table as printable characters, possibly as base64.
How do I make my applet into a jar file, and then how would I sign it?
Quote:Original post by Sean77771
How do I make my applet into a jar file, and then how would I sign it?


For packing into jar there's the jar utility along with your java SDK.

For signing, there's tons of links on google under "java applet signing". I won't single out any of them, since they vary in depth and background required.

This topic is closed to new replies.

Advertisement