SAE21_2021/CASE/Case.java

98 lines
3.2 KiB
Java
Raw Normal View History

2022-04-27 13:19:57 +02:00
// Tom Monin et Clément Martins
// paintChoix V1
// class pour l'affichage de la selection des lignes, collonnes et nombre de mines
import java.awt.*;
import javax.swing.*;
import javax.swing.JComponent;
public class Case extends JComponent{
private boolean visibilite;
private boolean bombe;
private int voisin;
private int suspition;
private Image interogation;
2022-04-27 13:19:57 +02:00
public Case(){
this.visibilite=false;
this.bombe=false;
this.voisin=0;
this.suspition=0;
this.interogation= Toolkit.getDefaultToolkit().getImage("./IMAGE/pointintero.png");
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;
}
}
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-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());
}
if(this.visibilite==false){
secondPinceau.setColor(new Color(100,100,100));
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
secondPinceau.setColor(new Color(200, 200, 200));
secondPinceau.fillRect(this.getWidth()/20, this.getHeight()/20, this.getWidth()/20*18, this.getHeight()/20*18);
}
if(this.visibilite==true){
secondPinceau.setColor(new Color(100,100,100));
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(String.valueOf(voisin), this.getWidth()/2, this.getHeight()/2);
}
2022-04-27 13:19:57 +02:00
}
2022-04-27 13:19:57 +02:00
if(this.suspition==1 && this.visibilite==false){
int[] x = new int[5];
int[] y = new int[5];
x[0]=this.getWidth()/2;
x[1]=this.getWidth()/10*9;
x[2]=this.getWidth()/10*7;
x[3]=this.getWidth()/10*3;
x[4]=this.getWidth()/10;
y[0]=this.getHeight()/10*2;
y[1]=this.getHeight()/2;
y[2]=this.getHeight()/10*8;
y[3]=this.getHeight()/10*8;
y[4]=this.getHeight()/2;
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());
}
2022-04-27 13:19:57 +02:00
}
}