Un peu de ménage dans le git
This commit is contained in:
236
src/fr/monkhanny/dorfromantik/game/GameOver.java
Normal file
236
src/fr/monkhanny/dorfromantik/game/GameOver.java
Normal file
@@ -0,0 +1,236 @@
|
||||
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
|
||||
List<Integer> 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();
|
||||
}
|
||||
|
||||
// Input panel for username and submission
|
||||
JPanel inputPanel = createInputPanel();
|
||||
mainPanel.add(inputPanel);
|
||||
|
||||
// Spacer
|
||||
mainPanel.add(Box.createVerticalStrut(30));
|
||||
}
|
||||
|
||||
|
||||
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 !";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private JPanel createInputPanel() {
|
||||
JPanel inputPanel = new JPanel();
|
||||
inputPanel.setLayout(new BoxLayout(inputPanel, BoxLayout.Y_AXIS));
|
||||
inputPanel.setOpaque(false);
|
||||
|
||||
// Username label and text field
|
||||
JPanel namePanel = new JPanel();
|
||||
namePanel.setOpaque(false);
|
||||
JLabel nameLabel = new JLabel("Entrez votre pseudo :");
|
||||
nameLabel.setForeground(Color.WHITE);
|
||||
nameLabel.setFont(Fonts.SCORE.getFont(24));
|
||||
namePanel.add(nameLabel);
|
||||
|
||||
JTextField nameField = new JTextField(20);
|
||||
nameField.setFont(Fonts.SCORE.getFont(18));
|
||||
nameField.setPreferredSize(new Dimension(250, 40));
|
||||
nameField.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
||||
nameField.setText("Anonyme");
|
||||
namePanel.add(nameField);
|
||||
|
||||
inputPanel.add(namePanel);
|
||||
|
||||
// Spacer between name field and button
|
||||
inputPanel.add(Box.createVerticalStrut(20));
|
||||
|
||||
// Add flexible space at the bottom to push the button down
|
||||
inputPanel.add(Box.createVerticalGlue());
|
||||
|
||||
// Submit button
|
||||
JButton submitButton = new JButton("Soumettre");
|
||||
submitButton.setFont(Fonts.BUTTON.getFont(24)); // Using the BUTTON font
|
||||
submitButton.setBackground(new Color(0, 255, 0));
|
||||
submitButton.setForeground(Color.WHITE);
|
||||
submitButton.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
||||
submitButton.setPreferredSize(new Dimension(150, 50));
|
||||
|
||||
// Center the button horizontally using BoxLayout
|
||||
submitButton.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
inputPanel.add(submitButton);
|
||||
|
||||
// Action to handle score submission
|
||||
submitButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String username = nameField.getText().trim();
|
||||
if (username.isEmpty()) {
|
||||
username = "Anonyme"; // Default to "Anonyme" if no name is given
|
||||
}
|
||||
|
||||
// Save the score to the database
|
||||
try {
|
||||
long seriesId = Options.SEED; // Replace with the appropriate series ID
|
||||
database.addScore(username, seriesId, finalScore);
|
||||
|
||||
// Débloquer les récompenses pour ce joueur
|
||||
database.unlockRewards(username, finalScore);
|
||||
|
||||
JOptionPane.showMessageDialog(gameFrame, "Score enregistré et récompenses débloquées !");
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(gameFrame, "Erreur lors de l'enregistrement du score : " + ex.getMessage());
|
||||
}
|
||||
|
||||
// Fermer la fenêtre de jeu
|
||||
Main.resetGame();
|
||||
}
|
||||
});
|
||||
return inputPanel;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user