ajout de la sauvegarde
This commit is contained in:
parent
b0973b26ab
commit
9fc54e030e
BIN
CASE/Case.class
BIN
CASE/Case.class
Binary file not shown.
@ -13,7 +13,6 @@ public class Case extends JComponent{
|
||||
private int voisin; //Le nombre de mine aux alentours
|
||||
private int suspition; // son Etat de suspition ( 0:pas une bombe, 1:en est une, 2:je doute)
|
||||
// Les Images de la case (point d'interogation, etoile et bombe)
|
||||
private Image interogation, etoile, imgboombe, un, deux, trois, quatre, cinq, six, sept, huit;
|
||||
|
||||
//Constructeur de la Case
|
||||
public Case(){
|
||||
@ -22,19 +21,6 @@ public class Case extends JComponent{
|
||||
this.bombe=false; // ce n'est pas une bombe
|
||||
this.voisin=0; // elle n'a pas de voisin bombe
|
||||
this.suspition=0; // la suspition est a 0 (pas une bombe)
|
||||
|
||||
// nous chargeons les images
|
||||
this.interogation= Toolkit.getDefaultToolkit().getImage("./IMAGE/pointintero.png");
|
||||
this.etoile= Toolkit.getDefaultToolkit().getImage("./IMAGE/etoile.png");
|
||||
this.imgboombe= Toolkit.getDefaultToolkit().getImage("./IMAGE/bombe.png");
|
||||
this.un=Toolkit.getDefaultToolkit().getImage("./IMAGE/un.jpg");
|
||||
this.deux=Toolkit.getDefaultToolkit().getImage("./IMAGE/deux.jpg");
|
||||
this.trois=Toolkit.getDefaultToolkit().getImage("./IMAGE/trois.jpg");
|
||||
this.quatre=Toolkit.getDefaultToolkit().getImage("./IMAGE/quatre.jpg");
|
||||
this.cinq=Toolkit.getDefaultToolkit().getImage("./IMAGE/cinq.jpg");
|
||||
this.six=Toolkit.getDefaultToolkit().getImage("./IMAGE/six.jpg");
|
||||
this.sept=Toolkit.getDefaultToolkit().getImage("./IMAGE/sept.jpg");
|
||||
this.huit=Toolkit.getDefaultToolkit().getImage("./IMAGE/huit.jpg");
|
||||
}
|
||||
|
||||
// Nous mettons les getter/setter
|
||||
@ -101,12 +87,14 @@ public class Case extends JComponent{
|
||||
//si on supecte que c'est une bome
|
||||
if(this.suspition==1){
|
||||
//on affiche l'etoile
|
||||
secondPinceau.drawImage(this.etoile, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
Image etoile= Toolkit.getDefaultToolkit().getImage("./IMAGE/etoile.png");
|
||||
secondPinceau.drawImage(etoile, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
}
|
||||
//si on suspecte que on ne sais pas
|
||||
if(this.suspition==2){
|
||||
Image interogation= Toolkit.getDefaultToolkit().getImage("./IMAGE/pointintero.png");
|
||||
//on affiche le point d'interogation
|
||||
secondPinceau.drawImage(this.interogation, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
secondPinceau.drawImage(interogation, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
}
|
||||
}
|
||||
//si la case est afficher(visible)
|
||||
@ -116,42 +104,50 @@ public class Case extends JComponent{
|
||||
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
secondPinceau.setColor(new Color(255, 255, 255));
|
||||
secondPinceau.fillRect(this.getWidth()/20, this.getHeight()/20, this.getWidth()/20*18, this.getHeight()/20*18);
|
||||
secondPinceau.setColor(new Color(255, 0, 0));
|
||||
//si la case a au moins 1 voisin qui est une bombe
|
||||
if(this.voisin>0){
|
||||
//on ecrit le nombre de voisin que elle a
|
||||
if(this.voisin==1){
|
||||
secondPinceau.drawImage(this.un, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
Image un=Toolkit.getDefaultToolkit().getImage("./IMAGE/un.jpg");
|
||||
secondPinceau.drawImage(un, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
}
|
||||
if(this.voisin==2){
|
||||
secondPinceau.drawImage(this.deux, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
Image deux=Toolkit.getDefaultToolkit().getImage("./IMAGE/deux.jpg");
|
||||
secondPinceau.drawImage(deux, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
}
|
||||
if(this.voisin==3){
|
||||
secondPinceau.drawImage(this.trois, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
Image trois=Toolkit.getDefaultToolkit().getImage("./IMAGE/trois.jpg");
|
||||
secondPinceau.drawImage(trois, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
}
|
||||
if(this.voisin==4){
|
||||
secondPinceau.drawImage(this.quatre, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
Image quatre=Toolkit.getDefaultToolkit().getImage("./IMAGE/quatre.jpg");
|
||||
secondPinceau.drawImage(quatre, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
}
|
||||
if(this.voisin==5){
|
||||
secondPinceau.drawImage(this.cinq, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
Image cinq=Toolkit.getDefaultToolkit().getImage("./IMAGE/cinq.jpg");
|
||||
secondPinceau.drawImage(cinq, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
}
|
||||
if(this.voisin==6){
|
||||
secondPinceau.drawImage(this.six, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
Image six=Toolkit.getDefaultToolkit().getImage("./IMAGE/six.jpg");
|
||||
secondPinceau.drawImage(six, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
}
|
||||
if(this.voisin==7){
|
||||
secondPinceau.drawImage(this.sept, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
Image sept=Toolkit.getDefaultToolkit().getImage("./IMAGE/sept.jpg");
|
||||
secondPinceau.drawImage(sept, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
}
|
||||
if(this.voisin==8){
|
||||
secondPinceau.drawImage(this.huit, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
Image huit=Toolkit.getDefaultToolkit().getImage("./IMAGE/huit.jpg");
|
||||
secondPinceau.drawImage(huit, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
}
|
||||
}
|
||||
//si la case est une bombe
|
||||
if(this.bombe==true){
|
||||
Image imgboombe= Toolkit.getDefaultToolkit().getImage("./IMAGE/bombe.png");
|
||||
//on remplace le rectangle blanc par un rectangle rouge
|
||||
secondPinceau.setColor(new Color(255,0,125));
|
||||
secondPinceau.fillRect(this.getWidth()/20, this.getHeight()/20, this.getWidth()/20*18, this.getHeight()/20*18);
|
||||
//on affiche la bombe
|
||||
secondPinceau.drawImage(this.imgboombe, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
secondPinceau.drawImage(imgboombe, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 14 KiB |
Binary file not shown.
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 36 KiB |
Binary file not shown.
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 14 KiB |
@ -9,7 +9,8 @@ OFILES= Case.class\
|
||||
plateau.class\
|
||||
observateurCase.class\
|
||||
paintMenuJeu.class\
|
||||
observateurSAV.class
|
||||
observateurSAV.class\
|
||||
observateurFenetre.class
|
||||
|
||||
CFLAGS= -implicit:none
|
||||
|
||||
@ -29,6 +30,9 @@ paintMenuJeu.class: paintMenuJeu.java
|
||||
observateurSAV.class: observateurSAV.java
|
||||
javac $(CFLAGS) observateurSAV.java
|
||||
|
||||
observateurFenetre.class: observateurFenetre.java
|
||||
javac $(CFLAGS) observateurFenetre.java
|
||||
|
||||
# Chapitre 4 : Dependances
|
||||
|
||||
main_ex.class: $(OFILES) main_ex.java
|
||||
|
Binary file not shown.
@ -10,9 +10,9 @@ public class main_ex{
|
||||
public static void main(String[] Args){
|
||||
// on initialise une fenettre
|
||||
JFrame fenetre = new JFrame("Démineur");
|
||||
int ligne=10;
|
||||
int collonne=20;
|
||||
int bombe=12;
|
||||
int ligne=5;
|
||||
int collonne=10;
|
||||
int bombe=10;
|
||||
fenetre.setLocation(0,0);
|
||||
fenetre.setSize(1500,500);
|
||||
fenetre.setVisible(true);
|
||||
@ -20,6 +20,6 @@ public class main_ex{
|
||||
|
||||
//nous utiliserons un gestionnaire GridLayout de dimensions choisi précédament
|
||||
plateau jeu = new plateau(fenetre);
|
||||
jeu.newGame(10,20,12);
|
||||
jeu.reprendrePartie();
|
||||
}
|
||||
}
|
BIN
CASE/observateurFenetre.class
Normal file
BIN
CASE/observateurFenetre.class
Normal file
Binary file not shown.
30
CASE/observateurFenetre.java
Normal file
30
CASE/observateurFenetre.java
Normal file
@ -0,0 +1,30 @@
|
||||
import java.awt.event.*;
|
||||
|
||||
public class observateurFenetre implements WindowListener{
|
||||
private plateau plat;
|
||||
public observateurFenetre(plateau plat0){
|
||||
this.plat=plat0;
|
||||
}
|
||||
|
||||
public void windowActivated(WindowEvent evenement){
|
||||
|
||||
} // premier plan
|
||||
public void windowClosed(WindowEvent evenement){
|
||||
|
||||
} // après fermeture
|
||||
public void windowClosing(WindowEvent evenement){
|
||||
this.plat.save();
|
||||
} // avant fermeture
|
||||
public void windowDeactivated(WindowEvent evenement){
|
||||
|
||||
} // arrière-plan
|
||||
public void windowDeiconified(WindowEvent evenement){
|
||||
|
||||
} // restauration
|
||||
public void windowIconified(WindowEvent evenement){
|
||||
|
||||
} // minimisation
|
||||
public void windowOpened(WindowEvent evenement){
|
||||
|
||||
} // après ouverture
|
||||
}
|
Binary file not shown.
@ -17,7 +17,7 @@ public class observateurSAV implements MouseListener{
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent evenement){
|
||||
if(this.fonction==false){
|
||||
plat.getFenetre().dispose();
|
||||
plat.save();
|
||||
}
|
||||
if(this.fonction==true){
|
||||
plat.newGame(plat.getLigne(), plat.getCollonne(), plat.getBombe());
|
||||
|
Binary file not shown.
@ -4,12 +4,13 @@ import javax.swing.JComponent;
|
||||
|
||||
public class paintMenuJeu extends JComponent{
|
||||
private int choix;
|
||||
private int score;
|
||||
private int scoreMax, score;
|
||||
private Image un, deux, trois, quatre, cinq, six, sept, huit, neuf, zero, err, sav, lose, win, replay;
|
||||
private boolean survol;
|
||||
public paintMenuJeu(int choix0, int score0){
|
||||
this.choix=choix0;
|
||||
this.score=score0;
|
||||
this.scoreMax=score0;
|
||||
this.un=Toolkit.getDefaultToolkit().getImage("./IMAGE/unD.png");
|
||||
this.deux=Toolkit.getDefaultToolkit().getImage("./IMAGE/deuxD.png");
|
||||
this.trois=Toolkit.getDefaultToolkit().getImage("./IMAGE/troisD.png");
|
||||
@ -42,6 +43,9 @@ public class paintMenuJeu extends JComponent{
|
||||
this.survol=survol0;
|
||||
this.repaint();
|
||||
}
|
||||
public int getScoreMax(){
|
||||
return this.scoreMax;
|
||||
}
|
||||
@Override
|
||||
protected void paintComponent(Graphics pinceau) {
|
||||
// obligatoire : on crée un nouveau pinceau pour pouvoir le modifier plus tard
|
||||
|
Binary file not shown.
@ -2,9 +2,10 @@
|
||||
//Class pour des fonction static de jeu
|
||||
//V2
|
||||
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
@ -191,15 +192,15 @@ public class plateau{
|
||||
for(int i=0; i<collonne; i++){
|
||||
paintMenuJeu menu= new paintMenuJeu(0, bombe);
|
||||
menu.setPreferredSize(new Dimension(100,100));
|
||||
if(i==1){
|
||||
if(i==0){
|
||||
this.tabScore[0]=menu;
|
||||
menu.setChoix(1);
|
||||
}
|
||||
if(i==2){
|
||||
if(i==1){
|
||||
this.tabScore[1]=menu;
|
||||
menu.setChoix(2);
|
||||
}
|
||||
if(i==3){
|
||||
if(i==2){
|
||||
this.tabScore[2]=menu;
|
||||
menu.setChoix(3);
|
||||
}
|
||||
@ -227,10 +228,96 @@ public class plateau{
|
||||
fenetre.add(this.tableau[i][t]);
|
||||
}
|
||||
}
|
||||
fenetre.addWindowListener(new observateurFenetre(this));
|
||||
//nous disposons les bombe dans le jeu
|
||||
this.setAllBombe();
|
||||
//maitenant que les bombe sont mise nous pouvons modifier le nombre de voisin des cases
|
||||
this.setAllVoisin();
|
||||
this.fenetre.pack();
|
||||
}
|
||||
public void save(){
|
||||
try{
|
||||
OutputStream sav = new FileOutputStream(new File("sauvegarde.data"));
|
||||
ObjectOutputStream oos = new ObjectOutputStream(sav);
|
||||
oos.writeInt(this.ligne);
|
||||
oos.writeInt(this.collonne);
|
||||
for(int i=0; i<this.ligne; i++){
|
||||
for(int t=0; t<this.collonne; t++){
|
||||
oos.writeObject(this.tableau[i][t]);
|
||||
}
|
||||
}
|
||||
oos.writeInt(this.tabScore[0].getScoreMax());
|
||||
oos.writeInt(this.tabScore[0].getScore());
|
||||
oos.close();
|
||||
sav.close();
|
||||
}catch(FileNotFoundException e1){
|
||||
}catch(IOException e2){
|
||||
}
|
||||
this.fenetre.dispose();
|
||||
|
||||
}
|
||||
public void reprendrePartie(){
|
||||
int score=0;
|
||||
try{
|
||||
FileInputStream file = new FileInputStream("./sauvegarde.data");
|
||||
ObjectInputStream ois = new ObjectInputStream(file);
|
||||
this.ligne=ois.readInt();
|
||||
this.collonne=ois.readInt();
|
||||
this.tableau=new Case[this.ligne][this.collonne];
|
||||
for(int i=0; i<ligne; i++){
|
||||
for(int t=0; t<collonne; t++){
|
||||
this.tableau[i][t]=(Case) ois.readObject();
|
||||
}
|
||||
}
|
||||
this.bombe=ois.readInt();
|
||||
score=ois.readInt();
|
||||
}catch(FileNotFoundException e1){
|
||||
System.out.println("FNF");
|
||||
}catch(IOException e2){
|
||||
System.out.println("IOE");
|
||||
}catch(ClassNotFoundException e3){
|
||||
System.out.println("CNF");
|
||||
}
|
||||
this.fenetre.dispose();
|
||||
this.fenetre=new JFrame("démineur");
|
||||
GridLayout grille = new GridLayout(ligne+1,collonne);
|
||||
for(int i=0; i<collonne; i++){
|
||||
paintMenuJeu menu= new paintMenuJeu(0, score);
|
||||
menu.setPreferredSize(new Dimension(100,100));
|
||||
if(i==0){
|
||||
this.tabScore[0]=menu;
|
||||
menu.setChoix(1);
|
||||
}
|
||||
if(i==1){
|
||||
this.tabScore[1]=menu;
|
||||
menu.setChoix(2);
|
||||
}
|
||||
if(i==2){
|
||||
this.tabScore[2]=menu;
|
||||
menu.setChoix(3);
|
||||
}
|
||||
if(i==collonne-1){
|
||||
menu.setChoix(4);
|
||||
this.setLogo(menu);
|
||||
observateurSAV observateur=new observateurSAV(menu, this);
|
||||
menu.addMouseListener(observateur);
|
||||
this.setObservateur(observateur);
|
||||
}
|
||||
fenetre.add(menu);
|
||||
}
|
||||
fenetre.setLayout(grille);
|
||||
// l'application ne se fermera que si on clique sur
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
fenetre.setVisible(true);
|
||||
fenetre.addWindowListener(new observateurFenetre(this));
|
||||
for(int i=0; i<ligne; i++){
|
||||
for(int t=0;t<collonne; t++){
|
||||
this.fenetre.add(this.tableau[i][t]);
|
||||
this.tableau[i][t].repaint();
|
||||
this.tableau[i][t].addMouseListener(new observateurCase(i, t, this.tableau, this));
|
||||
}
|
||||
}
|
||||
this.fenetre.pack();
|
||||
}
|
||||
|
||||
}
|
BIN
CASE/sauvegarde.data
Executable file
BIN
CASE/sauvegarde.data
Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user