Hi, i implemented a very simple highscore into my game:
The problem is, every time i restart the program the highscore resets. How can i create a text file(or something similar) which saves the integer and reads it again at the start of the game? (The game isn't intended to be uploaded here)
Thanks :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Highscore here. * * @author (your name) * @version (a version number or a date) */ public class Highscore extends Actor { int highscore; public void act() { drawText(); setHighscore(); } private void drawText() { GreenfootImage img = new GreenfootImage( 220 , 100 ); img.setColor( new Color( 0 , 0 , 0 , 0 )); img.fill(); img.setColor(Color.LIGHT_GRAY); img.setFont( new Font( "Pixeled" , false , false , 10 )); img.drawString( "Highscore: " +highscore, 10 , 90 ); setImage(img); } public void setHighscore() { if (HitCounter.hitscore > highscore) { highscore = HitCounter.hitscore; } } } |