rendered paste bodypackage Wumpus;
import java.util.Collection;
import java.util.TreeSet;
import java.util.Iterator;
import java.io.*;
/**
* Summary description for Score.
*/
public class Score
{
private Collection scores = new TreeSet();
private static final int MAX_SCORES = 10;
private boolean victory;
private int start, end;
private String name;
private int score;
private String cave;
private ScoreEntry player;
public Score()
{
load("highscores.dat");
victory = false;
}
public void add(ScoreEntry score)
{
scores.add(score);
save("highscores.dat");
}
public void show()
{
// create form
int n = 0;
for (Iterator i = scores.iterator(); i.hasNext(); )
{
if (++n > MAX_SCORES)
{
break;
}
ScoreEntry entry = (ScoreEntry)i.next();
// add entry to form
}
// show form
}
private void load(String fileName)
{
try
{
FileReader rfile = new FileReader("HighScores.dat");
FileWriter wfile = new FileWriter("HighScores.dat");
BufferedReader bfile = new BufferedReader(rfile);
String readln = bfile.readLine();
while (readln != null)
{
// parse the lines
// format of Name;Score;Map
// reads the name
start = 0;
end = readln.indexOf(";", start);
name = readln.substring(start, end);
// reads the score
start = end + 1;
end = readln.indexOf(";", start);
score = (Integer.valueOf(readln.substring(start, end))).intValue();
// reads the map number
start = end + 1;
end = readln.indexOf(";", start);
cave = readln.substring(start, end);
// makes a score entry with previously read info
player = new ScoreEntry(name, score, cave);
scores.add(player);
}
bfile.close();
}
catch (java.io.FileNotFoundException e1)
{
}
catch (java.io.IOException e2)
{
}
}
private void save(String fileName)
{
}
}