Sign in to follow this  
Sean77771

Java high score table help

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this