diff --git a/img/backButton.png b/img/backButton.png new file mode 100644 index 0000000..de71bd3 Binary files /dev/null and b/img/backButton.png differ diff --git a/src/BoutonClickListener.java b/src/BoutonClickListener.java new file mode 100644 index 0000000..a930fef --- /dev/null +++ b/src/BoutonClickListener.java @@ -0,0 +1,46 @@ +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.BorderLayout; +import javax.swing.JOptionPane; + +/** + * Listener for button clicks in the menu. + * It performs different actions based on the button clicked. + */ +class ButtonClickListener implements ActionListener { + private Window window; + + /** + * Constructs a ButtonClickListener with the specified window. + * @param window The window where the actions will be performed. + */ + public ButtonClickListener(Window window) { + this.window = window; + } + + /** + * Performs an action based on the button clicked. + * @param e The ActionEvent representing the button click. + */ + @Override + public void actionPerformed(ActionEvent e) { + String buttonText = ((Button) e.getSource()).getText(); + switch (buttonText) { + case "Jouer": + System.out.println("JOUER"); // À SUPPRIMER APRÈS DEBUG + break; + case "Comment jouer ?": + RulesDialogManager.showRulesDialog(); // Ouvre une fenêtre de dialogue avec les règles + break; + case "Paramètres": + // Code pour les paramètres + break; + case "Quitter": + System.exit(0); // Quitter le programme + break; + default: + break; + } + } + +} diff --git a/src/Main.java b/src/Main.java index 0793808..471a58d 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,5 +1,9 @@ +import javax.swing.*; +import java.awt.*; + public class Main{ public static void main(String[] args) { - MenuView menu = new MenuView(); + Window fenetre = new Window(); // Création d'une fenêtre + MenuView menu = new MenuView(fenetre); // Création du menu sur la fenêtre } } \ No newline at end of file diff --git a/src/MenuView.java b/src/MenuView.java index ad7ccc0..bfa035f 100644 --- a/src/MenuView.java +++ b/src/MenuView.java @@ -1,85 +1,75 @@ import javax.swing.*; import java.awt.*; -/** - * A menu view for a Sudoku application. - * @version 1.0 - * @author Moncef STITI - * @author Marco ORFAO - */ +public class MenuView { -public class MenuView extends JFrame { - private String scheminIconAudio = new String("../img/iconeAudio.png"); - private String scheminIconAudioMuted = new String("../img/iconeAudioMuted.png"); - private String scheminMusique = new String("../audio/musiqueDeFond.wav"); - private ImageIcon iconAudio = new ImageIcon(scheminIconAudio); - private ImageIcon iconAudioMuted = new ImageIcon(scheminIconAudioMuted); - private ImageIcon imageSudoku = new ImageIcon("../img/sudoku.png"); // Image Sudoku - private Dimension tailleFenetre = new Dimension(1000,700); // Taille de la fenêtre - private Dimension tailleBouton = new Dimension(300, 60); // Taille des boutons - private Color couleurFond = new Color(54, 91, 109); // Couleur du fond de la fenêtre - private Color couleurTexteTitre = Color.WHITE; // Couleur du texte du titre et sous-titre - private Font policeTitre = new Font("Copperplate", Font.BOLD, 75); // Police du titre - private Font policeSousTitre = new Font("Copperplate", Font.PLAIN, 24); // Police du sous-titre - private Font policeBouton = new Font("Copperplate", Font.BOLD, 24); // Police des boutons - private String[] boutonTextes = {"Jouer", "Comment jouer ?","Paramètres", "Quitter"}; // Textes des boutons - private JLabel[] labels = {new JLabel("Sudoku Solver", SwingConstants.CENTER), // Texte du titre - new JLabel("Par Moncef & Marco", SwingConstants.CENTER)}; // Texte du sous-titre + private static final String AUDIO_ON = "../img/iconeAudio.png"; // Chemin vers l'image iconeAudio + private static final String AUDIO_OFF = "../img/iconeAudioMuted.png"; // Chemin vers l'image iconeAudioMuted + private static final String MUSIC_FILE = "../audio/musiqueDeFond.wav"; // Chemin vers la musique de fond + private static final Dimension BUTTON_SIZE = new Dimension(300, 60); // Dimension des boutons + private static final Color BACKGROUND_COLOR = new Color(54, 91, 109); // Couleur de l'arrière plan + private static final Color TITLE_TEXT_COLOR = Color.WHITE; // Couleur du titre + private static final Font TITLE_FONT = new Font("Copperplate", Font.BOLD, 75); // Police des titres + private static final Font SUBTITLE_FONT = new Font("Copperplate", Font.PLAIN, 24); // Police des sous-titres + private static final Font BUTTON_FONT = new Font("Copperplate", Font.BOLD, 24); // Police des boutons + private static final String[] BUTTON_TEXTS = {"Jouer", "Comment jouer ?", "Paramètres", "Quitter"}; // Texte des boutons + private static final JLabel[] labels = { + new JLabel("Sudoku Solver", SwingConstants.CENTER), // Titre + new JLabel("Par Moncef & Marco", SwingConstants.CENTER)}; // Sous Titre + private final MusicButton musicButton; + private Window window; - - /** - * Constructs a MenuView. - * Initializes and configures the menu window with buttons and controls. - */ - public MenuView() { - // Création et configuration de la fenêtre - JFrame fenetre = new JFrame("Sudoku - Menu principal"); - fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - fenetre.setMinimumSize(this.tailleFenetre); - fenetre.getContentPane().setBackground(this.couleurFond); - BorderLayout gestionnaireBorderLayout = new BorderLayout(); - fenetre.setLayout(gestionnaireBorderLayout); + public MenuView(Window window) { + this.window = window; + JPanel titlePanel = createTitlePanel(); + JPanel buttonPanel = createButtonPanel(); + ImageIcon iconeSudoku = new ImageIcon("../img/sudoku.png"); + JLabel imageLabel = new JLabel(iconeSudoku); - // Création et ajout du panneau de titre - JPanel panneauTitre = new JPanel(new GridLayout(2, 1)); - panneauTitre.setBackground(this.couleurFond); + BorderLayout gestionnaireFenetre = new BorderLayout(); + this.window.getContentPane().setLayout(gestionnaireFenetre); + this.window.add(titlePanel, BorderLayout.NORTH); + this.window.add(buttonPanel, BorderLayout.WEST); + this.window.add(imageLabel, BorderLayout.EAST); + this.window.setPageTitle("Menu"); - Font[] fonts = {this.policeTitre, this.policeSousTitre}; - for (int i = 0; i < this.labels.length; i++) { - this.labels[i].setFont(fonts[i]); - this.labels[i].setForeground(this.couleurTexteTitre); - panneauTitre.add(this.labels[i]); - } - fenetre.add(panneauTitre, BorderLayout.NORTH); - - // Création et ajout du panneau de boutons - JPanel panneauBouton = new JPanel(); - GridLayout gestionnairePanneauBouton = new GridLayout(boutonTextes.length, 1, 0, 10); - panneauBouton.setLayout(gestionnairePanneauBouton); - panneauBouton.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); - panneauBouton.setBackground(this.couleurFond); - Button[] boutons = new Button[boutonTextes.length]; - for (int i = 0; i < boutons.length; i++) { - boutons[i] = new Button(this.boutonTextes[i], this.tailleBouton, this.policeBouton, this.couleurFond); - panneauBouton.add(boutons[i]); - } - fenetre.add(panneauBouton, BorderLayout.WEST); - - // Ajout de l'image "sudoku.png" - JLabel imageLabel = new JLabel(this.imageSudoku); - fenetre.add(imageLabel, BorderLayout.EAST); - - // Ajout du bouton de contrôle de la musique - MusicButton musicButton = new MusicButton(this.scheminIconAudio, this.scheminIconAudioMuted, this.scheminMusique); + musicButton = new MusicButton(AUDIO_ON, AUDIO_OFF, MUSIC_FILE); FlowLayout gestionnaireControlPanel = new FlowLayout(FlowLayout.RIGHT); JPanel controlPanel = new JPanel(gestionnaireControlPanel); - controlPanel.setBackground(this.couleurFond); + controlPanel.setBackground(BACKGROUND_COLOR); controlPanel.add(musicButton); - fenetre.add(controlPanel, BorderLayout.SOUTH); + this.window.add(controlPanel, BorderLayout.SOUTH); - fenetre.pack(); - fenetre.setLocationRelativeTo(null); - fenetre.setVisible(true); + this.window.pack(); + this.window.setLocationRelativeTo(null); + this.window.setVisible(true); } -} \ No newline at end of file + + private JPanel createTitlePanel() { + GridLayout gestionnairePanel = new GridLayout(2, 1); + JPanel panel = new JPanel(gestionnairePanel); + panel.setBackground(BACKGROUND_COLOR); + for (JLabel label : this.labels) { + label.setFont(label == this.labels[0] ? TITLE_FONT : SUBTITLE_FONT); + label.setForeground(TITLE_TEXT_COLOR); + panel.add(label); + } + return panel; + } + + private JPanel createButtonPanel() { + JPanel panel = new JPanel(); + GridLayout layout = new GridLayout(BUTTON_TEXTS.length, 1, 0, 10); + panel.setLayout(layout); + panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); // Permet de ne pas coller les boutons à la fenêtre + panel.setBackground(BACKGROUND_COLOR); + ButtonClickListener listenerButton = new ButtonClickListener(this.window); + for (String text : BUTTON_TEXTS) { + Button button = new Button(text, BUTTON_SIZE, BUTTON_FONT, BACKGROUND_COLOR); + button.addActionListener(listenerButton); + panel.add(button); + } + return panel; + } +} diff --git a/src/MusicButton.java b/src/MusicButton.java index 6fdf887..58b5135 100644 --- a/src/MusicButton.java +++ b/src/MusicButton.java @@ -24,7 +24,6 @@ public class MusicButton extends JButton { * @param offIconPath The file path for the icon when music is off. * @param musicFilePath The file path for the music file to be played. */ - public MusicButton(String onIconPath, String offIconPath, String musicFilePath) { this.iconOn = new ImageIcon(onIconPath); diff --git a/src/RulesDialogManager.java b/src/RulesDialogManager.java new file mode 100644 index 0000000..260d475 --- /dev/null +++ b/src/RulesDialogManager.java @@ -0,0 +1,8 @@ +import javax.swing.JOptionPane; + +public class RulesDialogManager { + public static void showRulesDialog() { + RulesSudoku rulesPanel = new RulesSudoku(); + JOptionPane.showMessageDialog(null, rulesPanel, "Règles du Sudoku", JOptionPane.PLAIN_MESSAGE); + } +} diff --git a/src/RulesSudoku.java b/src/RulesSudoku.java new file mode 100644 index 0000000..8438516 --- /dev/null +++ b/src/RulesSudoku.java @@ -0,0 +1,35 @@ +import javax.swing.*; +import java.awt.*; + +public class RulesSudoku extends JPanel { + + public RulesSudoku() { + BorderLayout gestionnaireBorderLayout = new BorderLayout(); + this.setLayout(gestionnaireBorderLayout); + this.setBackground(new Color(54, 91, 109)); // Couleur d'arrière-plan du menu principal + + JLabel titleLabel = new JLabel("Règles du Sudoku"); + titleLabel.setFont(new Font("Copperplate", Font.BOLD, 40)); // Police du titre + titleLabel.setForeground(Color.WHITE); // Couleur du titre + + JTextArea rulesTextArea = new JTextArea(); + rulesTextArea.setText("Les règles du Sudoku :\n\n" + + "1. Le but du jeu est de remplir la grille avec une série de chiffres de 1 à 9 de telle sorte que chaque ligne, chaque colonne et chaque région de 3x3 contienne tous les chiffres de 1 à 9 sans répétition.\n\n" + + "2. Certains chiffres sont déjà placés dans la grille au départ et ne peuvent pas être modifiés.\n\n" + + "3. Utilisez la logique et le raisonnement pour remplir la grille avec les chiffres manquants.\n\n" + + "4. Le jeu est terminé lorsqu'il n'y a plus de cases vides et que toutes les règles sont respectées."); + rulesTextArea.setEditable(false); + rulesTextArea.setLineWrap(true); + rulesTextArea.setWrapStyleWord(true); + rulesTextArea.setFont(new Font("Arial", Font.PLAIN, 20)); // Police du texte des règles + rulesTextArea.setForeground(Color.WHITE); // Couleur du texte des règles + rulesTextArea.setBackground(new Color(54, 91, 109)); // Couleur d'arrière-plan du texte des règles + + JScrollPane scrollPane = new JScrollPane(rulesTextArea); + + this.add(titleLabel, BorderLayout.NORTH); + this.add(scrollPane, BorderLayout.CENTER); + + this.setPreferredSize(new Dimension(400, 500)); // Taille de la fenêtre des règles + } +} diff --git a/src/Window.java b/src/Window.java new file mode 100644 index 0000000..4b01f09 --- /dev/null +++ b/src/Window.java @@ -0,0 +1,47 @@ +import javax.swing.*; +import java.awt.*; + +public class Window extends JFrame { + /** + * The minimum size of the window. + */ + private static final Dimension MIN_WINDOW_SIZE = new Dimension(850, 700); + /** + * The title of the program. + */ + private static final String PROGRAM_TITLE = "Sudoku"; + + + /** + * The title of the current page. + */ + private String PAGE_TITLE = ""; + + /** + * Constructor + */ + public Window() { + super(PROGRAM_TITLE); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + this.setMinimumSize(this.MIN_WINDOW_SIZE); + this.setLocationRelativeTo(null); + getContentPane().setBackground(new Color(54, 91, 109)); + } + + /** + * Get the title of the current page. + * @return The title of the current page. + */ + public String getPageTitle() { + return this.PAGE_TITLE; + } + + /** + * Set the title of the current page. + * @param title The title of the current page. + */ + public void setPageTitle(String title) { + this.PAGE_TITLE = title; + this.setTitle(this.PAGE_TITLE + " - " + Window.PROGRAM_TITLE); + } +}