SAE21_2021/paintMenuJeu.java

145 lines
5.7 KiB
Java
Raw Normal View History

2022-05-05 22:45:26 +02:00
import java.awt.*;
import javax.swing.*;
import javax.swing.JComponent;
public class paintMenuJeu extends JComponent{
private int choix;
private int scoreMax, score;
private boolean survol;
public paintMenuJeu(int choix0, int score0, int scoreMax0){
this.choix=choix0;
this.score=score0;
this.scoreMax=scoreMax0;
this.survol=false;
}
public void setChoix(int choix0){
this.choix=choix0;
this.repaint();
}
public void setScore(int score0){
this.score=score0;
this.repaint();
}
public int getScore(){
return this.score;
}
public void setSurvol(boolean survol0){
this.survol=survol0;
this.repaint();
}
public int getScoreMax(){
return this.scoreMax;
}
2022-05-20 13:39:53 +02:00
public int getFonction(){
return this.choix;
}
2022-05-05 22:45:26 +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());
}
//On paint ce que l'on veut maintenant
secondPinceau.setColor(new Color(0,0,0));
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
if(this.choix==1){
int nombre=this.score/100;
this.paintNombre(secondPinceau, nombre);
}
if(this.choix==2){
int nombre=this.score;
if(nombre>=100){
nombre=this.score-100*(this.score/100);
}
nombre=nombre/10;
this.paintNombre(secondPinceau, nombre);
}
if(this.choix==3){
int nombre=this.score;
if(nombre>=100){
nombre=this.score-100*(this.score/100);
}
if(nombre>=10){
nombre=this.score-10*(this.score/10);
}
this.paintNombre(secondPinceau, nombre);
}
if(this.choix==4){
if(this.survol==true){
secondPinceau.setColor(new Color(0,255,0));
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
}
2022-05-11 20:31:30 +02:00
Image sav=Toolkit.getDefaultToolkit().getImage("./IMAGE/sav.png");
secondPinceau.drawImage(sav, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
2022-05-05 22:45:26 +02:00
}
if(this.choix==5){
2022-05-11 20:31:30 +02:00
Image lose=Toolkit.getDefaultToolkit().getImage("./IMAGE/lose.png");
secondPinceau.drawImage(lose, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
2022-05-05 22:45:26 +02:00
}
if(this.choix==6){
2022-05-11 20:31:30 +02:00
Image win=Toolkit.getDefaultToolkit().getImage("./IMAGE/win.png");
secondPinceau.drawImage(win, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
2022-05-05 22:45:26 +02:00
}
if(this.choix==7){
if(this.survol==true){
secondPinceau.setColor(new Color(0,255,0));
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
}
2022-05-11 20:31:30 +02:00
Image replay=Toolkit.getDefaultToolkit().getImage("./IMAGE/replay.png");
secondPinceau.drawImage(replay, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
2022-05-05 22:45:26 +02:00
}
2022-05-20 13:39:53 +02:00
2022-05-05 22:45:26 +02:00
}
private void paintNombre(Graphics secondPinceau, int nombre){
if(this.score>=0){
if(nombre==1){
2022-05-11 20:31:30 +02:00
Image un=Toolkit.getDefaultToolkit().getImage("./IMAGE/unD.png");
secondPinceau.drawImage(un, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
2022-05-05 22:45:26 +02:00
}
if(nombre==2){
2022-05-11 20:31:30 +02:00
Image deux=Toolkit.getDefaultToolkit().getImage("./IMAGE/deuxD.png");
secondPinceau.drawImage(deux, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
2022-05-05 22:45:26 +02:00
}
if(nombre==3){
2022-05-11 20:31:30 +02:00
Image trois=Toolkit.getDefaultToolkit().getImage("./IMAGE/troisD.png");
secondPinceau.drawImage(trois, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
2022-05-05 22:45:26 +02:00
}
if(nombre==4){
2022-05-11 20:31:30 +02:00
Image quatre=Toolkit.getDefaultToolkit().getImage("./IMAGE/quatreD.png");
secondPinceau.drawImage(quatre, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
2022-05-05 22:45:26 +02:00
}
if(nombre==5){
2022-05-11 20:31:30 +02:00
Image cinq=Toolkit.getDefaultToolkit().getImage("./IMAGE/cinqD.png");
secondPinceau.drawImage(cinq, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
2022-05-05 22:45:26 +02:00
}
if(nombre==6){
2022-05-11 20:31:30 +02:00
Image six=Toolkit.getDefaultToolkit().getImage("./IMAGE/sixD.png");
secondPinceau.drawImage(six, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
2022-05-05 22:45:26 +02:00
}
if(nombre==7){
2022-05-11 20:31:30 +02:00
Image sept=Toolkit.getDefaultToolkit().getImage("./IMAGE/septD.png");
secondPinceau.drawImage(sept, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
2022-05-05 22:45:26 +02:00
}
if(nombre==8){
2022-05-11 20:31:30 +02:00
Image huit=Toolkit.getDefaultToolkit().getImage("./IMAGE/huitD.png");
secondPinceau.drawImage(huit, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
2022-05-05 22:45:26 +02:00
}
if(nombre==9){
2022-05-11 20:31:30 +02:00
Image neuf=Toolkit.getDefaultToolkit().getImage("./IMAGE/neufD.png");
secondPinceau.drawImage(neuf, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
2022-05-05 22:45:26 +02:00
}
if(nombre==0){
2022-05-11 20:31:30 +02:00
Image zero=Toolkit.getDefaultToolkit().getImage("./IMAGE/zeroD.png");
secondPinceau.drawImage(zero, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
2022-05-05 22:45:26 +02:00
}
}else{
2022-05-11 20:31:30 +02:00
Image err=Toolkit.getDefaultToolkit().getImage("./IMAGE/err.png");
secondPinceau.drawImage(err, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
2022-05-05 22:45:26 +02:00
}
}
}