bouton campagne
This commit is contained in:
@@ -10,7 +10,10 @@ public class Jeu implements KeyListener, ActionListener {
|
|||||||
protected CardLayout layout;
|
protected CardLayout layout;
|
||||||
|
|
||||||
protected ZoneDessin ecran = new ZoneDessin();
|
protected ZoneDessin ecran = new ZoneDessin();
|
||||||
|
|
||||||
|
// MENUS
|
||||||
protected MenuPrincipal menu;
|
protected MenuPrincipal menu;
|
||||||
|
protected MenuCampagne menuCampagne;
|
||||||
|
|
||||||
protected Cercle demiCercleAvant;
|
protected Cercle demiCercleAvant;
|
||||||
protected Cercle demiCercleArriere;
|
protected Cercle demiCercleArriere;
|
||||||
@@ -30,23 +33,23 @@ public class Jeu implements KeyListener, ActionListener {
|
|||||||
conteneurPrincipal = new JPanel(layout);
|
conteneurPrincipal = new JPanel(layout);
|
||||||
|
|
||||||
menu = new MenuPrincipal(this);
|
menu = new MenuPrincipal(this);
|
||||||
|
menuCampagne = new MenuCampagne(this);
|
||||||
|
|
||||||
// Initialisation initiale
|
// Initialisation initiale
|
||||||
resetPartie();
|
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() {
|
ecran.btnRetour.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
// 1. On change la carte visible vers le MENU
|
afficherMenuPrincipal();
|
||||||
layout.show(conteneurPrincipal, "MENU");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
ecran.addKeyListener(this);
|
ecran.addKeyListener(this);
|
||||||
|
|
||||||
conteneurPrincipal.add(menu, "MENU");
|
conteneurPrincipal.add(menu, "MENU");
|
||||||
|
conteneurPrincipal.add(menuCampagne, "CAMPAGNE");
|
||||||
conteneurPrincipal.add(ecran, "JEU");
|
conteneurPrincipal.add(ecran, "JEU");
|
||||||
|
|
||||||
fenetre.setContentPane(conteneurPrincipal);
|
fenetre.setContentPane(conteneurPrincipal);
|
||||||
@@ -56,6 +59,20 @@ public class Jeu implements KeyListener, ActionListener {
|
|||||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
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() {
|
public void lancerPartie() {
|
||||||
resetPartie();
|
resetPartie();
|
||||||
layout.show(conteneurPrincipal, "JEU");
|
layout.show(conteneurPrincipal, "JEU");
|
||||||
@@ -65,25 +82,20 @@ public class Jeu implements KeyListener, ActionListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void resetPartie() {
|
private void resetPartie() {
|
||||||
|
|
||||||
if(horloge != null) {
|
if(horloge != null) {
|
||||||
horloge.stop();
|
horloge.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
horloge = new Timer(40, this);
|
horloge = new Timer(40, this);
|
||||||
|
|
||||||
|
|
||||||
demiCercleAvant = new Cercle(90, -180);
|
demiCercleAvant = new Cercle(90, -180);
|
||||||
demiCercleArriere = new Cercle(90, 180);
|
demiCercleArriere = new Cercle(90, 180);
|
||||||
|
|
||||||
|
|
||||||
laligne = new Ligne();
|
laligne = new Ligne();
|
||||||
|
|
||||||
|
|
||||||
demiCercleArriere.setCouleur(new Color(0.8f, 0.0f, 0.0f));
|
demiCercleArriere.setCouleur(new Color(0.8f, 0.0f, 0.0f));
|
||||||
demiCercleAvant.setCouleur(new Color(1.0f, 0.2f, 0.2f));
|
demiCercleAvant.setCouleur(new Color(1.0f, 0.2f, 0.2f));
|
||||||
|
|
||||||
|
|
||||||
ecran.viderObjets();
|
ecran.viderObjets();
|
||||||
ecran.ajouterObjet(demiCercleArriere);
|
ecran.ajouterObjet(demiCercleArriere);
|
||||||
ecran.ajouterObjet(demiCercleAvant);
|
ecran.ajouterObjet(demiCercleAvant);
|
||||||
|
|||||||
55
src/linea/MenuCampagne.java
Normal file
55
src/linea/MenuCampagne.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,12 +3,12 @@ package linea;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
public class MenuPrincipal extends JPanel{
|
public class MenuPrincipal extends JPanel {
|
||||||
private JButton btnPlay;
|
private JButton btnPlay;
|
||||||
|
private JButton btnCampaign; // Nouveau bouton
|
||||||
private JButton btnSettings;
|
private JButton btnSettings;
|
||||||
private JButton btnQuit;
|
private JButton btnQuit;
|
||||||
|
|
||||||
|
|
||||||
public MenuPrincipal(Jeu jeu) {
|
public MenuPrincipal(Jeu jeu) {
|
||||||
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||||
setBackground(new Color(45, 45, 45)); // Gris foncé
|
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.setFont(new Font("SansSerif", Font.BOLD, 60));
|
||||||
titre.setAlignmentX(Component.CENTER_ALIGNMENT);
|
titre.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
|
||||||
// Boutons
|
// Création des Boutons
|
||||||
btnPlay = creerBouton("PLAY");
|
btnPlay = creerBouton("PLAY");
|
||||||
|
btnCampaign = creerBouton("CAMPAGNES"); // Création
|
||||||
btnSettings = creerBouton("SETTINGS");
|
btnSettings = creerBouton("SETTINGS");
|
||||||
btnQuit = creerBouton("QUIT");
|
btnQuit = creerBouton("QUIT");
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
btnPlay.addActionListener(e -> jeu.lancerPartie());
|
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 !"));
|
btnSettings.addActionListener(e -> JOptionPane.showMessageDialog(this, "Options bientôt disponibles !"));
|
||||||
btnQuit.addActionListener(e -> System.exit(0));
|
btnQuit.addActionListener(e -> System.exit(0));
|
||||||
|
|
||||||
// Mise en page (espacement)
|
// Mise en page (espacement vertical)
|
||||||
add(Box.createVerticalGlue());
|
add(Box.createVerticalGlue());
|
||||||
add(titre);
|
add(titre);
|
||||||
add(Box.createRigidArea(new Dimension(0, 50)));
|
add(Box.createRigidArea(new Dimension(0, 50)));
|
||||||
add(btnPlay);
|
add(btnPlay);
|
||||||
add(Box.createRigidArea(new Dimension(0, 15)));
|
add(Box.createRigidArea(new Dimension(0, 15)));
|
||||||
|
add(btnCampaign); // Ajout à l'affichage
|
||||||
|
add(Box.createRigidArea(new Dimension(0, 15)));
|
||||||
add(btnSettings);
|
add(btnSettings);
|
||||||
add(Box.createRigidArea(new Dimension(0, 15)));
|
add(Box.createRigidArea(new Dimension(0, 15)));
|
||||||
add(btnQuit);
|
add(btnQuit);
|
||||||
@@ -46,7 +54,7 @@ public class MenuPrincipal extends JPanel{
|
|||||||
b.setFont(new Font("SansSerif", Font.PLAIN, 20));
|
b.setFont(new Font("SansSerif", Font.PLAIN, 20));
|
||||||
b.setAlignmentX(Component.CENTER_ALIGNMENT);
|
b.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
b.setMaximumSize(new Dimension(200, 50));
|
b.setMaximumSize(new Dimension(200, 50));
|
||||||
b.setFocusable(false); // Pour ne pas voler le focus du clavier plus tard
|
b.setFocusable(false);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user