141 lines
5.7 KiB
Java
141 lines
5.7 KiB
Java
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;
|
|
}
|
|
@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());
|
|
}
|
|
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);
|
|
}
|
|
if(this.choix==5){
|
|
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);
|
|
}
|
|
if(this.choix==6){
|
|
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);
|
|
}
|
|
if(this.choix==7){
|
|
if(this.survol==true){
|
|
secondPinceau.setColor(new Color(0,255,0));
|
|
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
private void paintNombre(Graphics secondPinceau, int nombre){
|
|
if(this.score>=0){
|
|
if(nombre==1){
|
|
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);
|
|
}
|
|
if(nombre==2){
|
|
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);
|
|
}
|
|
if(nombre==3){
|
|
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);
|
|
}
|
|
if(nombre==4){
|
|
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);
|
|
}
|
|
if(nombre==5){
|
|
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);
|
|
}
|
|
if(nombre==6){
|
|
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);
|
|
}
|
|
if(nombre==7){
|
|
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);
|
|
}
|
|
if(nombre==8){
|
|
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);
|
|
}
|
|
if(nombre==9){
|
|
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);
|
|
}
|
|
if(nombre==0){
|
|
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);
|
|
}
|
|
}else{
|
|
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);
|
|
}
|
|
|
|
}
|
|
} |