2022-04-27 13:19:57 +02:00
|
|
|
// Tom Monin et Clément Martins
|
2022-04-28 21:31:03 +02:00
|
|
|
// paintChoix V3
|
|
|
|
// class représentant une case dans la partie
|
2022-04-27 13:19:57 +02:00
|
|
|
|
|
|
|
import java.awt.*;
|
|
|
|
import javax.swing.*;
|
|
|
|
import javax.swing.JComponent;
|
|
|
|
|
|
|
|
public class Case extends JComponent{
|
2022-04-28 21:31:03 +02:00
|
|
|
//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)
|
2022-04-28 22:01:12 +02:00
|
|
|
private Image interogation, etoile, imgboombe, un, deux, trois, quatre, cinq, six, sept, huit;
|
2022-04-28 21:31:03 +02:00
|
|
|
|
|
|
|
//Constructeur de la Case
|
2022-04-27 13:19:57 +02:00
|
|
|
public Case(){
|
2022-04-28 21:31:03 +02:00
|
|
|
//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 chargeons les images
|
|
|
|
this.interogation= Toolkit.getDefaultToolkit().getImage("./IMAGE/pointintero.png");
|
2022-04-28 01:03:16 +02:00
|
|
|
this.etoile= Toolkit.getDefaultToolkit().getImage("./IMAGE/etoile.png");
|
|
|
|
this.imgboombe= Toolkit.getDefaultToolkit().getImage("./IMAGE/bombe.png");
|
2022-04-28 22:01:12 +02:00
|
|
|
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");
|
2022-04-27 13:19:57 +02:00
|
|
|
}
|
2022-04-28 21:31:03 +02:00
|
|
|
|
|
|
|
// Nous mettons les getter/setter
|
|
|
|
|
2022-04-27 13:19:57 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2022-04-27 18:01:00 +02:00
|
|
|
public boolean getBombe(){
|
|
|
|
return this.bombe;
|
|
|
|
}
|
|
|
|
public void setVoisin(int nvoisin){
|
|
|
|
this.voisin=nvoisin;
|
|
|
|
}
|
|
|
|
public boolean getSuspition(){
|
|
|
|
if(this.suspition>0){
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2022-04-28 21:31:03 +02:00
|
|
|
// il y a deux suspition pour faciliter( le deux pour savoir si elle est suspecter sur 1:c'est une bombe et l'autre sur 0:pas une bombe)
|
2022-04-28 20:43:37 +02:00
|
|
|
public boolean getSuspition2(){
|
|
|
|
if(this.suspition==1){
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2022-04-28 18:15:17 +02:00
|
|
|
public boolean getVisibiliter(){
|
|
|
|
return this.visibilite;
|
|
|
|
}
|
|
|
|
public int getVoisin(){
|
|
|
|
return this.voisin;
|
|
|
|
}
|
2022-04-28 21:31:03 +02:00
|
|
|
|
|
|
|
//on paint la case en fonction de ses attribut et donc son etat
|
2022-04-27 13:19:57 +02:00
|
|
|
@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());
|
|
|
|
}
|
2022-04-28 21:31:03 +02:00
|
|
|
//On paint ce que l'on veut maintenant
|
|
|
|
//si la case est cacher (pas visible)
|
2022-04-27 13:19:57 +02:00
|
|
|
if(this.visibilite==false){
|
2022-04-28 21:31:03 +02:00
|
|
|
//on dessinne un rectangle gris sur un fond noir
|
2022-04-28 18:15:17 +02:00
|
|
|
secondPinceau.setColor(new Color(0,0,0));
|
2022-04-27 13:19:57 +02:00
|
|
|
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
2022-04-28 18:15:17 +02:00
|
|
|
secondPinceau.setColor(new Color(100, 100, 100));
|
2022-04-27 13:19:57 +02:00
|
|
|
secondPinceau.fillRect(this.getWidth()/20, this.getHeight()/20, this.getWidth()/20*18, this.getHeight()/20*18);
|
2022-04-28 21:31:03 +02:00
|
|
|
//si on supecte que c'est une bome
|
2022-04-28 18:15:17 +02:00
|
|
|
if(this.suspition==1){
|
2022-04-28 21:31:03 +02:00
|
|
|
//on affiche l'etoile
|
2022-04-28 18:15:17 +02:00
|
|
|
secondPinceau.drawImage(this.etoile, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
|
|
|
}
|
2022-04-28 21:31:03 +02:00
|
|
|
//si on suspecte que on ne sais pas
|
2022-04-28 18:15:17 +02:00
|
|
|
if(this.suspition==2){
|
2022-04-28 21:31:03 +02:00
|
|
|
//on affiche le point d'interogation
|
2022-04-28 18:15:17 +02:00
|
|
|
secondPinceau.drawImage(this.interogation, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
|
|
|
}
|
2022-04-27 13:19:57 +02:00
|
|
|
}
|
2022-04-28 21:31:03 +02:00
|
|
|
//si la case est afficher(visible)
|
2022-04-27 13:19:57 +02:00
|
|
|
if(this.visibilite==true){
|
2022-04-28 21:31:03 +02:00
|
|
|
//on dessine un rectangle blanc sur un fond noir
|
2022-04-28 18:15:17 +02:00
|
|
|
secondPinceau.setColor(new Color(0,0,0));
|
2022-04-27 13:19:57 +02:00
|
|
|
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);
|
2022-04-27 18:01:00 +02:00
|
|
|
secondPinceau.setColor(new Color(255, 0, 0));
|
2022-04-28 21:31:03 +02:00
|
|
|
//si la case a au moins 1 voisin qui est une bombe
|
2022-04-27 18:01:00 +02:00
|
|
|
if(this.voisin>0){
|
2022-04-28 21:31:03 +02:00
|
|
|
//on ecrit le nombre de voisin que elle a
|
2022-04-28 22:01:12 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
2022-04-27 18:01:00 +02:00
|
|
|
}
|
2022-04-28 21:31:03 +02:00
|
|
|
//si la case est une bombe
|
2022-04-28 18:15:17 +02:00
|
|
|
if(this.bombe==true){
|
2022-04-28 21:31:03 +02:00
|
|
|
//on remplace le rectangle blanc par un rectangle rouge
|
2022-04-28 18:15:17 +02:00
|
|
|
secondPinceau.setColor(new Color(255,0,125));
|
|
|
|
secondPinceau.fillRect(this.getWidth()/20, this.getHeight()/20, this.getWidth()/20*18, this.getHeight()/20*18);
|
2022-04-28 21:31:03 +02:00
|
|
|
//on affiche la bombe
|
2022-04-28 18:15:17 +02:00
|
|
|
secondPinceau.drawImage(this.imgboombe, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
|
|
|
|
}
|
2022-04-27 18:01:00 +02:00
|
|
|
}
|
2022-04-27 13:19:57 +02:00
|
|
|
}
|
|
|
|
}
|