This repository was archived by the owner on Oct 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScoreCalcul.java
More file actions
39 lines (37 loc) · 1.41 KB
/
ScoreCalcul.java
File metadata and controls
39 lines (37 loc) · 1.41 KB
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
33
34
35
36
37
38
39
import java.io.*;
public class ScoreCalcul {
public static int readScore() { // Cette methode va utiliser serializable pour récupérer le score dans le fichier socre afin de le lire dans CaseGame
ObjectInputStream ois = null;
try {
final FileInputStream fichier = new FileInputStream("jeu/score");
ois = new ObjectInputStream(fichier);
int a = (int) ois.readObject();
return a;
}
catch (Exception e){
System.out.println("Erreur lors de la lecture du fichier score");
}
return 0;
}
public static void writeScore(int score) { // Cette methode va réecrire l'ancien score au nouveau obtenu dans casegame dans le fichier score
ObjectOutputStream oos = null;
try {
final FileOutputStream fichier = new FileOutputStream("jeu/score"); // On save ici le nouveau Integer dans le fichier score
oos = new ObjectOutputStream(fichier);
oos.writeObject(score);
oos.flush();
}
catch (final java.io.IOException e) {
e.printStackTrace();
} finally {
try {
if (oos != null) {
oos.flush();
oos.close();
}
} catch (final IOException ex) {
ex.printStackTrace();
}
}
}
}