bouton campagne

This commit is contained in:
2026-02-10 16:34:22 +01:00
parent c52547120b
commit d10578c313
3 changed files with 90 additions and 15 deletions

View File

@@ -10,7 +10,10 @@ public class Jeu implements KeyListener, ActionListener {
protected CardLayout layout;
protected ZoneDessin ecran = new ZoneDessin();
// MENUS
protected MenuPrincipal menu;
protected MenuCampagne menuCampagne;
protected Cercle demiCercleAvant;
protected Cercle demiCercleArriere;
@@ -30,23 +33,23 @@ public class Jeu implements KeyListener, ActionListener {
conteneurPrincipal = new JPanel(layout);
menu = new MenuPrincipal(this);
menuCampagne = new MenuCampagne(this);
// Initialisation initiale
resetPartie();
// On ajoute l'action au bouton créé dans ZoneDessin
// On ajoute l'action au bouton "Retour" de la ZoneDessin (Game Over)
ecran.btnRetour.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// 1. On change la carte visible vers le MENU
layout.show(conteneurPrincipal, "MENU");
afficherMenuPrincipal();
}
});
ecran.addKeyListener(this);
conteneurPrincipal.add(menu, "MENU");
conteneurPrincipal.add(menuCampagne, "CAMPAGNE");
conteneurPrincipal.add(ecran, "JEU");
fenetre.setContentPane(conteneurPrincipal);
@@ -56,6 +59,20 @@ public class Jeu implements KeyListener, ActionListener {
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void afficherMenuCampagne() {
layout.show(conteneurPrincipal, "CAMPAGNE");
}
public void afficherMenuPrincipal() {
layout.show(conteneurPrincipal, "MENU");
}
public void lancerNiveau(int numeroNiveau) {
System.out.println("Lancement du niveau " + numeroNiveau);
// Ici tu pourras configurer la difficulté selon le niveau
lancerPartie();
}
public void lancerPartie() {
resetPartie();
layout.show(conteneurPrincipal, "JEU");
@@ -65,25 +82,20 @@ public class Jeu implements KeyListener, ActionListener {
}
private void resetPartie() {
if(horloge != null) {
horloge.stop();
}
horloge = new Timer(40, this);
demiCercleAvant = new Cercle(90, -180);
demiCercleArriere = new Cercle(90, 180);
laligne = new Ligne();
demiCercleArriere.setCouleur(new Color(0.8f, 0.0f, 0.0f));
demiCercleAvant.setCouleur(new Color(1.0f, 0.2f, 0.2f));
ecran.viderObjets();
ecran.ajouterObjet(demiCercleArriere);
ecran.ajouterObjet(demiCercleAvant);

View File

@@ -0,0 +1,55 @@
package linea;
import java.awt.*;
import javax.swing.*;
public class MenuCampagne extends JPanel {
public MenuCampagne(Jeu jeu) {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
setBackground(new Color(45, 45, 45)); // Même gris foncé
JLabel titre = new JLabel("CAMPAGNES");
titre.setForeground(Color.WHITE);
titre.setFont(new Font("SansSerif", Font.BOLD, 40));
titre.setAlignmentX(Component.CENTER_ALIGNMENT);
JButton btnC1 = creerBouton("CAMPAGNE 1");
JButton btnC2 = creerBouton("CAMPAGNE 2");
JButton btnC3 = creerBouton("CAMPAGNE 3");
JButton btnC4 = creerBouton("CAMPAGNE 4");
JButton btnRetour = creerBouton("RETOUR");
btnC1.addActionListener(e -> System.out.println("Lancement Campagne 1..."));
btnC2.addActionListener(e -> System.out.println("Lancement Campagne 2..."));
btnRetour.addActionListener(e -> jeu.afficherMenuPrincipal());
add(Box.createVerticalGlue());
add(titre);
add(Box.createRigidArea(new Dimension(0, 40)));
add(btnC1);
add(Box.createRigidArea(new Dimension(0, 10)));
add(btnC2);
add(Box.createRigidArea(new Dimension(0, 10)));
add(btnC3);
add(Box.createRigidArea(new Dimension(0, 10)));
add(btnC4);
add(Box.createRigidArea(new Dimension(0, 30))); // Espace plus grand avant le retour
add(btnRetour);
add(Box.createVerticalGlue());
}
private JButton creerBouton(String texte) {
JButton b = new JButton(texte);
b.setFont(new Font("SansSerif", Font.PLAIN, 18)); // Légèrement plus petit si tu veux
b.setAlignmentX(Component.CENTER_ALIGNMENT);
b.setMaximumSize(new Dimension(200, 45));
b.setFocusable(false);
return b;
}
}

View File

@@ -3,12 +3,12 @@ package linea;
import java.awt.*;
import javax.swing.*;
public class MenuPrincipal extends JPanel{
public class MenuPrincipal extends JPanel {
private JButton btnPlay;
private JButton btnCampaign; // Nouveau bouton
private JButton btnSettings;
private JButton btnQuit;
public MenuPrincipal(Jeu jeu) {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
setBackground(new Color(45, 45, 45)); // Gris foncé
@@ -19,22 +19,30 @@ public class MenuPrincipal extends JPanel{
titre.setFont(new Font("SansSerif", Font.BOLD, 60));
titre.setAlignmentX(Component.CENTER_ALIGNMENT);
// Boutons
// Création des Boutons
btnPlay = creerBouton("PLAY");
btnCampaign = creerBouton("CAMPAGNES"); // Création
btnSettings = creerBouton("SETTINGS");
btnQuit = creerBouton("QUIT");
// Actions
btnPlay.addActionListener(e -> jeu.lancerPartie());
// Action pour aller vers le menu campagne
// (Assure-toi d'avoir cette méthode dans ta classe Jeu)
btnCampaign.addActionListener(e -> jeu.afficherMenuCampagne());
btnSettings.addActionListener(e -> JOptionPane.showMessageDialog(this, "Options bientôt disponibles !"));
btnQuit.addActionListener(e -> System.exit(0));
// Mise en page (espacement)
// Mise en page (espacement vertical)
add(Box.createVerticalGlue());
add(titre);
add(Box.createRigidArea(new Dimension(0, 50)));
add(btnPlay);
add(Box.createRigidArea(new Dimension(0, 15)));
add(btnCampaign); // Ajout à l'affichage
add(Box.createRigidArea(new Dimension(0, 15)));
add(btnSettings);
add(Box.createRigidArea(new Dimension(0, 15)));
add(btnQuit);
@@ -46,7 +54,7 @@ public class MenuPrincipal extends JPanel{
b.setFont(new Font("SansSerif", Font.PLAIN, 20));
b.setAlignmentX(Component.CENTER_ALIGNMENT);
b.setMaximumSize(new Dimension(200, 50));
b.setFocusable(false); // Pour ne pas voler le focus du clavier plus tard
b.setFocusable(false);
return b;
}
}
}