Ajout de la persistance

- écriture dans fichier résultat.txt
main
ZIRTR0X 3 years ago
parent e2a78a84e7
commit e114a7aa93

@ -0,0 +1,3 @@
11 1 20-01-22
12 1 20-01-22
17 1 20-01-22

@ -3,16 +3,13 @@ package controller;
import com.jfoenix.controls.JFXButton;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;
@ -21,8 +18,8 @@ import model.Case;
import model.GameLoop;
import model.GameTime;
import model.Map;
import model.ResultatTxt;
import java.awt.*;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
@ -318,6 +315,7 @@ public class GamePlayController implements Initializable {
finJeu = true;
timer();
returnToStart();
saveScore();
}
}else{
System.out.println("Case null");
@ -326,12 +324,12 @@ public class GamePlayController implements Initializable {
}
public void returnToStart(){
button.setText("Restart");
button.setStyle("-fx-background-color: #EB9C0A; -fx-text-fill: white;");
button.setLayoutX(1071);
button.setLayoutY(752);
button.setPrefHeight(30);
button.setPrefWidth(119);
button.setText("Retour au début");
button.setOnAction(event -> {
AnchorPane pane = null;
try {
@ -459,13 +457,11 @@ public class GamePlayController implements Initializable {
}
}
/*resultat1.setText("Vous avez fait un " + diceNumber + ".");
resultat2.setText("Vous avez fait un " + diceNumber + ".");
resultat3.setText("Vous avez fait un " + diceNumber + ".");
resultat4.setText("Vous avez fait un " + diceNumber + ".");
resultat5.setText("Vous avez fait un " + diceNumber + ".");*/
}
public void saveScore(){
//difficulty
int resultat = gameTime.getTime();
ResultatTxt resultatTxt = new ResultatTxt();
resultatTxt.sauvegarderResultat(resultat, difficulty);
}
}

@ -53,11 +53,11 @@ public class MapController implements Initializable {
private final Image ak = new Image("/image/terrain/puit1hd.png");
private final Image al = new Image("/image/terrain/puit1bg.png");
private final Image am = new Image("/image/terrain/puit1bd.png");
private final int[][] coordFirstDifficultyMap = {{0,24},{1,24},{2,24},{3,24},{4,24},{5,24},{5,23},{5,22},{5,21},{5,20},{5,19},{5,18},{6,18},{7,18},{8,18},{9,18},{10,18},{11,18},{12,18},{12,17},{12,16},{12,15},{12,14},{12,13},{12,12},{11,12},{10,12},{9,12},{8,12},{7,12},{6,12},{5,12},{4,12},{3,12},{3,11},{3,10},{3,9},{3,8},{3,7},{3,6},{3,5},{3,4},{3,3},{4,3},{5,3},{6,3},{7,3},{8,3},{9,3},{10,3},{11,3},{12,3},{13,3},{14,3},{15,3},{16,3},{17,3},{18,3},{19,3},{19,4},{19,5},{19,6},{19,7},{19,8},{19,9},{19,10},{20,10},{21,10},{22,10},{23,10},{24,10},{24,11},{24,12},{24,13},{24,14},{24,15},{24,16},{24,17},{24,18},{24,19},{24,20},{24,21},{24,22},{24,23},{24,24},{25,24},{26,24},{27,24},{28,24},{29,24}};
//private final int[][] coordFirstDifficultyMap = {{0,24},{1,24},{2,24},{3,24},{4,24},{5,24},{5,23},{5,22},{5,21},{5,20},{5,19},{5,18},{6,18},{7,18},{8,18},{9,18},{10,18},{11,18},{12,18},{12,17},{12,16},{12,15},{12,14},{12,13},{12,12},{11,12},{10,12},{9,12},{8,12},{7,12},{6,12},{5,12},{4,12},{3,12},{3,11},{3,10},{3,9},{3,8},{3,7},{3,6},{3,5},{3,4},{3,3},{4,3},{5,3},{6,3},{7,3},{8,3},{9,3},{10,3},{11,3},{12,3},{13,3},{14,3},{15,3},{16,3},{17,3},{18,3},{19,3},{19,4},{19,5},{19,6},{19,7},{19,8},{19,9},{19,10},{20,10},{21,10},{22,10},{23,10},{24,10},{24,11},{24,12},{24,13},{24,14},{24,15},{24,16},{24,17},{24,18},{24,19},{24,20},{24,21},{24,22},{24,23},{24,24},{25,24},{26,24},{27,24},{28,24},{29,24}};
private final int[][] coordSecondDifficultyMap = {{17,0},{17,1},{17,2},{17,3},{17,4},{18,4},{19,4},{20,4},{21,4},{22,4},{23,4},{24,4},{25,4},{25,5},{25,6},{25,7},{25,8},{25,9},{25,10},{25,11},{25,12},{25,13},{25,14},{24,14},{23,14},{22,14},{21,14},{20,14},{20,15},{19,15},{18,15},{17,15},{16,15},{15,15},{15,14},{15,13},{15,12},{15,11},{15,10},{14,10},{13,10},{12,10},{11,10},{10,10},{9,10},{8,10},{7,10},{6,10},{5,10},{4,10},{3,10},{2,10},{2,11},{2,12},{2,13},{2,14},{2,15},{2,16},{2,17},{2,17},{3,17},{4,17},{5,17},{6,17},{7,17},{8,17},{9,17},{9,18},{9,19},{9,20},{9,21},{9,22},{9,23},{9,24},{9,25},{10,25},{11,25},{12,25},{13,25},{14,25},{15,25},{16,25},{17,25},{18,25},{19,25},{20,25},{21,25},{22,25},{23,25},{24,25},{25,25},{26,25},{27,25},{28,25},{29,25}};
private final int[][] coordThirdDifficultyMap = {{28,0},{28,1},{28,2},{28,3},{27,3},{26,3},{25,3},{24,3},{23,3},{22,3},{21,3},{20,3},{19,3},{18,3},{17,3},{16,3},{15,3},{14,3},{13,3},{12,3},{11,3},{10,3},{9,3},{8,3},{7,3},{6,3},{5,3},{4,3},{3,3},{3,4},{3,5},{3,6},{3,7},{4,7},{5,7},{6,7},{7,7},{8,7},{9,7},{10,7},{10,8},{10,9},{11,9},{12,9},{13,9},{14,9},{15,9},{16,9},{17,9},{18,9},{19,9},{20,9},{21,9},{22,9},{23,9},{23,10},{23,11},{23,12},{23,13},{23,14},{24,14},{25,14},{26,14},{26,15},{26,16},{26,17},{26,18},{26,19},{26,20},{26,21},{26,22},{26,23},{26,24},{26,25},{25,25},{24,25},{23,25},{22,25},{21,25},{20,25},{19,25},{18,25},{17,25},{16,25},{15,25},{14,25},{13,25},{12,25},{11,25},{10,25},{9,25},{8,25},{7,25},{6,25},{5,25},{4,25},{3,25},{2,25},{1,25},{1,24},{1,23},{1,22},{1,21},{1,20},{1,19},{2,19},{3,19},{4,19},{5,19},{6,19},{7,19},{8,19},{9,19},{10,19},{11,19},{12,19},{13,19},{13,18},{13,17},{13,16},{13,15},{13,14},{12,14},{11,14},{10,14},{9,14},{8,14},{7,14},{6,14},{5,14},{4,14},{3,14},{2,14},{1,14},{0,14}};
private int[][] coordMap = {};
//private final int[][] coordFirstDifficultyMap = {{0,24},{1,24},{2,24},{3,24},{4,24},{5,24},{5,23},{5,22},{5,21}};
private final int[][] coordFirstDifficultyMap = {{0,24},{1,24},{2,24},{3,24},{4,24},{5,24},{5,23},{5,22},{5,21}};
@Override
public void initialize(java.net.URL location, java.util.ResourceBundle resources) {

@ -36,6 +36,9 @@ public class GameTime {
System.out.println("GameTime.stop()");
timer.stop();
}
public int getTime() {
return Integer.parseInt(textTimer.getText());
}
}

@ -0,0 +1,14 @@
package model;
import java.awt.*;
import java.util.ArrayList;
public class ListeScore {
private ArrayList listeScore = new ArrayList<Score>();
public ListeScore() {
}
public void addScore(Score score) {
listeScore.add(score);
}
}

@ -0,0 +1,24 @@
package model;
import model.ListeScore;
import model.Score;
import java.io.*;
import java.nio.file.Files;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class ResultatTxt {
public void sauvegarderResultat(int resultat, int lvl) {
try {
LocalDate today = LocalDate.now();
FileWriter fw = new FileWriter("resultats.txt",true);
fw.write(resultat + " " + lvl + " " + today.format(DateTimeFormatter.ofPattern("dd-MM-yy")) + "\n");
fw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

@ -0,0 +1,15 @@
package model;
import java.time.LocalDateTime;
public class Score {
private int score;
private int level;
private String date;
public Score(int score, int level,String date) {
this.score = score;
this.level = level;
this.date = date;
}
}
Loading…
Cancel
Save