Malus mis a jour et fonctionnel
This commit is contained in:
@@ -17,31 +17,35 @@ public class ZoneDessin extends JPanel {
|
||||
// LE BOUTON DOIT ÊTRE PUBLIC POUR ÊTRE ACCESSIBLE DEPUIS JEU.JAVA
|
||||
public JButton btnRetour;
|
||||
|
||||
public ZoneDessin(){
|
||||
public ZoneDessin() {
|
||||
// Layout null pour positionner le bouton pixel par pixel
|
||||
setLayout(null);
|
||||
setPreferredSize(new Dimension(800, 600));
|
||||
setBackground(new Color(100,100,100));
|
||||
setBackground(new Color(100, 100, 100));
|
||||
|
||||
// 2. Création et configuration du bouton
|
||||
btnRetour = new JButton("Back to Menu");
|
||||
// x, y, largeur, hauteur (centré horizontalement pour une fenêtre de 800px)
|
||||
// entré horizontalement pour une fenêtre de 800px
|
||||
btnRetour.setBounds(300, 350, 200, 50);
|
||||
btnRetour.setFont(new Font("Arial", Font.BOLD, 16));
|
||||
btnRetour.setFocusable(false); // Important pour ne pas gêner le clavier
|
||||
btnRetour.setVisible(false); // Caché au début
|
||||
btnRetour.setFocusable(false);
|
||||
btnRetour.setVisible(false);
|
||||
|
||||
this.add(btnRetour);
|
||||
}
|
||||
|
||||
// ... (méthodes ajouterObjet, viderObjets, arreter, demarrer restent pareilles) ...
|
||||
public void ajouterObjet(ObjetGraphique unObjet) { this.listeObjets.add(unObjet); }
|
||||
public void viderObjets() { this.listeObjets.clear(); }
|
||||
public void ajouterObjet(ObjetGraphique unObjet) {
|
||||
this.listeObjets.add(unObjet);
|
||||
}
|
||||
|
||||
public void traiterBoucleAnimation(){
|
||||
if (estArrete || isGameOver || isVictoire) return;
|
||||
public void viderObjets() {
|
||||
this.listeObjets.clear();
|
||||
}
|
||||
|
||||
for (ObjetGraphique obj : listeObjets){
|
||||
public void traiterBoucleAnimation() {
|
||||
if (estArrete || isGameOver || isVictoire)
|
||||
return;
|
||||
|
||||
for (ObjetGraphique obj : listeObjets) {
|
||||
obj.Animer();
|
||||
}
|
||||
repaint();
|
||||
@@ -50,15 +54,15 @@ public class ZoneDessin extends JPanel {
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2D = (Graphics2D) g;
|
||||
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
for (ObjetGraphique obj : listeObjets){
|
||||
for (ObjetGraphique obj : listeObjets) {
|
||||
obj.Afficher(g);
|
||||
}
|
||||
|
||||
// Affichage de l'écran Game Over
|
||||
if (isGameOver) {
|
||||
g2D.setColor(new Color(0, 0, 0, 150)); // Fond sombre
|
||||
g2D.setColor(new Color(0, 0, 0, 150));
|
||||
g2D.fillRect(0, 0, getWidth(), getHeight());
|
||||
|
||||
g2D.setColor(Color.WHITE);
|
||||
@@ -67,7 +71,7 @@ public class ZoneDessin extends JPanel {
|
||||
int largeur = g2D.getFontMetrics().stringWidth(msg);
|
||||
g2D.drawString(msg, (getWidth() - largeur) / 2, getHeight() / 2 - 50);
|
||||
} else if (isVictoire) {
|
||||
g2D.setColor(new Color(0, 0, 0, 150)); // Fond sombre
|
||||
g2D.setColor(new Color(0, 0, 0, 150));
|
||||
g2D.fillRect(0, 0, getWidth(), getHeight());
|
||||
|
||||
g2D.setColor(Color.GREEN);
|
||||
@@ -81,10 +85,10 @@ public class ZoneDessin extends JPanel {
|
||||
|
||||
public void setGameOver(boolean state) {
|
||||
this.isGameOver = state;
|
||||
// 3. C'est ici qu'on affiche ou cache le bouton
|
||||
btnRetour.setVisible(state);
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void setVictoire(boolean state) {
|
||||
this.isVictoire = state;
|
||||
btnRetour.setVisible(state);
|
||||
|
||||
Reference in New Issue
Block a user