|
|
|
@ -14,11 +14,46 @@ public class ResultatTxt {
|
|
|
|
|
public void sauvegarderResultat(int resultat, int lvl) {
|
|
|
|
|
try {
|
|
|
|
|
LocalDate today = LocalDate.now();
|
|
|
|
|
FileWriter fw = new FileWriter("resultats.txt",true);
|
|
|
|
|
FileWriter fw = new FileWriter("ressources/resultat/resultats.txt",true);
|
|
|
|
|
fw.write(resultat + " " + lvl + " " + today.format(DateTimeFormatter.ofPattern("dd-MM-yy")) + "\n");
|
|
|
|
|
fw.close();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public ListeScore chargerResultat() {
|
|
|
|
|
ListeScore lp = new ListeScore();
|
|
|
|
|
String[] tab;
|
|
|
|
|
InputStream flux;
|
|
|
|
|
int level;
|
|
|
|
|
int resultat;
|
|
|
|
|
String date;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
File fi =new File("resultats.txt");
|
|
|
|
|
if(!fi.exists()) {
|
|
|
|
|
flux = getClass().getClassLoader().getResourceAsStream("Resultats/resultats");
|
|
|
|
|
assert flux != null;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
flux = new FileInputStream(fi);
|
|
|
|
|
}
|
|
|
|
|
InputStreamReader lecture = new InputStreamReader(flux);
|
|
|
|
|
BufferedReader in = new BufferedReader(lecture);
|
|
|
|
|
String ligne;
|
|
|
|
|
String separateur = " ";
|
|
|
|
|
while ((ligne = in.readLine()) != null) {
|
|
|
|
|
tab = ligne.split(separateur);
|
|
|
|
|
level = Integer.parseInt(tab[1]);
|
|
|
|
|
resultat = Integer.parseInt(tab[0]);
|
|
|
|
|
date = tab[2];
|
|
|
|
|
Score sc = new Score(resultat, level, date);
|
|
|
|
|
lp.addScore(sc);
|
|
|
|
|
}
|
|
|
|
|
in.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return lp;
|
|
|
|
|
}
|
|
|
|
|
}
|