ajout fichier final
							
								
								
									
										
											BIN
										
									
								
								Case.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										172
									
								
								Case.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,172 @@ | ||||
| // Tom Monin et Clément Martins | ||||
| // paintChoix V3 | ||||
| // class représentant une case dans la partie | ||||
|  | ||||
| import java.awt.*; | ||||
| import javax.swing.*; | ||||
| import javax.swing.JComponent; | ||||
|  | ||||
| public class Case extends JComponent{ | ||||
| 	//Etat de la case: | ||||
| 	private boolean visibilite; 	//Visible ou pas | ||||
| 	private boolean bombe;			//Miner ou pas | ||||
| 	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...) ne sont pas des attributs de la classe Case car | ||||
| 	//pour faciliter la sauvegarde et donc permettre de sérialiser l'objet les attribut devrons être des classes réalisant Serializable ou Externialisable | ||||
|  | ||||
| 	//Constructeur de la Case | ||||
| 	public Case(){ | ||||
| 		//nous initialisons les valeurs | ||||
| 		this.visibilite=false;		//la visibiler est fausse donc la case est cacher | ||||
| 		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 mettons les getter/setter | ||||
|  | ||||
| 	public void setVisibiliter(boolean trueorfalse){ | ||||
| 		this.visibilite=trueorfalse; | ||||
| 	} | ||||
| 	public void setBombe(){ | ||||
| 		this.bombe=true; | ||||
| 	} | ||||
| 	public void suspition(){ | ||||
| 		this.suspition++; | ||||
| 		if(this.suspition==3){ | ||||
| 			this.suspition=0; | ||||
| 		} | ||||
| 	} | ||||
| 	public void setSuspition(int n){ | ||||
| 		this.suspition=n; | ||||
| 		//valeur sentinel pour montrer que c'est cette case qui a exploser | ||||
| 	} | ||||
| 	public boolean getBombe(){ | ||||
| 		return this.bombe; | ||||
| 	} | ||||
| 	public void setVoisin(int nvoisin){ | ||||
| 		this.voisin=nvoisin; | ||||
| 	} | ||||
| 	public int getSuspition(){ | ||||
| 		return this.suspition; | ||||
| 	} | ||||
| 	public boolean getVisibiliter(){ | ||||
| 		return this.visibilite; | ||||
| 	} | ||||
| 	public int getVoisin(){ | ||||
| 		return this.voisin; | ||||
| 	} | ||||
|  | ||||
| 	//on paint la case en fonction de ses attribut et donc son etat | ||||
|   	@Override | ||||
| 	protected void paintComponent(Graphics pinceau) { | ||||
|     	// obligatoire : on crée un nouveau pinceau pour pouvoir le modifier plus tard | ||||
|     	Graphics secondPinceau = pinceau.create(); | ||||
|     	// obligatoire : si le composant n'est pas censé être transparent | ||||
|     	if (this.isOpaque()) { | ||||
|       	// obligatoire : on repeint toute la surface avec la couleur de fond | ||||
|       	secondPinceau.setColor(this.getBackground()); | ||||
|       	secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight()); | ||||
|     	} | ||||
|     	//On paint ce que l'on veut maintenant | ||||
|     	//si la case est cacher (pas visible) | ||||
|     	if(this.visibilite==false){ | ||||
|     		//on dessinne un rectangle gris sur un fond noir | ||||
|     		secondPinceau.setColor(new Color(0,0,0)); | ||||
|     		secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight()); | ||||
|     		secondPinceau.setColor(new Color(100, 100, 100)); | ||||
|     		secondPinceau.fillRect(this.getWidth()/20, this.getHeight()/20, this.getWidth()/20*18, this.getHeight()/20*18); | ||||
|     		//si on supecte que c'est une bome | ||||
|     		if(this.suspition==1){ | ||||
|     			//on affiche l'etoile | ||||
|     			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(interogation, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this); | ||||
|     		} | ||||
|     	} | ||||
|     	//si la case est afficher(visible) | ||||
|     	if(this.visibilite==true){ | ||||
|     		//on dessine un rectangle blanc sur un fond noir | ||||
|     		secondPinceau.setColor(new Color(0,0,0)); | ||||
|     		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); | ||||
|     		//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){ | ||||
|     				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){ | ||||
|     				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){ | ||||
|     				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){ | ||||
|     				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){ | ||||
|     				Image cinq=Toolkit.getDefaultToolkit().getImage("./IMAGE/cinq.png"); | ||||
|     				secondPinceau.drawImage(cinq, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this); | ||||
|     			} | ||||
|     			if(this.voisin==6){ | ||||
|     				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){ | ||||
|     				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){ | ||||
|     				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 supecter mais visible (possible que si le joueur a perdu) et que ce n'est pas une bombe | ||||
|     			//on affiche un fond rouge pour mettre en valeur l'erreur | ||||
|     			if(this.suspition==1 && this.bombe==false){ | ||||
|     				secondPinceau.setColor(new Color(255, 0, 0)); | ||||
|     				secondPinceau.fillRect(this.getWidth()/20, this.getHeight()/20, this.getWidth()/20*18, this.getHeight()/20*18); | ||||
|     				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 la case est une bombe | ||||
|     		if(this.bombe==true){ | ||||
|     			//si la bombe est suspecter mais afficher (possible que si le joeur perd) | ||||
|     			if(this.suspition==1){ | ||||
|     				//on affiche l'etoile sur fond vert pour préciser que le joueur avait raison | ||||
|     				secondPinceau.setColor(new Color(0, 255, 0)); | ||||
|     				secondPinceau.fillRect(this.getWidth()/20, this.getHeight()/20, this.getWidth()/20*18, this.getHeight()/20*18); | ||||
|     				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); | ||||
|   					//autrement nous afficherons l'image de la bombe | ||||
|     			}else{ | ||||
|     				Image imgboombe= Toolkit.getDefaultToolkit().getImage("./IMAGE/bombe.png"); | ||||
|     				//si la suspition est de 4 (possible que si c'est la bombe qui a exploser) valeur sentinelle | ||||
|     				if(this.suspition==4){ | ||||
|     					//on dessine un rectangle rouge | ||||
|     					secondPinceau.setColor(new Color(255,0,0)); | ||||
|     					secondPinceau.fillRect(this.getWidth()/20, this.getHeight()/20, this.getWidth()/20*18, this.getHeight()/20*18); | ||||
|     				}else{ | ||||
|     					//on dessine un rectangle orange pour montrer que la case était une bombe | ||||
|     					secondPinceau.setColor(new Color(200, 127, 0)); | ||||
|     					secondPinceau.fillRect(this.getWidth()/20, this.getHeight()/20, this.getWidth()/20*18, this.getHeight()/20*18); | ||||
|     				} | ||||
|     				//on affiche la bombe | ||||
|     				secondPinceau.drawImage(imgboombe, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this); | ||||
|     			} | ||||
|     		} | ||||
|     	} | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								IMAGE/bombe.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 5.5 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/cinq.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 22 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/cinqD.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 20 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/deux.jpg
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 18 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/deuxD.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 18 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/err.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 17 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/etoile.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 5.7 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/huit.jpg
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 20 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/huitD.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 17 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/lose.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 66 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/neufD.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 19 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/nouveau.jpg
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 40 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/pointintero.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 35 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/quatre.jpg
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 16 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/quatreD.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 15 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/quitter.jpg
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 40 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/replay.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 36 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/reprendre.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 83 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/sav.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 14 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/sept.jpg
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 15 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/septD.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 13 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/six.jpg
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 19 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/sixD.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 18 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/trois.jpg
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 18 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/troisD.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 18 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/un.jpg
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 15 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/unD.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 9.9 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/win.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 75 KiB | 
							
								
								
									
										
											BIN
										
									
								
								IMAGE/zeroD.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 20 KiB | 
							
								
								
									
										64
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,64 @@ | ||||
| # PROJET DÉMINEUR MAKEFILE: | ||||
| # | ||||
| #  Chapitre 1: But final; | ||||
|  | ||||
| but: main_ex.class | ||||
|  | ||||
| # Chapitre 2 : Variable | ||||
| OFILES= Case.class\ | ||||
| 		plateau.class\ | ||||
| 		observateurCase.class\ | ||||
| 		paintMenuJeu.class\ | ||||
| 		observateurSAV.class\ | ||||
| 		observateurFenetre.class\ | ||||
| 		paintChoix.class\ | ||||
| 		observateurChoix.class\ | ||||
| 		observateurButtonEtText.class | ||||
|  | ||||
| CFLAGS= -implicit:none | ||||
|  | ||||
| # Chapitre 3 : Dependances (règle implicite): | ||||
| Case.class: Case.java  | ||||
| 	javac $(CFLAGS) Case.java | ||||
|  | ||||
| plateau.class : plateau.java | ||||
| 	javac $(CFLAGS) plateau.java | ||||
|  | ||||
| observateurCase.class : observateurCase.java | ||||
| 	javac $(CFLAGS) observateurCase.java | ||||
|  | ||||
| paintMenuJeu.class: paintMenuJeu.java | ||||
| 	javac $(CFLAGS) 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 | ||||
| 	javac $(CFLAGS) main_ex.java | ||||
|  | ||||
| paintChoix.class: paintChoix.java | ||||
| 	javac $(CFLAGS) paintChoix.java | ||||
|  | ||||
| observateurChoix.class: observateurChoix.java | ||||
| 	javac $(CFLAGS) observateurChoix.java | ||||
|  | ||||
| observateurButtonEtText.class: observateurButtonEtText.java | ||||
| 	javac $(CFLAGS) observateurButtonEtText.java | ||||
|  | ||||
| #Chapitre 5: nettoyage des fichiers generes | ||||
|  | ||||
| clean :  | ||||
| 	-rm -f $(OFILES) main_ex.class | ||||
|  | ||||
| run : | ||||
| 	java main_ex | ||||
| #chapitre 6 : buts factices | ||||
|  | ||||
| .PHONY : but clean | ||||
|  | ||||
| .PHONY : but run | ||||
							
								
								
									
										
											BIN
										
									
								
								main_ex.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										17
									
								
								main_ex.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,17 @@ | ||||
| // Tom Monint et Clément Martins | ||||
| // main_ex V4 | ||||
| // Classe ayant pour but d'être executer | ||||
|  | ||||
| //importons les packages necessaires | ||||
| import javax.swing.*; | ||||
|  | ||||
| public class main_ex{ | ||||
| 	public static void main(String[] Args){ | ||||
| 		// on initialise une fenettre | ||||
| 		JFrame fenetre = new JFrame("Démineur"); | ||||
| 		//on créé notre plateau de jeu | ||||
| 		plateau jeu = new plateau(fenetre); | ||||
| 		//on lance a l'aide de celui-ci le 1er menu | ||||
| 		jeu.menuChoixTypePartie(); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								observateurButtonEtText.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										173
									
								
								observateurButtonEtText.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,173 @@ | ||||
| //Clément Martins et Tom Monin | ||||
| //Class utiliser pour observateur avec plusieur action possible (en fonction de sa fonction défini a la création)  | ||||
| import java.awt.event.*; | ||||
| import javax.swing.*; | ||||
| import java.awt.*; | ||||
|  | ||||
| public class observateurButtonEtText implements ActionListener { | ||||
|   private plateau plat;   //le plateau de jeu | ||||
|   private int fonction;   //la fonction de l'observateur | ||||
|   private JTextField zone;  // la zone de texte a modifier | ||||
|  | ||||
|   //constructeur | ||||
|   //@params (le plateau, la fonction, la zone de texte) | ||||
|   public observateurButtonEtText(plateau plat0, int fonction0, JTextField zone0){ | ||||
|     //on initialise les attributs | ||||
|     this.plat=plat0; | ||||
|     this.fonction=fonction0; | ||||
|     this.zone=zone0; | ||||
|   } | ||||
|   @Override | ||||
|   public void actionPerformed(ActionEvent evenement){ | ||||
|     //si fonction 1 on va adapter la zone de texte en fonction de son contenu | ||||
|     if(this.fonction==1){ | ||||
|       int nombre=0; | ||||
|       //try catch pour le parseInt pour voir si le format correspond | ||||
|       //tant que le format est bon: | ||||
|       try{ | ||||
|         //on met le fond du texte en blanc | ||||
|         this.zone.setBackground(new Color(255,255,255)); | ||||
|         //on recupere le nombre contenu dans le text | ||||
|         nombre=Integer.parseInt(evenement.getActionCommand()); | ||||
|         //si il est inferieur a 0 | ||||
|         if(nombre<0){ | ||||
|           //je le met sur 0 (min de bombe) | ||||
|           nombre=0; | ||||
|         } | ||||
|         //si les collonnes et les ligne ne sont pas encore selectionner | ||||
|         //vu par les valeur sentinnelles (-1) | ||||
|         if(this.plat.getLigne()!=-1 && this.plat.getCollonne()!=-1){ | ||||
|           //si il y a plus de bombe que de case | ||||
|           if(nombre>this.plat.getLigne()*this.plat.getCollonne()){ | ||||
|             //on repositionne le nombre de bombe au maximun | ||||
|             nombre=this.plat.getLigne()*this.plat.getCollonne(); | ||||
|           } | ||||
|           //on affiche le nombre dans la zone de text | ||||
|           this.zone.setText(String.valueOf(nombre)); | ||||
|         }else{ | ||||
|           //si les ligne et les collonnes ne sont pas encore selectionner | ||||
|           //fond e rouge | ||||
|           this.zone.setBackground(Color.red); | ||||
|           //on précise a l'utilisateur se que l'ont veut | ||||
|           this.zone.setText("Selectionner Ligne et Collonne Avant"); | ||||
|           //on précisera au plateau que le choix des bombes n'est plus bon | ||||
|           //par une valeur sentinnelles | ||||
|           //pour eviter de garder l'ancien nombre si il y en avait un | ||||
|           nombre=-1; | ||||
|         } | ||||
|         //on dis au plateau le nombre de bombe | ||||
|         this.plat.setBombe(nombre); | ||||
|       }catch(NumberFormatException e1){ | ||||
|         //si le format n'est pas bon | ||||
|         //fond en rouge | ||||
|         this.zone.setBackground(Color.red); | ||||
|         //on précise a l'utilisateur l'erreur | ||||
|         this.zone.setText("rentrer un entier"); | ||||
|         //on précisera au plateau que le choix des bombes n'est plus bon | ||||
|         //par une valeur sentinnelles | ||||
|         //pour eviter de garder l'ancien nombre si il y en avait un | ||||
|         this.plat.setBombe(-1); | ||||
|       } | ||||
|     } | ||||
|     //si la fonction est 2 | ||||
|     if(this.fonction==2){ | ||||
|       int nombre=0; | ||||
|       //try catch pour les format pas bon | ||||
|       //tant que il n'y a pas d'Exception | ||||
|       try{ | ||||
|         //fond en blanc | ||||
|         this.zone.setBackground(new Color(255,255,255)); | ||||
|         //le nombre est = au nombre dans la zone de texte | ||||
|         nombre=Integer.parseInt(this.zone.getText()); | ||||
|         //si inferieur a 0 | ||||
|         if(nombre<0){ | ||||
|           //nombre a 0 (min de bombe) | ||||
|           nombre=0; | ||||
|         } | ||||
|         //si collonne et ligne deja existant | ||||
|         if(this.plat.getLigne()!=-1 && this.plat.getCollonne()!=-1){ | ||||
|           //si ce nombre > nb de Case | ||||
|           if(nombre>this.plat.getLigne()*this.plat.getCollonne()){ | ||||
|             //nombre = nombre max de bombe | ||||
|             nombre=this.plat.getLigne()*this.plat.getCollonne(); | ||||
|           } | ||||
|           //on précise au plateau le nombre de bombe | ||||
|           this.plat.setBombe(nombre); | ||||
|           //si il tout est deja initialiser (ligne, collonne et bombe) | ||||
|           if(this.plat.getLigne()!=-1 && this.plat.getCollonne()!=-1 && this.plat.getBombe()!=-1){ | ||||
|             //on lance la nouvelle partie | ||||
|             this.plat.newGame(); | ||||
|           }else{ | ||||
|             //autrement  | ||||
|             if(this.plat.getBombe()==-1){ | ||||
|             this.zone.setBackground(Color.red); | ||||
|             this.zone.setText("Rentrer un nombre de Bombe"); | ||||
|             } | ||||
|           } | ||||
|         }else{ | ||||
|           this.zone.setBackground(Color.red); | ||||
|           this.zone.setText("Selectionner Ligne et Collonne Avant"); | ||||
|           this.plat.setBombe(-1); | ||||
|         } | ||||
|         this.plat.setBombe(nombre); | ||||
|       }catch(NumberFormatException e1){ | ||||
|         this.zone.setBackground(Color.red); | ||||
|         this.zone.setText("rentrer un entier"); | ||||
|         this.plat.setBombe(-1); | ||||
|       } | ||||
|     } | ||||
|     if(this.fonction==3){ | ||||
|       //si fonction 3 donc boutons + | ||||
|       //plusoumoins avec comme argument +1 | ||||
|      this.plusoumoins(1); | ||||
|     } | ||||
|     if(this.fonction==4){ | ||||
|       //si fonction 4 donc boutons - | ||||
|       //plus ou moins avec argument -1 | ||||
|       this.plusoumoins(-1); | ||||
|     } | ||||
|   } | ||||
|   private void plusoumoins(int n){ | ||||
|     int nombre=0; | ||||
|     //try catch pour les gestion de format non conforme | ||||
|     //tant que il n'y a pas d'exception | ||||
|     try{ | ||||
|       //fond en blanc | ||||
|       this.zone.setBackground(new Color(255,255,255)); | ||||
|       //le nombre = nombre deja présent + l'argument | ||||
|       nombre=Integer.parseInt(this.zone.getText())+n; | ||||
|       //si le nombre <0 nombre = au minimum | ||||
|       if(nombre<0){ | ||||
|         nombre=0; | ||||
|       } | ||||
|       //si les collonnes et les lignes existe deja | ||||
|       if(this.plat.getLigne()!=-1 && this.plat.getCollonne()!=-1){ | ||||
|         //si le nomnbre > au nombre de case | ||||
|         // nombre = nombre de case | ||||
|         if(nombre>this.plat.getLigne()*this.plat.getCollonne()){ | ||||
|           nombre=this.plat.getLigne()*this.plat.getCollonne(); | ||||
|         } | ||||
|         //on indique a l'utilisateur le nouveau nombre | ||||
|         this.zone.setText(String.valueOf(nombre)); | ||||
|       }else{ | ||||
|         //si pas de ligne et de collonnes | ||||
|         //fond en rouge | ||||
|         this.zone.setBackground(Color.red); | ||||
|         //on indique a l'utilisateur les précondition avant de remplir ce champs | ||||
|         this.zone.setText("Selectionner Ligne et Collonne Avant"); | ||||
|         //on indique au plateau que le choix n'est toujours pas fait | ||||
|         nombre=-1; | ||||
|       } | ||||
|       //on précise au plateau le nombre de bombe choisit | ||||
|       this.plat.setBombe(nombre); | ||||
|     }catch(NumberFormatException e1){ | ||||
|       //si format inchohérent | ||||
|       //fond en rouge | ||||
|       this.zone.setBackground(Color.red); | ||||
|       //on précise ce que l'ont veut | ||||
|       this.zone.setText("rentrer un entier"); | ||||
|       //on indique au plateau que le choix n'est toujours pas fait | ||||
|       this.plat.setBombe(-1); | ||||
|     } | ||||
|   } | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								observateurCase.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										170
									
								
								observateurCase.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,170 @@ | ||||
| //Tom Monin et Clément Martins | ||||
| // observateurChoix V4 | ||||
| //Class de l'observateur des Cases | ||||
| import java.awt.*; | ||||
| import java.awt.event.*; | ||||
| import javax.swing.*; | ||||
| import java.time.*; | ||||
|  | ||||
| public class observateurCase implements MouseListener{ | ||||
| 	private int ligne, collonne; | ||||
| 	private Case[][] tableau; | ||||
| 	private plateau plat; | ||||
| 	public observateurCase(int ligne0, int collonne0, Case[][] tableau0, plateau plat0){ | ||||
| 		this.ligne=ligne0; | ||||
| 		this.collonne=collonne0; | ||||
| 		this.tableau=tableau0; | ||||
| 		this.plat=plat0; | ||||
| 	} | ||||
| 	@Override | ||||
| 	public void mouseClicked(MouseEvent evenement){ | ||||
| 		//si on clique gauche | ||||
| 		if(evenement.getButton() == MouseEvent.BUTTON1){ | ||||
| 			//si la case n'est pas suspecter(d'etre une bombe ou je sais pas) et que elle n'est pas visible | ||||
| 			if(this.tableau[this.ligne][this.collonne].getSuspition()==0 && this.tableau[this.ligne][this.collonne].getVisibiliter()==false){ | ||||
| 				//nous la rendons visible et la reafichons | ||||
| 				this.tableau[this.ligne][this.collonne].setVisibiliter(true); | ||||
| 				this.tableau[this.ligne][this.collonne].repaint(); | ||||
| 				//si elle n'a pas de voisin nous pouvons afficher les case aux alentours qui serons évidentes a cliquer | ||||
| 				if(this.tableau[this.ligne][this.collonne].getVoisin()==0 && this.tableau[this.ligne][this.collonne].getBombe()==false){ | ||||
| 					this.cliqueEvident(this.ligne, this.collonne);	 | ||||
| 				}			 | ||||
| 			} | ||||
| 		} | ||||
| 		//si clique droit | ||||
| 		if(evenement.getButton() == MouseEvent.BUTTON3){ | ||||
| 			//nous modifions la suspitions de la case et la reafichons si la case n'est pas visible | ||||
| 			if(this.tableau[this.ligne][this.collonne].getVisibiliter()==false){ | ||||
| 				this.tableau[this.ligne][this.collonne].suspition(); | ||||
| 				this.tableau[this.ligne][this.collonne].repaint(); | ||||
| 			} | ||||
| 			//nous testons si le joeur a gagner/perdu | ||||
| 			if(this.tableau[this.ligne][this.collonne].getSuspition()==1){ | ||||
| 				plat.setScore(-1); | ||||
| 			}if(this.tableau[this.ligne][this.collonne].getSuspition()==2){ | ||||
| 				plat.setScore(+1); | ||||
| 			} | ||||
| 			 | ||||
| 		} | ||||
| 		//nous testons si le joueur a gagner/perdu | ||||
| 		//si perdu | ||||
| 		if(plat.etatDeVictoire()==-1){ | ||||
| 			//on precise quelle case a exploser | ||||
| 			this.tableau[this.ligne][this.collonne].setSuspition(4); | ||||
| 		} | ||||
| 		//si gagner | ||||
| 		if(plat.etatDeVictoire()==1){ | ||||
| 			//on initialise le nombre de minute a 0 | ||||
| 			int min=0; | ||||
| 			//on regarde si le joueur a passer plus de 1h | ||||
| 			if(LocalTime.now(ZoneId.systemDefault()).getHour()-this.plat.getTemps().getHour()>0){ | ||||
| 				//si oui on recupere ses minutes avec h*60 plus n minute | ||||
| 				min+=LocalTime.now(ZoneId.systemDefault()).getHour()-this.plat.getTemps().getHour()*60; | ||||
| 			} | ||||
| 			//le score sera calculer de cette manière: | ||||
| 			//frequence de bombe par rapport au nombre de case *10 000 / le temps en min passer a le résoudre | ||||
| 			//temps en minute: | ||||
| 			float resultatTemps=LocalTime.now(ZoneId.systemDefault()).getMinute()+this.plat.getMinute()-this.plat.getTemps().getMinute()+1; | ||||
| 			//fréquence des bombe | ||||
| 			float frequenceBombe=(this.plat.getBombe()*10000)/(this.plat.getLigne()*this.plat.getCollonne()); | ||||
| 			//score final= frequenceBombe/resultatTemps | ||||
| 			//on affiche au joueur son score | ||||
| 			JOptionPane.showMessageDialog(this.plat.getFenetre(), "Vous avez gagné! \n Votre score est de "+frequenceBombe/resultatTemps); | ||||
| 		} | ||||
| 	} | ||||
| 	@Override          // un bouton cliqué | ||||
| 	public void mouseEntered(MouseEvent evenement){ | ||||
|  | ||||
| 	} | ||||
| 	@Override          // debut du survol | ||||
| 	public void mouseExited(MouseEvent evenement){ | ||||
| 	} | ||||
| 	@Override          // fin du survol | ||||
| 	public void mousePressed(MouseEvent evenement){ | ||||
|  | ||||
| 	} | ||||
| 	@Override          // un bouton appuyé | ||||
| 	public void mouseReleased(MouseEvent evenement){ | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	//--------------------------------fonction permettant d'afficher toutes les case n'ayant pas de voisin adjacente utilisant plusieur fonction récursive----------------------------- | ||||
|  | ||||
|  | ||||
| 	private void cliqueEvident(int ligneDelta, int collonneDelta){ | ||||
| 		//nous affichons la case si elle n'est pas suspecter (pour laisser l'erreur au joueur) | ||||
| 		if(this.tableau[ligneDelta][collonneDelta].getSuspition()==0){ | ||||
| 			this.tableau[ligneDelta][collonneDelta].setVisibiliter(true); | ||||
| 			this.tableau[ligneDelta][collonneDelta].repaint(); | ||||
| 		} | ||||
| 		//nous affichons les cases possédants des voisins | ||||
| 		this.affichageVoisinEvident(ligneDelta, collonneDelta); | ||||
| 		//si la case du haut existe et n'est pas visible et n'a pas de voisin et n'est pas une bombe | ||||
| 		if(ligneDelta>0 && this.tableau[ligneDelta-1][collonneDelta].getVisibiliter()==false && this.tableau[ligneDelta-1][collonneDelta].getVoisin()==0 && this.tableau[ligneDelta-1][collonneDelta].getBombe()==false){ | ||||
| 			//on utilise la fonction recurisve sur la case du haut | ||||
| 			this.cliqueEvident(ligneDelta-1, collonneDelta); | ||||
| 		} | ||||
| 		//la même chose pour les 8 cases possible donc recursivite possible (voir principe en haut) | ||||
| 		if(collonneDelta>0 && ligneDelta>0 && this.tableau[ligneDelta-1][collonneDelta-1].getVisibiliter()==false && this.tableau[ligneDelta-1][collonneDelta-1].getVoisin()==0 && this.tableau[ligneDelta-1][collonneDelta-1].getBombe()==false){ | ||||
| 			this.cliqueEvident(ligneDelta-1, collonneDelta-1); | ||||
| 		} | ||||
| 		if(ligneDelta<tableau.length-1 && this.tableau[ligneDelta+1][collonneDelta].getVisibiliter()==false && this.tableau[ligneDelta+1][collonneDelta].getVoisin()==0 && this.tableau[ligneDelta+1][collonneDelta].getBombe()==false){	 | ||||
| 			this.cliqueEvident(ligneDelta+1, collonneDelta); | ||||
| 		} | ||||
| 		if(collonneDelta<tableau[ligneDelta].length-1 && this.tableau[ligneDelta][collonneDelta+1].getVisibiliter()==false && this.tableau[ligneDelta][collonneDelta+1].getVoisin()==0 && this.tableau[ligneDelta][collonneDelta+1].getBombe()==false){ | ||||
| 			this.cliqueEvident(ligneDelta, collonneDelta+1); | ||||
| 		} | ||||
| 		if(collonneDelta>0 && this.tableau[ligneDelta][collonneDelta-1].getVisibiliter()==false && this.tableau[ligneDelta][collonneDelta-1].getVoisin()==0 && this.tableau[ligneDelta][collonneDelta-1].getBombe()==false){ | ||||
| 			this.cliqueEvident(ligneDelta, collonneDelta-1); | ||||
| 		} | ||||
| 		if(collonneDelta>0 && ligneDelta<this.tableau.length-1 && this.tableau[ligneDelta+1][collonneDelta-1].getVisibiliter()==false && this.tableau[ligneDelta+1][collonneDelta-1].getVoisin()==0 && this.tableau[ligneDelta+1][collonneDelta-1].getBombe()==false){ | ||||
| 			this.cliqueEvident(ligneDelta+1, collonneDelta-1); | ||||
| 		} | ||||
| 		if(collonneDelta<this.tableau[ligneDelta].length-1 && ligneDelta>0 && this.tableau[ligneDelta-1][collonneDelta+1].getVisibiliter()==false && this.tableau[ligneDelta-1][collonneDelta+1].getVoisin()==0 && this.tableau[ligneDelta-1][collonneDelta+1].getBombe()==false){ | ||||
| 			this.cliqueEvident(ligneDelta-1, collonneDelta+1); | ||||
| 		} | ||||
| 		if(collonneDelta<this.tableau[ligneDelta].length-1 && ligneDelta<this.tableau.length-1 && this.tableau[ligneDelta+1][collonneDelta+1].getVisibiliter()==false && this.tableau[ligneDelta+1][collonneDelta+1].getVoisin()==0 && this.tableau[ligneDelta+1][collonneDelta+1].getBombe()==false){ | ||||
| 			this.cliqueEvident(ligneDelta+1, collonneDelta+1); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	//--------------------------------------fonction qui affiche toutes les case possédant un voisin d'une case donnée------------------------------------------ | ||||
|  | ||||
|  | ||||
| 	private void affichageVoisinEvident(int ligneDelta, int collonneDelta){ | ||||
| 		//nous regardons les 8 case adjacentes et si elle a des voisin | ||||
| 		//si elle en a alors nous la rendons visible | ||||
| 		if(ligneDelta>0 && this.tableau[ligneDelta-1][collonneDelta].getVisibiliter()==false && this.tableau[ligneDelta-1][collonneDelta].getVoisin()>0 && this.tableau[ligneDelta-1][collonneDelta].getSuspition()==0){ | ||||
| 			this.tableau[ligneDelta-1][collonneDelta].setVisibiliter(true); | ||||
| 			this.tableau[ligneDelta-1][collonneDelta].repaint(); | ||||
| 		} | ||||
| 		if(ligneDelta<tableau.length-1 && this.tableau[ligneDelta+1][collonneDelta].getVisibiliter()==false && this.tableau[ligneDelta+1][collonneDelta].getVoisin()>0 && this.tableau[ligneDelta+1][collonneDelta].getSuspition()==0){	 | ||||
| 			this.tableau[ligneDelta+1][collonneDelta].setVisibiliter(true); | ||||
| 			this.tableau[ligneDelta+1][collonneDelta].repaint(); | ||||
| 		} | ||||
| 		if(collonneDelta<tableau[ligneDelta].length-1 && this.tableau[ligneDelta][collonneDelta+1].getVisibiliter()==false && this.tableau[ligneDelta][collonneDelta+1].getVoisin()>0 && this.tableau[ligneDelta][collonneDelta+1].getSuspition()==0){ | ||||
| 			this.tableau[ligneDelta][collonneDelta+1].setVisibiliter(true); | ||||
| 			this.tableau[ligneDelta][collonneDelta+1].repaint(); | ||||
| 		} | ||||
| 		if(collonneDelta>0 && this.tableau[ligneDelta][collonneDelta-1].getVisibiliter()==false && this.tableau[ligneDelta][collonneDelta-1].getVoisin()>0 && this.tableau[ligneDelta][collonneDelta-1].getSuspition()==0){ | ||||
| 			this.tableau[ligneDelta][collonneDelta-1].setVisibiliter(true); | ||||
| 			this.tableau[ligneDelta][collonneDelta-1].repaint(); | ||||
| 		} | ||||
| 		if(collonneDelta>0 && ligneDelta>0 && this.tableau[ligneDelta-1][collonneDelta-1].getVisibiliter()==false && this.tableau[ligneDelta-1][collonneDelta-1].getVoisin()>0 && this.tableau[ligneDelta-1][collonneDelta-1].getSuspition()==0){ | ||||
| 			this.tableau[ligneDelta-1][collonneDelta-1].setVisibiliter(true); | ||||
| 			this.tableau[ligneDelta-1][collonneDelta-1].repaint(); | ||||
| 		} | ||||
| 		if(collonneDelta>0 && ligneDelta<this.tableau.length-1 && this.tableau[ligneDelta+1][collonneDelta-1].getVisibiliter()==false && this.tableau[ligneDelta+1][collonneDelta-1].getVoisin()>0 && this.tableau[ligneDelta+1][collonneDelta-1].getSuspition()==0){ | ||||
| 			this.tableau[ligneDelta+1][collonneDelta-1].setVisibiliter(true); | ||||
| 			this.tableau[ligneDelta+1][collonneDelta-1].repaint(); | ||||
| 		} | ||||
| 		if(collonneDelta<this.tableau[ligneDelta].length-1 && ligneDelta>0 && this.tableau[ligneDelta-1][collonneDelta+1].getVisibiliter()==false && this.tableau[ligneDelta-1][collonneDelta+1].getVoisin()>0 && this.tableau[ligneDelta-1][collonneDelta+1].getSuspition()==0){ | ||||
| 			this.tableau[ligneDelta-1][collonneDelta+1].setVisibiliter(true); | ||||
| 			this.tableau[ligneDelta-1][collonneDelta+1].repaint(); | ||||
| 		} | ||||
| 		if(collonneDelta<this.tableau[ligneDelta].length-1 && ligneDelta<this.tableau.length-1 && this.tableau[ligneDelta+1][collonneDelta+1].getVisibiliter()==false && this.tableau[ligneDelta+1][collonneDelta+1].getVoisin()>0 && this.tableau[ligneDelta+1][collonneDelta+1].getSuspition()==0){ | ||||
| 			this.tableau[ligneDelta+1][collonneDelta+1].setVisibiliter(true); | ||||
| 			this.tableau[ligneDelta+1][collonneDelta+1].repaint(); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								observateurChoix.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										95
									
								
								observateurChoix.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,95 @@ | ||||
| //Tom Monin et Clément Martins | ||||
| // observateurChoix V1 | ||||
| //Class pour la selection du nombre de collone et ligne et de Mine a la souris | ||||
| //ainsi que pour le choix du premier menu | ||||
| import java.awt.*; | ||||
| import java.awt.event.*; | ||||
| import javax.swing.*; | ||||
| import java.io.*; | ||||
|  | ||||
| public class observateurChoix implements MouseListener{ | ||||
| 	//le composant qui est observer ainsi que le premier (pour les ligne de choix du 2ème menu) | ||||
| 	private paintChoix pinceau, premier; | ||||
| 	//le texte des ligne et collonne | ||||
| 	private JLabel texte; | ||||
| 	//le plateau | ||||
| 	private plateau plat; | ||||
| 	//constructeur | ||||
| 	private boolean fonction; // attribut utiliser que pour le logo | ||||
| 	//@params (le composant, le premier composant de la ligne, le texte, le plateau) | ||||
| 	public observateurChoix(paintChoix pinceau0, paintChoix premier0, JLabel texte0, plateau plat0){ | ||||
| 		this.pinceau=pinceau0; | ||||
| 		this.premier=premier0; | ||||
| 		this.texte=texte0; | ||||
| 		this.plat=plat0; | ||||
| 		this.fonction=false; | ||||
| 	} | ||||
| 	public void setFonction(boolean fonction0){ | ||||
| 		this.fonction=fonction0; | ||||
| 	} | ||||
| 	@Override | ||||
| 	public void mouseClicked(MouseEvent evenement){ | ||||
| 		//on connaîtra la fonction desirer par le composant grâce a sa fonction | ||||
| 		//et donc réagir en conséquence | ||||
| 		//si la fonction est hors 8 et 10 | ||||
| 		//c'est alors que l'observateur est destiner au deuxième menu | ||||
| 		if(this.pinceau.getFonction()==1 || this.pinceau.getFonction()==2){ | ||||
| 			//on remet tous en false a partir du premier composant | ||||
| 			this.premier.setClique(false); | ||||
| 			//on les remet en true a partir de celui qui est cliquer | ||||
| 			this.pinceau.setClique(true); | ||||
| 			//si la fonction est de 1 (pour les ligne) | ||||
| 			if(this.pinceau.getFonction()==1){ | ||||
| 				//nous repositionons le nombre de ligne en foction de la position du composant | ||||
| 				this.texte.setText("<=== Ligne: "+String.valueOf(this.pinceau.getN())); | ||||
| 				//nous precisions au plateau le nombre de ligne selectionner | ||||
| 				this.plat.setLigne(this.pinceau.getN()); | ||||
| 			} | ||||
| 			//si la fonction est de 2 (pour les collonnes) | ||||
| 			if(this.pinceau.getFonction()==2){ | ||||
| 				//nous repositionons le nombre de collonne en fonction de la position du composant | ||||
| 				this.texte.setText("Collonne: "+String.valueOf(this.pinceau.getN()+" ===>")); | ||||
| 				//nous precisions au plateau le nombre de collonne selectionner | ||||
| 				this.plat.setCollonne(this.pinceau.getN()); | ||||
| 			} | ||||
| 		// pour les autres fonction (premier menu) | ||||
| 		}else{ | ||||
| 			//fonction 9 (pour nouvelle partie) | ||||
| 			if(this.pinceau.getFonction()==9){ | ||||
|       			this.plat.menuChoixLCB(); | ||||
|     		} | ||||
| 			//fonction 10 (pour reprendre une partie) | ||||
|     		if(this.pinceau.getFonction()==10){ | ||||
|       			try{ | ||||
|       			  FileInputStream fichier = new FileInputStream("./sauvegarde.data"); | ||||
|       			  this.plat.reprendrePartie(fichier); | ||||
|       			}catch(FileNotFoundException e1){ | ||||
|       			  JOptionPane.showMessageDialog(this.plat.getFenetre(), "sauvegarde introuvable"); | ||||
|       			} | ||||
|     		} | ||||
| 			//fonction 8 (pour quitter la partie) | ||||
|     		if(this.pinceau.getFonction()==8){ | ||||
|       			this.plat.getFenetre().dispose(); | ||||
|     		} | ||||
| 		} | ||||
| 	} | ||||
| 	@Override          // un bouton cliqué | ||||
| 	public void mouseEntered(MouseEvent evenement){ | ||||
| 		//on precise au composant que ont est en train de le survoler | ||||
| 		this.pinceau.selectionner(true); | ||||
| 	} | ||||
| 	@Override          // debut du survol | ||||
| 	public void mouseExited(MouseEvent evenement){ | ||||
| 		//on precise au composant que on ne le survol plus | ||||
| 		this.pinceau.selectionner(false); | ||||
| 	} | ||||
| 	@Override          // fin du survol | ||||
| 	public void mousePressed(MouseEvent evenement){ | ||||
|  | ||||
| 	} | ||||
| 	@Override          // un bouton appuyé | ||||
| 	public void mouseReleased(MouseEvent evenement){ | ||||
|  | ||||
| 	} | ||||
|  | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								observateurFenetre.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										37
									
								
								observateurFenetre.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,37 @@ | ||||
| //Fonction permettant d'observer les action realiser sur la fenetre et notament pour  | ||||
| //sauvegarder avant la fermeture de celle-di | ||||
| 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){ | ||||
|         //si le joueur veut fermer la fenetre | ||||
|         //si la partie n'est pas encore fini | ||||
|         if(this.plat.etatDeVictoire()==0){ | ||||
|             //on sauvegarde | ||||
|             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 | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								observateurSAV.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										49
									
								
								observateurSAV.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,49 @@ | ||||
| import java.awt.*; | ||||
| import java.awt.event.*; | ||||
| import javax.swing.*; | ||||
|  | ||||
| //classe de l'observateur pour la sauvegarde | ||||
|  | ||||
| public class observateurSAV implements MouseListener{ | ||||
| 	private plateau plat;	//le plateau | ||||
| 	private paintMenuJeu button;	//notre boutons de sauvegarde | ||||
| 	private boolean fonction;	//la fonction | ||||
| 	public observateurSAV(paintMenuJeu button0, plateau plat0){ | ||||
| 		this.button=button0; | ||||
| 		this.plat=plat0; | ||||
| 		this.fonction=false;	// par default a false (mode sauvegarde) | ||||
| 	} | ||||
| 	public void setFonction(boolean fonction0){ | ||||
| 		this.fonction=fonction0;	//pour modifier la fonction plus tard | ||||
| 	} | ||||
| 	@Override | ||||
| 	public void mouseClicked(MouseEvent evenement){ | ||||
| 		//si fonction false (mode sauvegarde) | ||||
| 		if(this.fonction==false){ | ||||
| 			plat.save(); | ||||
| 		} | ||||
| 		//sinp=on mode rejouer | ||||
| 		if(this.fonction==true){ | ||||
| 			plat= new plateau(plat.getFenetre()); | ||||
| 			plat.menuChoixTypePartie(); | ||||
| 		} | ||||
| 	} | ||||
| 	@Override          // un bouton cliqué | ||||
| 	public void mouseEntered(MouseEvent evenement){ | ||||
| 		//on indique au composant le survol | ||||
| 		this.button.setSurvol(true); | ||||
| 	} | ||||
| 	@Override          // debut du survol | ||||
| 	public void mouseExited(MouseEvent evenement){ | ||||
| 		//on indique au composant la fin du survol | ||||
| 		this.button.setSurvol(false); | ||||
| 	} | ||||
| 	@Override          // fin du survol | ||||
| 	public void mousePressed(MouseEvent evenement){ | ||||
|  | ||||
| 	} | ||||
| 	@Override          // un bouton appuyé | ||||
| 	public void mouseReleased(MouseEvent evenement){ | ||||
|  | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								paintChoix.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										116
									
								
								paintChoix.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,116 @@ | ||||
|  | ||||
| // Tom Monin et Clément Martins | ||||
| // paintChoix V1 | ||||
| // class pour l'affichage de la selection des lignes, collonnes et nombre de mines | ||||
|  | ||||
| import java.awt.*; | ||||
| import javax.swing.*; | ||||
| import javax.swing.JComponent; | ||||
|  | ||||
| public class paintChoix extends JComponent{ | ||||
| 	private boolean selectionner;	//si la case est survoler | ||||
| 	private paintChoix pinceau;		//le composant suivant | ||||
| 	private boolean clique;		//si la casse a été cliquer | ||||
| 	private int x;		//sa position | ||||
| 	private int fonction;		//sa fonction (pour éviter le surplus de classe inutiles) | ||||
| 	public paintChoix(int x0, int fonction0){ | ||||
| 		this.clique=false;	//de base le composant n'est pas cliquer | ||||
| 		this.pinceau=null;	//il n'a pas de suivant | ||||
| 		this.selectionner=false;	//il n'est pas selectionner | ||||
| 		this.x=30-x0;	//sa position est la différence de 30 - celle donner (car ordre decroisant) | ||||
| 		this.fonction=fonction0; | ||||
| 		//de base ce n'est pas selectionner | ||||
| 	} | ||||
|  | ||||
| 	// fonction permetant positionner la case et ses voisoins sur selectionner | ||||
| 	public void selectionner(boolean verif){ | ||||
| 		//on postionne la case en selectionner = @params | ||||
| 		this.selectionner=verif; | ||||
| 		//si il a un suivant | ||||
| 		if(this.pinceau!=null){ | ||||
| 			//on lui transmet le message | ||||
| 			this.pinceau.selectionner(verif); | ||||
| 		} | ||||
| 		//on repaint la case | ||||
| 		this.repaint(); | ||||
| 	} | ||||
| 	public void setPaintChoix(paintChoix pinceau0){ | ||||
| 		//pour positionner le composant suivant | ||||
| 		this.pinceau=pinceau0; | ||||
| 	} | ||||
| 	public void setClique(boolean verif){ | ||||
| 		//même principe que selectionner | ||||
| 		this.clique=verif; | ||||
| 		if(this.pinceau!=null){ | ||||
| 			this.pinceau.setClique(verif); | ||||
| 		} | ||||
| 		this.repaint(); | ||||
| 	} | ||||
| 	public int getFonction(){ | ||||
| 		return this.fonction; | ||||
| 	} | ||||
| 	public int getN(){ | ||||
| 		return this.x; | ||||
| 	} | ||||
|   	@Override | ||||
| 	protected void paintComponent(Graphics pinceau) { | ||||
|     	// obligatoire : on crée un nouveau pinceau pour pouvoir le modifier plus tard | ||||
|     	Graphics secondPinceau = pinceau.create(); | ||||
|     	// obligatoire : si le composant n'est pas censé être transparent | ||||
|     	if (this.isOpaque()) { | ||||
|       	// obligatoire : on repeint toute la surface avec la couleur de fond | ||||
|       	secondPinceau.setColor(this.getBackground()); | ||||
|       	secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight()); | ||||
|     	} | ||||
|     	//si cliquer | ||||
| 		if(this.clique==true){ | ||||
| 			//carrer bleu | ||||
| 			secondPinceau.setColor(new Color(0, 127, 255)); | ||||
| 			secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight()); | ||||
| 		} | ||||
| 		//si selectionner | ||||
| 		if(selectionner==true){ | ||||
| 			//carrer orange | ||||
| 			secondPinceau.setColor(new Color(255, 127, 0)); | ||||
| 			secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight()); | ||||
| 		} | ||||
| 		//autrement carrer blanc | ||||
| 		secondPinceau.setColor(new Color(0,0,0)); | ||||
| 		secondPinceau.drawRect(0, 0, this.getWidth(), this.getHeight()); | ||||
| 		//si la fonction est de 8 (pour les premier menu) | ||||
| 		if(this.fonction==8){ | ||||
| 			//fond blanc | ||||
|     		secondPinceau.setColor(new Color(255, 255, 255)); | ||||
|     		secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight()); | ||||
|     		//on dessinne l'image correspondante | ||||
|     		Image nouveau=Toolkit.getDefaultToolkit().getImage("./IMAGE/nouveau.jpg"); | ||||
|     		if(this.selectionner==true){ | ||||
|     			//si elle est survoler un l'agrandi pour une mailleur visibilite | ||||
|     			secondPinceau.drawImage(nouveau, 0, 0, this.getWidth(), this.getHeight(), this); | ||||
|     		}else{ | ||||
|     			secondPinceau.drawImage(nouveau, this.getWidth()/20, this.getHeight()/20, this.getWidth()/20*18, this.getHeight()/20*18, this); | ||||
|     		} | ||||
|     	} | ||||
|     	//même principe pour les autre if suivant | ||||
|     	if(this.fonction==9){ | ||||
|     		secondPinceau.setColor(new Color(255, 255, 255)); | ||||
|     		secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight()); | ||||
|     		Image quitter=Toolkit.getDefaultToolkit().getImage("./IMAGE/quitter.jpg"); | ||||
|     		if(this.selectionner==true){ | ||||
|     			secondPinceau.drawImage(quitter, 0, 0, this.getWidth(), this.getHeight(), this); | ||||
|     		}else{ | ||||
|     			secondPinceau.drawImage(quitter, this.getWidth()/20, this.getHeight()/20, this.getWidth()/20*18, this.getHeight()/20*18, this);  			 | ||||
|     		} | ||||
|     	} | ||||
|     	if(this.fonction==10){ | ||||
|     		secondPinceau.setColor(new Color(255, 255, 255)); | ||||
|     		secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight()); | ||||
|     		Image reprendre=Toolkit.getDefaultToolkit().getImage("./IMAGE/reprendre.png"); | ||||
|     		if(this.selectionner==true){ | ||||
|     			secondPinceau.drawImage(reprendre, 0, 0, this.getWidth(), this.getHeight(), this); | ||||
|     		}else{ | ||||
|     			secondPinceau.drawImage(reprendre, this.getWidth()/20, this.getHeight()/20, this.getWidth()/20*18, this.getHeight()/20*18, this); | ||||
|     		} | ||||
|     	} | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								paintMenuJeu.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										175
									
								
								paintMenuJeu.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,175 @@ | ||||
| import java.awt.*; | ||||
| import javax.swing.*; | ||||
| import javax.swing.JComponent; | ||||
|  | ||||
| //Classe pour l'affichage du menu en haut du jeu avec notament le score et les logo | ||||
| public class paintMenuJeu extends JComponent{ | ||||
| 	private int choix;	//pour préciser le but du composant | ||||
| 	private int scoreMax, score;	//le score maximum et le score actuel | ||||
| 	private boolean survol;	//si la case est survoler | ||||
| 	public paintMenuJeu(int choix0, int score0, int scoreMax0){ | ||||
| 		this.choix=choix0; | ||||
| 		this.score=score0; | ||||
| 		this.scoreMax=scoreMax0; | ||||
| 		this.survol=false; | ||||
| 	} | ||||
| 	//----------------------getteur et Setter------------------------------ | ||||
| 	public void setChoix(int choix0){ | ||||
| 		this.choix=choix0; | ||||
| 		this.repaint(); | ||||
| 	} | ||||
| 	public void setScore(int score0){ | ||||
| 		this.score=score0; | ||||
| 		this.repaint(); | ||||
| 	} | ||||
| 	public int getScore(){ | ||||
| 		return this.score; | ||||
| 	} | ||||
| 	public void setSurvol(boolean survol0){ | ||||
| 		this.survol=survol0; | ||||
| 		this.repaint(); | ||||
| 	} | ||||
| 	public int getScoreMax(){ | ||||
| 		return this.scoreMax; | ||||
| 	} | ||||
| 	public int getFonction(){ | ||||
| 		return this.choix; | ||||
| 	} | ||||
|  | ||||
|  | ||||
| 	@Override | ||||
| 	protected void paintComponent(Graphics pinceau) { | ||||
|     	// obligatoire : on crée un nouveau pinceau pour pouvoir le modifier plus tard | ||||
|     	Graphics secondPinceau = pinceau.create(); | ||||
|     	// obligatoire : si le composant n'est pas censé être transparent | ||||
|     	if (this.isOpaque()) { | ||||
|       	// obligatoire : on repeint toute la surface avec la couleur de fond | ||||
|       	secondPinceau.setColor(this.getBackground()); | ||||
|       	secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight()); | ||||
|     	} | ||||
|     	//On paint ce que l'on veut maintenant | ||||
|     	//par default on remplis de noir | ||||
|     	secondPinceau.setColor(new Color(0,0,0)); | ||||
|     	secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight()); | ||||
|     	//si le choix est de 1 (chiffre des centaines) | ||||
|     	if(this.choix==1){ | ||||
|     		//le score correspond au chiffre des centaine | ||||
|     		int nombre=this.score/100; | ||||
|     		//on affiche le chiffre correspondant | ||||
|     		this.paintNombre(secondPinceau, nombre); | ||||
|     	} | ||||
|     	//si le choix est de 1 (chiffre des dixaines) | ||||
|     	if(this.choix==2){ | ||||
|     		//le score correspond au chiffre des dixaine | ||||
|     		int nombre=this.score; | ||||
|     		if(nombre>=100){ | ||||
|     			nombre=this.score-100*(this.score/100); | ||||
|     		} | ||||
|     		nombre=nombre/10; | ||||
|     		//on affiche le chiffre correspondant | ||||
|     		this.paintNombre(secondPinceau, nombre); | ||||
|     	} | ||||
|     	//si le choix de 3 (chiffre des untité) | ||||
|     	if(this.choix==3){ | ||||
|     		//le score correspond au chiffre des uité | ||||
|     		int nombre=this.score; | ||||
|     		if(nombre>=100){ | ||||
|     			nombre=this.score-100*(this.score/100); | ||||
|     		} | ||||
|     		if(nombre>=10){ | ||||
|     			nombre=this.score-10*(this.score/10); | ||||
|     		} | ||||
|     		//on affiche le chiffre correspondant | ||||
|     		this.paintNombre(secondPinceau, nombre); | ||||
|     	} | ||||
|     	//si le choix est de (logo sauvegarde) | ||||
|     	if(this.choix==4){ | ||||
|     		//si survoler | ||||
|     		if(this.survol==true){ | ||||
|     			//fond en vert | ||||
|     			secondPinceau.setColor(new Color(0,255,0)); | ||||
|     			secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight()); | ||||
|     		} | ||||
|     		//on affiche l'image | ||||
|     		Image sav=Toolkit.getDefaultToolkit().getImage("./IMAGE/sav.png"); | ||||
|     		secondPinceau.drawImage(sav, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this); | ||||
|     	} | ||||
|     	//si choix est de 5 (lorsque le joueur perd) | ||||
|     	if(this.choix==5){ | ||||
|     		//on affiche des bonhomes pas content pour montrer que il a perdu | ||||
|     		Image lose=Toolkit.getDefaultToolkit().getImage("./IMAGE/lose.png"); | ||||
|     		secondPinceau.drawImage(lose, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this); | ||||
|     	} | ||||
|     	//si choix de 6 (gagner) | ||||
|     	if(this.choix==6){ | ||||
|     		//bonhomme content | ||||
|     		Image win=Toolkit.getDefaultToolkit().getImage("./IMAGE/win.png"); | ||||
|     		secondPinceau.drawImage(win, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this); | ||||
|     	} | ||||
|     	//si choix de 7 (logo replay) | ||||
|     	if(this.choix==7){ | ||||
|     		//et survol | ||||
|     		if(this.survol==true){ | ||||
|     			//fond en vert | ||||
|     			secondPinceau.setColor(new Color(0,255,0)); | ||||
|     			secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight()); | ||||
|     		} | ||||
|     		// on affiche le logo replay | ||||
|     		Image replay=Toolkit.getDefaultToolkit().getImage("./IMAGE/replay.png"); | ||||
|     		secondPinceau.drawImage(replay, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this); | ||||
|     	} | ||||
|     	 | ||||
|     } | ||||
|  | ||||
|     //----------------------fonction pour afficher le nombre donner----------------------- | ||||
|     private void paintNombre(Graphics secondPinceau, int nombre){ | ||||
|     	//si le nombre est positif | ||||
|     	if(this.score>=0){ | ||||
|     		//on regarde les 10 chiffre possible et l'affichons en conséquences | ||||
|     		if(nombre==1){ | ||||
|     			Image un=Toolkit.getDefaultToolkit().getImage("./IMAGE/unD.png"); | ||||
|    				secondPinceau.drawImage(un, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this); | ||||
|    			} | ||||
|     		if(nombre==2){ | ||||
|     			Image deux=Toolkit.getDefaultToolkit().getImage("./IMAGE/deuxD.png"); | ||||
|     			secondPinceau.drawImage(deux, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this); | ||||
|     		} | ||||
|     		if(nombre==3){ | ||||
|     			Image trois=Toolkit.getDefaultToolkit().getImage("./IMAGE/troisD.png"); | ||||
|     			secondPinceau.drawImage(trois, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this); | ||||
|     		} | ||||
|     		if(nombre==4){ | ||||
|     			Image quatre=Toolkit.getDefaultToolkit().getImage("./IMAGE/quatreD.png"); | ||||
|     			secondPinceau.drawImage(quatre, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this); | ||||
|     		} | ||||
|     		if(nombre==5){ | ||||
|     			Image cinq=Toolkit.getDefaultToolkit().getImage("./IMAGE/cinqD.png"); | ||||
|     			secondPinceau.drawImage(cinq, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this); | ||||
|     		} | ||||
|     		if(nombre==6){ | ||||
|     			Image six=Toolkit.getDefaultToolkit().getImage("./IMAGE/sixD.png"); | ||||
|     			secondPinceau.drawImage(six, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this); | ||||
|     		} | ||||
|     		if(nombre==7){ | ||||
|     			Image sept=Toolkit.getDefaultToolkit().getImage("./IMAGE/septD.png"); | ||||
|     			secondPinceau.drawImage(sept, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this); | ||||
|     		} | ||||
|     		if(nombre==8){ | ||||
|     			Image huit=Toolkit.getDefaultToolkit().getImage("./IMAGE/huitD.png"); | ||||
|     			secondPinceau.drawImage(huit, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this); | ||||
|     		} | ||||
|     		if(nombre==9){ | ||||
|     			Image neuf=Toolkit.getDefaultToolkit().getImage("./IMAGE/neufD.png"); | ||||
|     			secondPinceau.drawImage(neuf, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this); | ||||
|     		} | ||||
|     		if(nombre==0){ | ||||
|     			Image zero=Toolkit.getDefaultToolkit().getImage("./IMAGE/zeroD.png"); | ||||
|     			secondPinceau.drawImage(zero, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this); | ||||
|     		} | ||||
|     	}else{ | ||||
|     		Image err=Toolkit.getDefaultToolkit().getImage("./IMAGE/err.png"); | ||||
|     		secondPinceau.drawImage(err, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/6*4, this.getHeight()/6*4 ,this); | ||||
|     	} | ||||
|     	 | ||||
|     } | ||||
| } | ||||