Bugfixes and added missing infos
This commit is contained in:
parent
75312cf06b
commit
d071187c79
2 changed files with 117 additions and 105 deletions
|
|
@ -53,7 +53,7 @@ public class ScoreEntry implements Comparable<ScoreEntry> {
|
||||||
* @param printWriter der PrintWriter, mit dem der Eintrag geschrieben wird
|
* @param printWriter der PrintWriter, mit dem der Eintrag geschrieben wird
|
||||||
*/
|
*/
|
||||||
public void write(PrintWriter printWriter) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -76,7 +76,7 @@ public class ScoreEntry implements Comparable<ScoreEntry> {
|
||||||
String[] parts = line.split(";");
|
String[] parts = line.split(";");
|
||||||
if(parts.length != 4)
|
if(parts.length != 4)
|
||||||
return null;
|
return null;
|
||||||
ScoreEntry res = new ScoreEntry(parts[0], Integer.parseInt(parts[1]), new Date(Long.parseLong(parts[2])), parts[3]);
|
ScoreEntry res = new ScoreEntry(parts[0], Integer.parseInt(parts[2]), new Date(Long.parseLong(parts[1])), parts[3]);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,21 @@ public class Resources {
|
||||||
* @throws IOException Eine IOException wird geworfen, wenn Probleme beim Schreiben auftreten.
|
* @throws IOException Eine IOException wird geworfen, wenn Probleme beim Schreiben auftreten.
|
||||||
*/
|
*/
|
||||||
private void saveScoreEntries() throws IOException {
|
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() {
|
private void loadScoreEntries() {
|
||||||
|
|
||||||
List<ScoreEntry> regionNames = new LinkedList<>();
|
try {
|
||||||
InputStream is = Resources.class.getClassLoader().getResourceAsStream("highscores.txt");
|
InputStream is = new FileInputStream("highscores.txt");
|
||||||
InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8);
|
InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8);
|
||||||
BufferedReader br =new BufferedReader(isr);
|
BufferedReader br =new BufferedReader(isr);
|
||||||
scoreEntries = new LinkedList<>();
|
|
||||||
String line;
|
String line;
|
||||||
try {
|
|
||||||
while((line = br.readLine()) != null) {
|
while((line = br.readLine()) != null) {
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
if(line.length() > 0 && !line.startsWith("#")) {
|
if(line.length() > 0 && !line.startsWith("#")) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue