ajout du nombre de voisin, bombe, modif visuel et de la classe plateau
This commit is contained in:
parent
d6eee19761
commit
82795b037a
BIN
CASE/Case.class
BIN
CASE/Case.class
Binary file not shown.
@ -11,11 +11,13 @@ public class Case extends JComponent{
|
||||
private boolean bombe;
|
||||
private int voisin;
|
||||
private int suspition;
|
||||
private Image interogation;
|
||||
public Case(){
|
||||
this.visibilite=false;
|
||||
this.bombe=false;
|
||||
this.voisin=0;
|
||||
this.suspition=0;
|
||||
this.interogation= Toolkit.getDefaultToolkit().getImage("./IMAGE/pointintero.png");
|
||||
}
|
||||
public void setVisibiliter(boolean trueorfalse){
|
||||
this.visibilite=trueorfalse;
|
||||
@ -29,6 +31,19 @@ public class Case extends JComponent{
|
||||
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
|
||||
protected void paintComponent(Graphics pinceau) {
|
||||
// obligatoire : on crée un nouveau pinceau pour pouvoir le modifier plus tard
|
||||
@ -50,11 +65,12 @@ 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));
|
||||
}
|
||||
if(this.voisin>0){
|
||||
secondPinceau.drawString("3", this.getWidth()/2, this.getHeight()/2);
|
||||
secondPinceau.setColor(new Color(255, 0, 0));
|
||||
if(this.voisin>0){
|
||||
secondPinceau.drawString(String.valueOf(voisin), this.getWidth()/2, this.getHeight()/2);
|
||||
}
|
||||
}
|
||||
|
||||
if(this.suspition==1 && this.visibilite==false){
|
||||
int[] x = 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.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
BIN
CASE/IMAGE/pointintero.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
Binary file not shown.
@ -27,5 +27,8 @@ public class main_ex{
|
||||
fenetre.add(tab[i][t]);
|
||||
}
|
||||
}
|
||||
plateau plat = new plateau(tab);
|
||||
plat.setAllBombe(18, 14, 8);
|
||||
plat.setAllVoisin();
|
||||
}
|
||||
}
|
Binary file not shown.
@ -16,8 +16,10 @@ public class observateurCase implements MouseListener{
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent evenement){
|
||||
if(evenement.getButton() == MouseEvent.BUTTON1){
|
||||
case1.setVisibiliter(true);
|
||||
case1.repaint();
|
||||
if(case1.getSuspition()==false){
|
||||
case1.setVisibiliter(true);
|
||||
case1.repaint();
|
||||
}
|
||||
}
|
||||
if(evenement.getButton() == MouseEvent.BUTTON3){
|
||||
case1.suspition();
|
||||
|
BIN
CASE/plateau.class
Normal file
BIN
CASE/plateau.class
Normal file
Binary file not shown.
69
CASE/plateau.java
Normal file
69
CASE/plateau.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user