Files
Projet_DEV/src/linea/ZoneDessin.java

97 lines
2.5 KiB
Java
Raw Normal View History

2026-02-03 13:50:27 +01:00
package linea;
2026-02-03 15:45:52 +01:00
import java.awt.*;
2026-02-03 13:50:27 +01:00
import java.util.ArrayList;
2026-02-10 16:02:29 +01:00
import javax.swing.*;
2026-02-03 13:50:27 +01:00
2026-02-10 16:02:29 +01:00
public class ZoneDessin extends JPanel {
2026-02-03 13:50:27 +01:00
private static final long serialVersionUID = 1L;
protected ArrayList<ObjetGraphique> listeObjets = new ArrayList<ObjetGraphique>();
2026-02-03 15:45:52 +01:00
2026-02-10 16:02:29 +01:00
// Etats du jeu
protected boolean estArrete = false;
2026-02-03 15:45:52 +01:00
protected boolean isGameOver = false;
2026-03-16 16:39:57 +01:00
protected boolean isVictoire = false;
2026-02-10 16:02:29 +01:00
// LE BOUTON DOIT ÊTRE PUBLIC POUR ÊTRE ACCESSIBLE DEPUIS JEU.JAVA
public JButton btnRetour;
2026-03-17 14:11:48 +01:00
public ZoneDessin() {
// Layout null pour positionner le bouton pixel par pixel
2026-02-10 16:02:29 +01:00
setLayout(null);
2026-02-03 13:50:27 +01:00
setPreferredSize(new Dimension(800, 600));
2026-03-17 14:11:48 +01:00
setBackground(new Color(100, 100, 100));
2026-02-03 13:50:27 +01:00
2026-02-10 16:03:23 +01:00
btnRetour = new JButton("Back to Menu");
2026-03-17 14:11:48 +01:00
// entré horizontalement pour une fenêtre de 800px
2026-02-10 16:02:29 +01:00
btnRetour.setBounds(300, 350, 200, 50);
btnRetour.setFont(new Font("Arial", Font.BOLD, 16));
2026-03-17 14:11:48 +01:00
btnRetour.setFocusable(false);
btnRetour.setVisible(false);
2026-02-10 16:02:29 +01:00
this.add(btnRetour);
2026-02-03 13:50:27 +01:00
}
2026-02-10 16:02:29 +01:00
2026-03-17 14:11:48 +01:00
public void ajouterObjet(ObjetGraphique unObjet) {
this.listeObjets.add(unObjet);
}
public void viderObjets() {
this.listeObjets.clear();
}
2026-02-10 16:02:29 +01:00
2026-03-17 14:11:48 +01:00
public void traiterBoucleAnimation() {
if (estArrete || isGameOver || isVictoire)
return;
2026-02-03 13:50:27 +01:00
2026-03-17 14:11:48 +01:00
for (ObjetGraphique obj : listeObjets) {
2026-02-03 13:50:27 +01:00
obj.Animer();
}
2026-02-10 16:02:29 +01:00
repaint();
2026-02-03 13:50:27 +01:00
}
2026-02-10 16:02:29 +01:00
2026-02-03 13:50:27 +01:00
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2D = (Graphics2D) g;
2026-03-17 14:11:48 +01:00
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
2026-02-10 16:02:29 +01:00
2026-03-17 14:11:48 +01:00
for (ObjetGraphique obj : listeObjets) {
2026-02-03 13:50:27 +01:00
obj.Afficher(g);
}
2026-02-10 16:02:29 +01:00
// Affichage de l'écran Game Over
2026-02-03 15:45:52 +01:00
if (isGameOver) {
2026-03-17 14:11:48 +01:00
g2D.setColor(new Color(0, 0, 0, 150));
2026-02-03 15:45:52 +01:00
g2D.fillRect(0, 0, getWidth(), getHeight());
g2D.setColor(Color.WHITE);
g2D.setFont(new Font("Arial", Font.BOLD, 50));
String msg = "GAME OVER";
2026-02-10 16:02:29 +01:00
int largeur = g2D.getFontMetrics().stringWidth(msg);
g2D.drawString(msg, (getWidth() - largeur) / 2, getHeight() / 2 - 50);
2026-03-16 16:39:57 +01:00
} else if (isVictoire) {
2026-03-17 14:11:48 +01:00
g2D.setColor(new Color(0, 0, 0, 150));
2026-03-16 16:39:57 +01:00
g2D.fillRect(0, 0, getWidth(), getHeight());
g2D.setColor(Color.GREEN);
g2D.setFont(new Font("Arial", Font.BOLD, 50));
String msg = "VICTOIRE";
int largeur = g2D.getFontMetrics().stringWidth(msg);
g2D.drawString(msg, (getWidth() - largeur) / 2, getHeight() / 2 - 50);
2026-02-03 15:45:52 +01:00
}
2026-03-16 16:39:57 +01:00
2026-02-03 15:45:52 +01:00
}
public void setGameOver(boolean state) {
this.isGameOver = state;
2026-02-10 16:02:29 +01:00
btnRetour.setVisible(state);
2026-02-03 15:45:52 +01:00
repaint();
2026-02-03 13:50:27 +01:00
}
2026-03-17 14:11:48 +01:00
2026-03-16 16:39:57 +01:00
public void setVictoire(boolean state) {
this.isVictoire = state;
btnRetour.setVisible(state);
repaint();
}
2026-02-10 16:02:29 +01:00
}