-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoreManager.java
More file actions
32 lines (28 loc) · 1002 Bytes
/
ScoreManager.java
File metadata and controls
32 lines (28 loc) · 1002 Bytes
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
import java.io.*;
import java.util.ArrayList;
public class ScoreManager {
private String filePath;
public ScoreManager(String filePath) {
this.filePath = filePath;
}
public void saveScore(String word, int guesses, long time) {
try (BufferedWriter bw = new BufferedWriter(new FileWriter(filePath, true))) {
bw.write(word + "," + guesses + "," + time);
bw.newLine();
} catch (IOException e) {
System.out.println("Error saving score: " + e.getMessage());
}
}
public ArrayList<String> loadScores() {
ArrayList<String> scores = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
String line;
while ((line = br.readLine()) != null) {
scores.add(line);
}
} catch (IOException e) {
System.out.println("Error loading scores: " + e.getMessage());
}
return scores;
}
}