diff --git a/Avancee.odt b/Avancee.odt index 71f882a..419e9ca 100644 Binary files a/Avancee.odt and b/Avancee.odt differ diff --git a/Banniere.java b/Banniere.java index 623e2db..504f464 100644 --- a/Banniere.java +++ b/Banniere.java @@ -5,6 +5,7 @@ public class Banniere extends JPanel { private FrameJeu fenetre; private FrameMenu menu; private JButton save; + private JLabel mines; // Définition du constructeur public Banniere(int mines, FrameJeu fenetre, FrameMenu menu, Grille grille) { super(); @@ -16,6 +17,11 @@ public class Banniere extends JPanel { this.setBackground(new Color(0, 236, 96)); this.setLayout(new BorderLayout()); + // Compteur de mines restantes + + this.mines= new JLabel(); + this.add(this.mines, BorderLayout.NORTH); + // Bouton pour sauver et quitter this.save = new JButton("Sauver et quitter"); save.addActionListener(new SaveListener(grille, fenetre)); @@ -24,8 +30,7 @@ public class Banniere extends JPanel { // Méthode pour afficher le nombre de mines restantes public void setMinesLeft(int minesLeft) { - JLabel mines = new JLabel("Mines restantes : "+Integer.toString(minesLeft)); - this.add(mines, BorderLayout.NORTH); + this.mines.setText("Mines restantes : "+Integer.toString(minesLeft)); this.repaint(); } diff --git a/Chargement.java b/Chargement.java new file mode 100644 index 0000000..b0c24ad --- /dev/null +++ b/Chargement.java @@ -0,0 +1,16 @@ +import java.awt.event.*; +public class Chargement implements ActionListener { + private FrameMenu menu; + public Chargement(FrameMenu menu){ + this.menu=menu; + } + + @Override + public void actionPerformed(ActionEvent e) { + this.menu.dispose(); + SaveManager saveManager = new SaveManager(); + SaveManager.SaveData donnees = saveManager.load("Save.txt"); + System.out.println(donnees); + } + +} diff --git a/FrameMenu.java b/FrameMenu.java index 71cabdf..c8dd14b 100644 --- a/FrameMenu.java +++ b/FrameMenu.java @@ -1,5 +1,6 @@ import javax.swing.*; import java.awt.event.*; +import java.io.File; import java.awt.*; // Cette classe à pour but d'afficher un menu et de réagir aux directives de l'utilisateur (lancer le jeu, le quitter...) @@ -71,7 +72,7 @@ public class FrameMenu extends JFrame{ JButton newGame = new JButton("Jouer"); newGame.addActionListener(new NewGameListener(this)); - newGame.setBounds(frameSize.width*10/15, frameSize.height*12/15, frameSize.width/5, frameSize.height/15);; + newGame.setBounds(frameSize.width*7/10, frameSize.height*12/15, frameSize.width/5, frameSize.height/15);; this.add(newGame); JButton exit = new JButton("Quitter"); @@ -83,8 +84,15 @@ public class FrameMenu extends JFrame{ exit.setBounds(frameSize.width/10, frameSize.height*12/15, frameSize.width/5, frameSize.height/15); this.add(exit); + + File save = new File("Save.txt"); + if(save.exists()){ + JButton charger = new JButton("Charger"); + charger.addActionListener(new Chargement(this)); + charger.setBounds(frameSize.width*4/10, frameSize.height*12/15, frameSize.width/5, frameSize.height/15); + this.add(charger); + } - //TODO : Bouton charger this.setResizable(false); this.setVisible(true); } diff --git a/MenuListener.java b/MenuListener.java index b055a28..96b9a84 100644 --- a/MenuListener.java +++ b/MenuListener.java @@ -10,6 +10,8 @@ public class MenuListener implements ActionListener{ @Override public void actionPerformed(ActionEvent event){ this.menu.setVisible(true); + WindowListener[] wl= this.fenetre.getWindowListeners(); + this.fenetre.removeWindowListener(wl[0]); this.fenetre.dispose(); } } \ No newline at end of file diff --git a/SaveAndCloseListener.java b/SaveAndCloseListener.java index d3694bb..a8dfeaf 100644 --- a/SaveAndCloseListener.java +++ b/SaveAndCloseListener.java @@ -13,7 +13,6 @@ public class SaveAndCloseListener implements WindowListener{ public void windowClosing(WindowEvent e) { SaveManager saveManager = new SaveManager(); saveManager.save(this.grille, "Save.txt"); - SaveManager.SaveData donnees = saveManager.load("Save.txt"); } diff --git a/SaveListener.java b/SaveListener.java index 81bca43..2117de5 100644 --- a/SaveListener.java +++ b/SaveListener.java @@ -11,7 +11,6 @@ public class SaveListener implements ActionListener { public void actionPerformed(ActionEvent event){ SaveManager saveManager = new SaveManager(); saveManager.save(this.grille, "Save.txt"); - SaveManager.SaveData donnees = saveManager.load("Save.txt"); this.fenetre.dispose(); } } diff --git a/SaveManager.java b/SaveManager.java index ddb8a09..9629d98 100644 --- a/SaveManager.java +++ b/SaveManager.java @@ -49,6 +49,9 @@ public class SaveManager { e.printStackTrace(); } + File save = new File(nomFichier); + save.delete(); + toRet.cases=toReturn; toRet.taille=dimension; return toRet; diff --git a/SaveTester.java b/SaveTester.java deleted file mode 100644 index ec016e9..0000000 --- a/SaveTester.java +++ /dev/null @@ -1,9 +0,0 @@ -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"); - } -} \ No newline at end of file