2022-04-27 18:01:00 +02:00
|
|
|
import java.util.*;
|
2022-04-28 20:43:37 +02:00
|
|
|
import java.awt.event.*;
|
2022-04-27 18:01:00 +02:00
|
|
|
|
|
|
|
public class plateau{
|
2022-04-28 20:43:37 +02:00
|
|
|
public static void setAllBombe(int nombre, int ligne, int collonne, Case[][] tableau0){
|
2022-04-27 18:01:00 +02:00
|
|
|
Random rand = new Random();
|
|
|
|
for(int i=0; i<nombre; i++){
|
|
|
|
int x=rand.nextInt(ligne);
|
|
|
|
int y=rand.nextInt(collonne);
|
2022-04-28 20:43:37 +02:00
|
|
|
if(tableau0[x][y].getBombe()==false){
|
|
|
|
tableau0[x][y].setBombe();
|
2022-04-27 18:01:00 +02:00
|
|
|
}else{
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-28 20:43:37 +02:00
|
|
|
public static void setAllVoisin(Case[][] tableau0){
|
|
|
|
for(int i=0; i<tableau0.length; i++){
|
|
|
|
for(int t=0; t<tableau0[i].length; t++){
|
2022-04-27 18:01:00 +02:00
|
|
|
int voisin=0;
|
|
|
|
if(i>0){
|
2022-04-28 20:43:37 +02:00
|
|
|
if(tableau0[i-1][t].getBombe()==true){
|
2022-04-27 18:01:00 +02:00
|
|
|
voisin++;
|
|
|
|
}
|
|
|
|
if(t>0){
|
2022-04-28 20:43:37 +02:00
|
|
|
if(tableau0[i-1][t-1].getBombe()==true){
|
2022-04-27 18:01:00 +02:00
|
|
|
voisin++;
|
|
|
|
}
|
|
|
|
}
|
2022-04-28 20:43:37 +02:00
|
|
|
if(t<tableau0[i].length-1){
|
|
|
|
if(tableau0[i-1][t+1].getBombe()==true){
|
2022-04-27 18:01:00 +02:00
|
|
|
voisin++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-28 20:43:37 +02:00
|
|
|
if(i<tableau0.length-1){
|
|
|
|
if(tableau0[i+1][t].getBombe()==true){
|
2022-04-27 18:01:00 +02:00
|
|
|
voisin++;
|
|
|
|
}
|
|
|
|
if(t>0){
|
2022-04-28 20:43:37 +02:00
|
|
|
if(tableau0[i+1][t-1].getBombe()==true){
|
2022-04-27 18:01:00 +02:00
|
|
|
voisin++;
|
|
|
|
}
|
|
|
|
}
|
2022-04-28 20:43:37 +02:00
|
|
|
if(t<tableau0[i].length-1){
|
|
|
|
if(tableau0[i+1][t+1].getBombe()==true){
|
2022-04-27 18:01:00 +02:00
|
|
|
voisin++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(t>0){
|
2022-04-28 20:43:37 +02:00
|
|
|
if(tableau0[i][t-1].getBombe()==true){
|
2022-04-27 18:01:00 +02:00
|
|
|
voisin++;
|
|
|
|
}
|
|
|
|
}
|
2022-04-28 20:43:37 +02:00
|
|
|
if(t<tableau0[i].length-1){
|
|
|
|
if(tableau0[i][t+1].getBombe()==true){
|
2022-04-27 18:01:00 +02:00
|
|
|
voisin++;
|
|
|
|
}
|
|
|
|
}
|
2022-04-28 20:43:37 +02:00
|
|
|
tableau0[i][t].setVoisin(voisin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public static int etatDeVictoire(Case[][] tableau0){
|
|
|
|
int condition=0;
|
|
|
|
for(int i=0; i<tableau0.length; i++){
|
|
|
|
for(int t=0; t<tableau0[i].length; t++){
|
|
|
|
if(tableau0[i][t].getVisibiliter()==false && tableau0[i][t].getBombe()==false){
|
|
|
|
condition++;
|
|
|
|
}
|
|
|
|
if(tableau0[i][t].getVisibiliter()==true && tableau0[i][t].getBombe()==true){
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if(tableau0[i][t].getSuspition2()==false && tableau0[i][t].getBombe()==true){
|
|
|
|
condition++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(condition>0){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
public static void perduGagner(Case[][] tableau0){
|
|
|
|
for(int i=0; i<tableau0.length; i++){
|
|
|
|
for(int t=0; t<tableau0[i].length; t++){
|
|
|
|
MouseListener[] tabListener;
|
|
|
|
tabListener=tableau0[i][t].getMouseListeners();
|
|
|
|
for(int longeur=0; longeur<=tabListener.length-1; longeur++){
|
|
|
|
tableau0[i][t].removeMouseListener(tabListener[longeur]);
|
|
|
|
}
|
2022-04-27 18:01:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|