SAE21_2021/CASE/Case.java

100 lines
3.4 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;
2022-04-28 01:03:16 +02:00
private Image interogation, etoile, imgboombe;
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-28 01:03:16 +02:00
this.etoile= Toolkit.getDefaultToolkit().getImage("./IMAGE/etoile.png");
this.imgboombe= Toolkit.getDefaultToolkit().getImage("./IMAGE/bombe.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-28 20:43:37 +02:00
public boolean getSuspition2(){
if(this.suspition==1){
return true;
}else{
return false;
}
}
public boolean getVisibiliter(){
return this.visibilite;
}
public int getVoisin(){
return this.voisin;
}
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(0,0,0));
2022-04-27 13:19:57 +02:00
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
secondPinceau.setColor(new Color(100, 100, 100));
2022-04-27 13:19:57 +02:00
secondPinceau.fillRect(this.getWidth()/20, this.getHeight()/20, this.getWidth()/20*18, this.getHeight()/20*18);
if(this.suspition==1){
secondPinceau.drawImage(this.etoile, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
}
if(this.suspition==2){
secondPinceau.drawImage(this.interogation, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
}
2022-04-27 13:19:57 +02:00
}
if(this.visibilite==true){
secondPinceau.setColor(new Color(0,0,0));
2022-04-27 13:19:57 +02:00
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);
}
if(this.bombe==true){
secondPinceau.setColor(new Color(255,0,125));
secondPinceau.fillRect(this.getWidth()/20, this.getHeight()/20, this.getWidth()/20*18, this.getHeight()/20*18);
secondPinceau.drawImage(this.imgboombe, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this);
}
}
2022-04-27 13:19:57 +02:00
}
}