Bugfixes and added missing infos

This commit is contained in:
stiv wogner 2019-03-25 17:17:08 +00:00
parent 75312cf06b
commit d071187c79
2 changed files with 117 additions and 105 deletions

View file

@ -53,7 +53,7 @@ public class ScoreEntry implements Comparable<ScoreEntry> {
* @param printWriter der PrintWriter, mit dem der Eintrag geschrieben wird
*/
public void write(PrintWriter printWriter) {
printWriter.println(this.name + ";" + this.date + ";" + this.score + ";" + this.gameType);
printWriter.println(this.name + ";" + this.date.getTime() + ";" + this.score + ";" + this.gameType);
}
/**
@ -73,11 +73,11 @@ public class ScoreEntry implements Comparable<ScoreEntry> {
* @return Ein ScoreEntry-Objekt oder null
*/
public static ScoreEntry read(String line) {
String[] parts = line.split(";");
if(parts.length != 4)
return null;
ScoreEntry res = new ScoreEntry(parts[0], Integer.parseInt(parts[1]), new Date(Long.parseLong(parts[2])), parts[3]);
return res;
String[] parts = line.split(";");
if(parts.length != 4)
return null;
ScoreEntry res = new ScoreEntry(parts[0], Integer.parseInt(parts[2]), new Date(Long.parseLong(parts[1])), parts[3]);
return res;
}
public Date getDate() {

View file

@ -142,7 +142,21 @@ public class Resources {
* @throws IOException Eine IOException wird geworfen, wenn Probleme beim Schreiben auftreten.
*/
private void saveScoreEntries() throws IOException {
// TODO: Resources#saveScoreEntries()
try {
OutputStream os = new FileOutputStream("highscores.txt");
OutputStreamWriter osr = new OutputStreamWriter(os, StandardCharsets.UTF_8);
BufferedWriter bw =new BufferedWriter(osr);
String data = new String();
List<ScoreEntry> scoreEntries = this.scoreEntries;
PrintWriter pw = new PrintWriter(bw);
while(!scoreEntries.isEmpty()) {
ScoreEntry se = scoreEntries.remove(0);
se.write(pw);
}
bw.close();
} catch (IOException e) {
throw new IOException(e);
}
}
/**
@ -156,13 +170,11 @@ public class Resources {
*/
private void loadScoreEntries() {
List<ScoreEntry> regionNames = new LinkedList<>();
InputStream is = Resources.class.getClassLoader().getResourceAsStream("highscores.txt");
InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8);
BufferedReader br = new BufferedReader(isr);
scoreEntries = new LinkedList<>();
String line;
try {
InputStream is = new FileInputStream("highscores.txt");
InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8);
BufferedReader br =new BufferedReader(isr);
String line;
while((line = br.readLine()) != null) {
line = line.trim();
if(line.length() > 0 && !line.startsWith("#")) {