package fr.monkhanny.dorfromantik.game; import fr.monkhanny.dorfromantik.utils.Database; import fr.monkhanny.dorfromantik.gui.MainMenu; import fr.monkhanny.dorfromantik.Main; import fr.monkhanny.dorfromantik.Options; import fr.monkhanny.dorfromantik.enums.Fonts; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.SQLException; import java.util.List; public class GameOver extends JPanel { private JFrame gameFrame; private int finalScore; private Database database; private MainMenu mainMenu; public GameOver(JFrame gameFrame, int finalScore, Database database, MainMenu mainMenu) { this.gameFrame = gameFrame; this.mainMenu = mainMenu; this.finalScore = finalScore; this.database = database; setLayout(new BorderLayout()); // Background image setup JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg")); background.setLayout(new BorderLayout()); this.add(background, BorderLayout.CENTER); // Main content panel JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); mainPanel.setOpaque(false); background.add(mainPanel, BorderLayout.CENTER); // Title for the Game Over message JLabel titleLabel = new JLabel("Partie terminée !"); titleLabel.setFont(Fonts.TITLE.getFont(48)); // Using the TITLE font titleLabel.setForeground(Color.WHITE); titleLabel.setAlignmentX(Component.CENTER_ALIGNMENT); mainPanel.add(titleLabel); // Spacer mainPanel.add(Box.createVerticalStrut(30)); // Display the final score JLabel scoreLabel = new JLabel("Votre score est de : " + finalScore); scoreLabel.setFont(Fonts.SCORE.getFont(36)); // Using the SCORE font scoreLabel.setForeground(Color.WHITE); scoreLabel.setAlignmentX(Component.CENTER_ALIGNMENT); scoreLabel.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0)); // Padding scoreLabel.setOpaque(true); scoreLabel.setBackground(new Color(0, 0, 0, 100)); // Background color with transparency mainPanel.add(scoreLabel); // Spacer mainPanel.add(Box.createVerticalStrut(30)); // Grouping information and funny quote try { long seriesId = Options.SEED; // Get the correct seriesId database.addScore(seriesId, finalScore); List allScores = database.getScoresBySeriesId(seriesId); // Calculate the groups int totalPlayers = allScores.size(); int groupSize = totalPlayers / 10; int playerGroup = 0; // Check if there are less than 20 players String funnyQuote = ""; if (totalPlayers < 20) { // Only show the funny quote if there are less than 20 players if(totalPlayers == 0){ funnyQuote = "Vous êtes le premier joueur à jouer à cette partie personalisée..."; } if(totalPlayers == 1){ funnyQuote = "Vous êtes le deuxième joueur à jouer à cette partie personalisée..."; } if(totalPlayers > 1){ funnyQuote = "À part vous, il y a " + totalPlayers + " joueurs qui à joué à cette partie personalisée..."; } // Display the funny quote directly JLabel quoteLabel = new JLabel(funnyQuote); quoteLabel.setFont(Fonts.SCORE.getFont(24)); quoteLabel.setForeground(Color.WHITE); quoteLabel.setAlignmentX(Component.CENTER_ALIGNMENT); mainPanel.add(quoteLabel); } else { // Calculate which group the player's score falls into for (int i = 0; i < totalPlayers; i++) { if (allScores.get(i) <= finalScore) { playerGroup = i / groupSize + 1; break; } } // Group information JPanel groupPanel = new JPanel(); groupPanel.setOpaque(false); groupPanel.setLayout(new BoxLayout(groupPanel, BoxLayout.Y_AXIS)); JLabel groupTitleLabel = new JLabel("Vous êtes dans le groupe " + playerGroup + "/10 !"); groupTitleLabel.setFont(Fonts.SCORE.getFont(24)); groupTitleLabel.setForeground(Color.WHITE); groupTitleLabel.setAlignmentX(Component.CENTER_ALIGNMENT); groupPanel.add(groupTitleLabel); JLabel groupSizeLabel = new JLabel("Il y a " + groupSize + " joueurs dans ce groupe."); groupSizeLabel.setFont(Fonts.SCORE.getFont(24)); groupSizeLabel.setForeground(Color.WHITE); groupSizeLabel.setAlignmentX(Component.CENTER_ALIGNMENT); groupPanel.add(groupSizeLabel); // Show a funny quote based on the group funnyQuote = getFunnyQuote(playerGroup); JLabel quoteLabel = new JLabel(funnyQuote); quoteLabel.setFont(Fonts.SCORE.getFont(24)); quoteLabel.setForeground(Color.WHITE); quoteLabel.setAlignmentX(Component.CENTER_ALIGNMENT); groupPanel.add(quoteLabel); // Add group information panel mainPanel.add(groupPanel); // Spacer mainPanel.add(Box.createVerticalStrut(30)); } } catch (SQLException e) { e.printStackTrace(); } // Spacer mainPanel.add(Box.createVerticalStrut(30)); // Bouton pour retourner au menu principal JButton returnButton = new JButton("Retour au Menu Principal"); returnButton.setFont(Fonts.BUTTON.getFont(24)); returnButton.setAlignmentX(Component.CENTER_ALIGNMENT); returnButton.setFocusPainted(false); // Optionnel : pour un style plus propre returnButton.setBackground(new Color(0, 0, 0)); // Couleur d'arrière-plan du bouton returnButton.setForeground(Color.BLACK); // Couleur du texte du bouton // Ajouter un listener d'action au bouton MainMenuButtonListener listener = new MainMenuButtonListener(gameFrame, null, null); returnButton.addActionListener(listener); // Ajouter le bouton au panneau principal mainPanel.add(returnButton); } private String getFunnyQuote(int playerGroup) { // A list of funny and motivational quotes based on the group switch (playerGroup) { case 1: return "Vous êtes officiellement un génie ! Peut-être même un super-héros...!"; case 2: return "Pas mal ! Mais attention, le groupe 1 vous attend avec des applaudissements !"; case 3: return "Vous êtes sur la bonne voie, mais vous avez encore un peu de chemin à parcourir !"; case 4: return "Il est encore temps d'appeler un coach... ou un ami pour vous aider !"; case 5: return "Vous êtes dans la bonne direction, mais votre GPS semble un peu perdu !"; case 6: return "Vous n'êtes pas loin du sommet, mais le sommet semble être dans un autre pays !"; case 7: return "C'est un bon début ! Peut-être qu'un peu de café améliorerait encore la situation ?!"; case 8: return "Sur le chemin de la gloire, mais vous êtes encore coincé dans les bouchons..."; case 9: return "Pas de panique, il y a encore de la place pour s'améliorer... à peu près toute la place."; case 10: return "Félicitations ! Mais peut-être que vous voudriez réessayer sans les lunettes de soleil ?"; default: return "Hé, on progresse ! Peut-être qu'un jour, vous dominerez le monde... ou du moins ce jeu !"; } } }