game highscore system.

Ok, this sounds simple but i have no clue how to or what to do.

Me and a freind are remakng the game Asteroids for our semeste exam.

Al we want for a highscore system is to display the higest score ever gotten in the game, no name for now.

When the game starts it should i guees read the file which contains the high score. w/e it is set it to an int highScore. Then when a person runs out of all their lifes we will perform a check

if(score > highScore)

then replace the old high score with the new one.

We can do this for the length of the game while it runs but we dont now how to work with files. Or how we could accomplish this the simplest way.

What should i be looking for? Whats the eastiest way? best way? what type of file do we store it in?

note where using eclipse.

[836 byte] By [krrose27a] at [2007-11-27 3:54:07]
# 1

It depends. Who's using the game? How are you delivering it to them? How inclusive does the high score data have to me?

For example, suppose we're both using different computers, and with both download the game. Should the high score reflect both of our high scores, or should there be a different high score for each computer?

How about if we both use the game on the same computer?

etc.

paulcwa at 2007-7-12 8:58:13 > top of Java-index,Java Essentials,Java Programming...
# 2
The game will be compiled into a jar. For now the highscore should only be relavent to the computer. Can you store the highscore in the jar? This is very basic for now. No names, no nothing just a highscore.
krrose27a at 2007-7-12 8:58:13 > top of Java-index,Java Essentials,Java Programming...
# 3

If you want to keep it simple, I'd suggest making the high score per-user only, and to keep the high score in a flat file in the user's home directory. Don't put it in the jar.

Use System.getProperty("user.home")

to get the user's home directory (confirm that in the API docs; I think it's right, but confirm it). When you have that, create a File object pointing to a file in that directory, then read the file to get the current high score. (If the file doesn't exist, there will be no current high score.) Then you can parse the contents to get an integer, and compare with the current high score. Then if necessary you can write the file out with a new value.

paulcwa at 2007-7-12 8:58:13 > top of Java-index,Java Essentials,Java Programming...
# 4
do u know of a tutorialcdoing something like his?and ys that was right.
krrose27a at 2007-7-12 8:58:13 > top of Java-index,Java Essentials,Java Programming...
# 5

I don't know of any tutorials in particular that cover this, but it's pretty simple. The basic I/O tutorials should cover it. The only things that might not be in those tutorials is the use of the user.home system property, which I showed you basically all of, and parsing the file contents to get an integer. You can do that with java.lang.Integer.parseInt, I believe. Just make the number be the first string on the first line of the file, and it should be able to get it and parse it.

paulcwa at 2007-7-12 8:58:13 > top of Java-index,Java Essentials,Java Programming...