Marquage finalisé, cases non clicables, problème d'affichage fixé
This commit is contained in:
parent
cecd279029
commit
fd598eeb07
11
Grille.java
11
Grille.java
@ -27,7 +27,6 @@ public class Grille extends JPanel {
|
||||
Random rand = new Random();
|
||||
// On initialise les emplacements des mines
|
||||
caseMine[0] = rand.nextInt(lignes*colonnes);
|
||||
System.out.println("mine 0 : "+ caseMine[0]);
|
||||
for (int i=1;i<mines;i++){
|
||||
caseMine[i] = rand.nextInt(lignes*colonnes);
|
||||
// On vérifie que la case n'a pas déjà été minée, auquel cas on change de case
|
||||
@ -35,19 +34,10 @@ public class Grille extends JPanel {
|
||||
if (caseMine[i]==caseMine[j]){
|
||||
caseMine[i] = rand.nextInt(lignes*colonnes);
|
||||
j=-1;
|
||||
System.out.println("Nouvelle case qu'on essaye de miner :"+ caseMine[i]);
|
||||
} else if (caseMine[i]!=caseMine[j]){
|
||||
System.out.println(""+ caseMine[i]+" != "+ caseMine[j]);
|
||||
}
|
||||
}
|
||||
System.out.println("Mine posee :"+ "("+i+")"+caseMine[i]);
|
||||
}
|
||||
|
||||
/* Affichage de l'mplacement des mines
|
||||
for (int i=0;i<mines;i++){
|
||||
System.out.println(""+ caseMine[i]);
|
||||
}*/
|
||||
|
||||
// On place maintenant les mines sur la plateau
|
||||
boolean[] minee = new boolean[lignes*colonnes];
|
||||
for (int i=0; i<lignes*colonnes;i++){
|
||||
@ -277,7 +267,6 @@ public class Grille extends JPanel {
|
||||
protected void AfficherPlateau(int taille, Dimension caseSize, int[] entourage, boolean[] minee){
|
||||
for (int i=0;i<taille;i++){
|
||||
this.plateau[i]= new Case(caseSize,minee[i],entourage[i]);
|
||||
this.plateau[i].setVisible();
|
||||
this.add(this.plateau[i].getCase());
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,12 @@ import java.awt.event.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Listener implements MouseListener{
|
||||
private int marquage=0;
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent evenement){
|
||||
Case panel = (Case)evenement.getSource();
|
||||
if ((evenement.getButton() == MouseEvent.BUTTON1)&&(panel.getVisible()==false)){
|
||||
if ((evenement.getButton() == MouseEvent.BUTTON1)&&(panel.getVisible()==false)&&(this.marquage==0)){
|
||||
panel.setVisible();
|
||||
panel.getCase();
|
||||
if (panel.getMine()==true){
|
||||
@ -14,9 +15,22 @@ public class Listener implements MouseListener{
|
||||
}
|
||||
}
|
||||
if (evenement.getButton() == MouseEvent.BUTTON3) {
|
||||
panel.add(new Etoile(panel.getSize()), BorderLayout.CENTER);
|
||||
if (this.marquage==0){
|
||||
panel.add(new Etoile(panel.getSize()), BorderLayout.CENTER);
|
||||
this.marquage=1;
|
||||
}
|
||||
else if (this.marquage==1){
|
||||
panel.removeAll();
|
||||
panel.add(new Sus(panel.getSize()), BorderLayout.CENTER);
|
||||
this.marquage=2;
|
||||
}
|
||||
else if (this.marquage==2){
|
||||
panel.removeAll();
|
||||
this.marquage=0;
|
||||
}
|
||||
panel.updateUI();
|
||||
System.out.println("Marquage");
|
||||
|
||||
System.out.println(""+this.marquage);
|
||||
}
|
||||
}
|
||||
public void mouseEntered(MouseEvent evenement){
|
||||
|
18
Sus.java
Normal file
18
Sus.java
Normal file
@ -0,0 +1,18 @@
|
||||
import javax.swing.JComponent;
|
||||
import java.awt.*;
|
||||
|
||||
public class Sus extends JComponent {
|
||||
private Dimension caseSize;
|
||||
public Sus(Dimension caseSize) {
|
||||
super();
|
||||
this.caseSize=caseSize;
|
||||
}
|
||||
@Override
|
||||
protected void paintComponent(Graphics pinceau) {
|
||||
Graphics chiffre = pinceau.create();
|
||||
Font font = new Font("Arial", Font.BOLD, caseSize.width*3/5);
|
||||
chiffre.setFont(font);
|
||||
chiffre.setColor(new Color(236, 0, 140));
|
||||
chiffre.drawString("?",caseSize.width*3/10,caseSize.height*4/5);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user