avancee rapport et debut save

This commit is contained in:
Haïssous Kayyissa 2022-05-24 13:49:09 +02:00
parent a9f837eaeb
commit cac52c7180
9 changed files with 2707 additions and 6 deletions

Binary file not shown.

View File

@ -5,10 +5,11 @@ public class Banniere extends JPanel {
private FrameJeu fenetre;
private FrameMenu menu;
// Définition du constructeur
public Banniere(int mines, FrameJeu fenetre, FrameMenu menu) {
public Banniere(int mines, FrameJeu fenetre, FrameMenu menu, Dimension grilleSize) {
super();
this.fenetre=fenetre;
this.menu=menu;
this.setSize(grilleSize.width,grilleSize.height/8);
// On défini un style à la bannière
this.setBackground(new Color(0, 236, 96));

View File

@ -123,6 +123,18 @@ public class Case extends JPanel {
return this.grille.getEnJeu();
}
// TODO : Override toString() pour avoir 3 bits désignants l'état de la case
//
@Override
public String toString(){
int value=0;
if (this.minee){
value+=1;
}
if (this.reperee){
value+=2;
}
if (this.visible){
value+=4;
}
return Integer.toString(value);
}
}

2599
DiagrammeDeClasses.mdj Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,14 @@
import javax.swing.*;
import java.awt.*;
import java.util.Random;
import java.util.Arrays;
public class Grille extends JPanel{
private Banniere banniere;
private Dimension grilleSize=new Dimension(0,0);
private Case[] plateau;
private int colonnes;
private int lignes;
private int taille;
private int mines;
private int minesLeft;
@ -20,6 +22,7 @@ public class Grille extends JPanel{
public Grille(int lignes, int colonnes, int mines, FrameJeu fenetre, FrameMenu menu){
super();
this.colonnes=colonnes;
this.lignes=lignes;
this.taille=lignes*colonnes;
this.mines=mines;
this.minesLeft=mines;
@ -30,9 +33,8 @@ public class Grille extends JPanel{
this.grilleSize = new Dimension(((screenSize.height*3/4)/lignes)*colonnes, screenSize.height*3/4 );
Dimension caseSize = new Dimension(this.grilleSize.height/lignes,this.grilleSize.height/lignes);
GridLayout damier = new GridLayout(lignes,colonnes);
Banniere banniere = new Banniere(mines,this.fenetre, menu);
Banniere banniere = new Banniere(mines,this.fenetre, menu, grilleSize);
this.banniere=banniere;
banniere.setSize(grilleSize.width,grilleSize.height/8);
this.setLayout(damier);
this.setSize(grilleSize);
@ -203,7 +205,13 @@ public class Grille extends JPanel{
// Methode pour récupérer le plateau de jeu
public Case[] getPlateau(){
return this.plateau;
return Arrays.copyOf(this.plateau,this.taille);
}
// Méthode pour récupérer le nombre de lignes
public Dimension getDimensionGrille(){
Dimension grilleSize= new Dimension(this.colonnes, this.lignes);
return grilleSize;
}
// Méthode pour rendre visibles les cases autour d'un 0

Binary file not shown.

70
SaveManager.java Normal file
View File

@ -0,0 +1,70 @@
import java.awt.Dimension;
import java.io.*;
public class SaveManager {
public void save(Grille grille, String nomFichier) {
Dimension taille = grille.getDimensionGrille();
String metaData= (int) taille.getWidth()+"x"+ (int) taille.getHeight()+"\n";
try {
BufferedWriter fichier = new BufferedWriter(new FileWriter(nomFichier));
Case[] toSave = grille.getPlateau();
fichier.write(metaData);
for(Case c : toSave) {
fichier.write(c.toString());
}
fichier.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public SaveData load(String nomFichier) {
String toReturn="";
String ligne;
Dimension dimension=new Dimension(0,0);
SaveData toRet=new SaveData(null, null);
try {
BufferedReader fichier = new BufferedReader(new FileReader(nomFichier));
ligne=fichier.readLine();
String[] taille = ligne.split("x");
int largeur = Integer.parseInt(taille[0]);
int hauteur = Integer.parseInt(taille[1]);
dimension = new Dimension(largeur, hauteur);
while((ligne = fichier.readLine()) != null) {
toReturn += ligne;
}
fichier.close();
} catch (IOException e) {
e.printStackTrace();
}
toRet.cases=toReturn;
toRet.taille=dimension;
return toRet;
}
public class SaveData{
public Dimension taille;
public String cases;
public SaveData(Dimension taille, String cases) {
this.taille = taille;
this.cases = cases;
}
public String toString() {
return (int) taille.getWidth()+"x"+(int) taille.getHeight()+"\n"+cases;
}
}
}

9
SaveTester.java Normal file
View File

@ -0,0 +1,9 @@
public class SaveTester {
public static void main(String[] args) {
Grille grille = new Grille(10,10,10, null, null);
SaveManager saveManager = new SaveManager();
saveManager.save(grille, "test_sauvegarde.txt");
SaveManager.SaveData donnees = saveManager.load("test_sauvegarde.txt");
}
}

2
test_sauvegarde.txt Normal file
View File

@ -0,0 +1,2 @@
10x10
0010000000000000001000000000000001010000000000000010000000000100001000000000000000000001100000000100