ajout du nombre de voisin, bombe, modif visuel et de la classe plateau

This commit is contained in:
martins 2022-04-27 18:01:00 +02:00
parent d6eee19761
commit 82795b037a
9 changed files with 103 additions and 6 deletions

Binary file not shown.

View File

@ -11,11 +11,13 @@ public class Case extends JComponent{
private boolean bombe; private boolean bombe;
private int voisin; private int voisin;
private int suspition; private int suspition;
private Image interogation;
public Case(){ public Case(){
this.visibilite=false; this.visibilite=false;
this.bombe=false; this.bombe=false;
this.voisin=0; this.voisin=0;
this.suspition=0; this.suspition=0;
this.interogation= Toolkit.getDefaultToolkit().getImage("./IMAGE/pointintero.png");
} }
public void setVisibiliter(boolean trueorfalse){ public void setVisibiliter(boolean trueorfalse){
this.visibilite=trueorfalse; this.visibilite=trueorfalse;
@ -29,6 +31,19 @@ public class Case extends JComponent{
this.suspition=0; this.suspition=0;
} }
} }
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;
}
}
@Override @Override
protected void paintComponent(Graphics pinceau) { protected void paintComponent(Graphics pinceau) {
// obligatoire : on crée un nouveau pinceau pour pouvoir le modifier plus tard // obligatoire : on crée un nouveau pinceau pour pouvoir le modifier plus tard
@ -51,10 +66,11 @@ public class Case extends JComponent{
secondPinceau.setColor(new Color(255, 255, 255)); secondPinceau.setColor(new Color(255, 255, 255));
secondPinceau.fillRect(this.getWidth()/20, this.getHeight()/20, this.getWidth()/20*18, this.getHeight()/20*18); secondPinceau.fillRect(this.getWidth()/20, this.getHeight()/20, this.getWidth()/20*18, this.getHeight()/20*18);
secondPinceau.setColor(new Color(255, 0, 0)); secondPinceau.setColor(new Color(255, 0, 0));
}
if(this.voisin>0){ if(this.voisin>0){
secondPinceau.drawString("3", this.getWidth()/2, this.getHeight()/2); secondPinceau.drawString(String.valueOf(voisin), this.getWidth()/2, this.getHeight()/2);
} }
}
if(this.suspition==1 && this.visibilite==false){ if(this.suspition==1 && this.visibilite==false){
int[] x = new int[5]; int[] x = new int[5];
int[] y = new int[5]; int[] y = new int[5];
@ -71,5 +87,12 @@ public class Case extends JComponent{
secondPinceau.setColor(new Color(255,0,125)); secondPinceau.setColor(new Color(255,0,125));
secondPinceau.fillPolygon(x, y, 5); secondPinceau.fillPolygon(x, y, 5);
} }
if(this.suspition==2 && this.visibilite==false){
secondPinceau.drawImage(this.interogation, this.getWidth()/10, this.getHeight()/10, this.getWidth()/10*5, this.getHeight()/10*5 ,this);
}
if(this.bombe==true && this.visibilite==true){
secondPinceau.setColor(new Color(255,0,125));
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
}
} }
} }

BIN
CASE/IMAGE/pointintero.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

View File

@ -27,5 +27,8 @@ public class main_ex{
fenetre.add(tab[i][t]); fenetre.add(tab[i][t]);
} }
} }
plateau plat = new plateau(tab);
plat.setAllBombe(18, 14, 8);
plat.setAllVoisin();
} }
} }

Binary file not shown.

View File

@ -16,9 +16,11 @@ public class observateurCase implements MouseListener{
@Override @Override
public void mouseClicked(MouseEvent evenement){ public void mouseClicked(MouseEvent evenement){
if(evenement.getButton() == MouseEvent.BUTTON1){ if(evenement.getButton() == MouseEvent.BUTTON1){
if(case1.getSuspition()==false){
case1.setVisibiliter(true); case1.setVisibiliter(true);
case1.repaint(); case1.repaint();
} }
}
if(evenement.getButton() == MouseEvent.BUTTON3){ if(evenement.getButton() == MouseEvent.BUTTON3){
case1.suspition(); case1.suspition();
case1.repaint(); case1.repaint();

BIN
CASE/plateau.class Normal file

Binary file not shown.

69
CASE/plateau.java Normal file
View File

@ -0,0 +1,69 @@
import java.util.*;
public class plateau{
private Case[][] tableau;
public plateau(Case[][] tableau0){
this.tableau=tableau0;
}
public void setAllBombe(int nombre, int ligne, int collonne){
Random rand = new Random();
for(int i=0; i<nombre; i++){
int x=rand.nextInt(ligne);
int y=rand.nextInt(collonne);
if(this.tableau[x][y].getBombe()==false){
this.tableau[x][y].setBombe();
}else{
i--;
}
}
}
public void setAllVoisin(){
for(int i=0; i<tableau.length; i++){
for(int t=0; t<tableau[i].length; t++){
int voisin=0;
if(i>0){
if(tableau[i-1][t].getBombe()==true){
voisin++;
}
if(t>0){
if(tableau[i-1][t-1].getBombe()==true){
voisin++;
}
}
if(t<tableau[i].length-1){
if(tableau[i-1][t+1].getBombe()==true){
voisin++;
}
}
}
if(i<tableau.length-1){
if(tableau[i+1][t].getBombe()==true){
voisin++;
}
if(t>0){
if(tableau[i+1][t-1].getBombe()==true){
voisin++;
}
}
if(t<tableau[i].length-1){
if(tableau[i+1][t+1].getBombe()==true){
voisin++;
}
}
}
if(t>0){
if(tableau[i][t-1].getBombe()==true){
voisin++;
}
}
if(t<tableau[i].length-1){
if(tableau[i][t+1].getBombe()==true){
voisin++;
}
}
tableau[i][t].setVoisin(voisin);
}
}
}
}