Hey, I'm making a game, and I'm wondering how to make a file and then edit/read it so I can store high scores. Any help on this will be appreciated.
import java.util.Preferences; public class HighScores extends Actor { private Preferences prefs; private int highestScore = 0; private boolean prefsWorking = false; public void addHighScore(int score){ /*If in an applet we don't have permision to use preferences and * a SecurityException will be thrown. If this happens we set * prefsWorking to false */ try { prefs = Preferences.userNodeForPackage(HighScores.class); prefsWorking = true; } catch (Exception e){ prefsWorking = false; } if(prefsWorking){ //We now get the value from preferences highestScore = prefs.getInt("yourgamename_highestscore",0); if(score > highestScore){ //If the score is higher than the highest score we put it's value as the new highest score prefs.putInt("yourgamename_highestscore", score); } } } }
prefs = Preferences.userNodeForPackage(billygame.SomeClass.class);