Correction du style
This commit is contained in:
@@ -8,6 +8,8 @@ import javax.swing.*;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class GameOver extends JPanel {
|
public class GameOver extends JPanel {
|
||||||
private JFrame gameFrame;
|
private JFrame gameFrame;
|
||||||
@@ -23,58 +25,155 @@ public class GameOver extends JPanel {
|
|||||||
|
|
||||||
// Background image setup
|
// Background image setup
|
||||||
JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg"));
|
JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg"));
|
||||||
background.setLayout(new GridBagLayout());
|
background.setLayout(new BorderLayout());
|
||||||
this.add(background);
|
this.add(background, BorderLayout.CENTER);
|
||||||
|
|
||||||
// Main content panel
|
// Main content panel
|
||||||
JPanel mainPanel = createMainPanel();
|
JPanel mainPanel = new JPanel();
|
||||||
background.add(mainPanel);
|
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
|
||||||
|
mainPanel.setOpaque(false);
|
||||||
|
background.add(mainPanel, BorderLayout.CENTER);
|
||||||
|
|
||||||
// Title for the Game Over message
|
// Title for the Game Over message
|
||||||
JLabel titleLabel = new JLabel("Partie terminée !");
|
JLabel titleLabel = new JLabel("Partie terminée !");
|
||||||
titleLabel.setFont(Fonts.TITLE.getFont(48)); // Using the TITLE font
|
titleLabel.setFont(Fonts.TITLE.getFont(48)); // Using the TITLE font
|
||||||
titleLabel.setForeground(Color.WHITE);
|
titleLabel.setForeground(Color.WHITE);
|
||||||
mainPanel.add(titleLabel, createGridBagConstraints(0, 0, 2));
|
titleLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
mainPanel.add(titleLabel);
|
||||||
|
|
||||||
|
// Spacer
|
||||||
|
mainPanel.add(Box.createVerticalStrut(30));
|
||||||
|
|
||||||
// Display final score
|
// Display final score
|
||||||
JLabel scoreLabel = new JLabel("Votre score est de : " + finalScore);
|
JLabel scoreLabel = new JLabel("Votre score est de : " + finalScore);
|
||||||
scoreLabel.setFont(Fonts.SCORE.getFont(36)); // Using the SCORE font
|
scoreLabel.setFont(Fonts.SCORE.getFont(36)); // Using the SCORE font
|
||||||
scoreLabel.setForeground(Color.WHITE);
|
scoreLabel.setForeground(Color.WHITE);
|
||||||
mainPanel.add(scoreLabel, createGridBagConstraints(0, 1, 2));
|
scoreLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
mainPanel.add(scoreLabel);
|
||||||
|
|
||||||
// Vertical spacer
|
// Spacer
|
||||||
mainPanel.add(Box.createVerticalStrut(20), createGridBagConstraints(0, 2, 1));
|
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
|
||||||
|
funnyQuote = "Vous n'êtes que " + totalPlayers + " à avoir 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 + " !");
|
||||||
|
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
|
// Input panel for username and submission
|
||||||
JPanel inputPanel = createInputPanel();
|
JPanel inputPanel = createInputPanel();
|
||||||
mainPanel.add(inputPanel, createGridBagConstraints(0, 3, 2));
|
mainPanel.add(inputPanel);
|
||||||
|
|
||||||
// Vertical spacer
|
// Spacer
|
||||||
mainPanel.add(Box.createVerticalStrut(20), createGridBagConstraints(0, 4, 1));
|
mainPanel.add(Box.createVerticalStrut(30));
|
||||||
}
|
}
|
||||||
|
|
||||||
private JPanel createMainPanel() {
|
|
||||||
JPanel mainPanel = new JPanel(new GridBagLayout());
|
private String getFunnyQuote(int playerGroup) {
|
||||||
mainPanel.setOpaque(false); // Transparent background
|
// A list of funny and motivational quotes based on the group
|
||||||
return mainPanel;
|
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() {
|
private JPanel createInputPanel() {
|
||||||
JPanel inputPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10));
|
JPanel inputPanel = new JPanel();
|
||||||
|
inputPanel.setLayout(new BoxLayout(inputPanel, BoxLayout.Y_AXIS));
|
||||||
inputPanel.setOpaque(false);
|
inputPanel.setOpaque(false);
|
||||||
|
|
||||||
// Username label and text field
|
// Username label and text field
|
||||||
JLabel nameLabel = new JLabel("Entrez votre pseudo (facultatif) :");
|
JPanel namePanel = new JPanel();
|
||||||
|
namePanel.setOpaque(false);
|
||||||
|
JLabel nameLabel = new JLabel("Entrez votre pseudo :");
|
||||||
nameLabel.setForeground(Color.WHITE);
|
nameLabel.setForeground(Color.WHITE);
|
||||||
nameLabel.setFont(Fonts.SCORE.getFont(24));
|
nameLabel.setFont(Fonts.SCORE.getFont(24));
|
||||||
inputPanel.add(nameLabel);
|
namePanel.add(nameLabel);
|
||||||
|
|
||||||
JTextField nameField = new JTextField(20);
|
JTextField nameField = new JTextField(20);
|
||||||
nameField.setFont(Fonts.SCORE.getFont(18));
|
nameField.setFont(Fonts.SCORE.getFont(18));
|
||||||
nameField.setPreferredSize(new Dimension(250, 40));
|
nameField.setPreferredSize(new Dimension(250, 40));
|
||||||
nameField.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
nameField.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
||||||
nameField.setText("Anonyme");
|
nameField.setText("Anonyme");
|
||||||
inputPanel.add(nameField);
|
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
|
// Submit button
|
||||||
JButton submitButton = new JButton("Soumettre");
|
JButton submitButton = new JButton("Soumettre");
|
||||||
@@ -83,6 +182,9 @@ public class GameOver extends JPanel {
|
|||||||
submitButton.setForeground(Color.WHITE);
|
submitButton.setForeground(Color.WHITE);
|
||||||
submitButton.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
submitButton.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
||||||
submitButton.setPreferredSize(new Dimension(150, 50));
|
submitButton.setPreferredSize(new Dimension(150, 50));
|
||||||
|
|
||||||
|
// Center the button horizontally using BoxLayout
|
||||||
|
submitButton.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
inputPanel.add(submitButton);
|
inputPanel.add(submitButton);
|
||||||
|
|
||||||
// Action to handle score submission
|
// Action to handle score submission
|
||||||
@@ -112,13 +214,4 @@ public class GameOver extends JPanel {
|
|||||||
return inputPanel;
|
return inputPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private GridBagConstraints createGridBagConstraints(int x, int y, int gridWidth) {
|
|
||||||
GridBagConstraints gbc = new GridBagConstraints();
|
|
||||||
gbc.gridx = x;
|
|
||||||
gbc.gridy = y;
|
|
||||||
gbc.gridwidth = gridWidth;
|
|
||||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc.insets = new Insets(10, 20, 10, 20); // Adjust spacing
|
|
||||||
return gbc;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,7 @@ import java.sql.Statement;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Database {
|
public class Database {
|
||||||
@@ -66,6 +67,28 @@ public class Database {
|
|||||||
return seed;
|
return seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<PlayerScore> getAllScores(long seriesId) throws SQLException {
|
||||||
|
List<PlayerScore> allScores = new ArrayList<>();
|
||||||
|
|
||||||
|
String query = "SELECT username, score FROM Scores WHERE series_id = ? ORDER BY score DESC";
|
||||||
|
try (PreparedStatement stmt = this.database.prepareStatement(query)) {
|
||||||
|
stmt.setLong(1, seriesId);
|
||||||
|
try (ResultSet rs = stmt.executeQuery()) {
|
||||||
|
while (rs.next()) {
|
||||||
|
String username = rs.getString("username");
|
||||||
|
if (username == null || username.trim().isEmpty()) {
|
||||||
|
username = "Joueur Anonyme"; // Default name if empty
|
||||||
|
}
|
||||||
|
int score = rs.getInt("score");
|
||||||
|
allScores.add(new PlayerScore(username, score));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return allScores;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public long getSeedByName(String name) throws SQLException {
|
public long getSeedByName(String name) throws SQLException {
|
||||||
String query = "SELECT series_id FROM Series WHERE name = " + "\'" + name + "\'" +";";
|
String query = "SELECT series_id FROM Series WHERE name = " + "\'" + name + "\'" +";";
|
||||||
long seed = -1; // Valeur par défaut si le seed n'est pas trouvé
|
long seed = -1; // Valeur par défaut si le seed n'est pas trouvé
|
||||||
@@ -143,6 +166,31 @@ public class Database {
|
|||||||
return topPlayers;
|
return topPlayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère les scores d'une série spécifique, triés en ordre décroissant (du plus élevé au plus bas)
|
||||||
|
* @param seriesId L'ID de la série
|
||||||
|
* @return Liste des scores pour la série donnée
|
||||||
|
* @throws SQLException En cas d'erreur lors de la récupération des scores
|
||||||
|
*/
|
||||||
|
public List<Integer> getScoresBySeriesId(long seriesId) throws SQLException {
|
||||||
|
List<Integer> scores = new ArrayList<>();
|
||||||
|
|
||||||
|
String query = "SELECT score FROM Scores WHERE series_id = ? ORDER BY score DESC";
|
||||||
|
try (PreparedStatement stmt = this.database.prepareStatement(query)) {
|
||||||
|
stmt.setLong(1, seriesId);
|
||||||
|
try (ResultSet rs = stmt.executeQuery()) {
|
||||||
|
while (rs.next()) {
|
||||||
|
scores.add(rs.getInt("score"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If you want the scores to be in descending order (from highest to lowest)
|
||||||
|
Collections.sort(scores, Collections.reverseOrder());
|
||||||
|
|
||||||
|
return scores;
|
||||||
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
try {
|
try {
|
||||||
if (this.database != null && !this.database.isClosed()) {
|
if (this.database != null && !this.database.isClosed()) {
|
||||||
|
Reference in New Issue
Block a user