Rangement
This commit is contained in:
70
src/fr/monkhanny/dorfromantik/gui/BarChartPanel.java
Normal file
70
src/fr/monkhanny/dorfromantik/gui/BarChartPanel.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import javax.swing.*;
|
||||
|
||||
public class BarChartPanel extends JPanel {
|
||||
private List<Integer> groupAverages;
|
||||
private int highlightedGroup;
|
||||
|
||||
public BarChartPanel(List<Integer> groupAverages, int highlightedGroup, JPanel mainPanel) {
|
||||
this.groupAverages = groupAverages;
|
||||
this.highlightedGroup = highlightedGroup;
|
||||
|
||||
// Rendre le fond transparent et ajouter une bordure noire
|
||||
setBackground(new Color(0, 0, 0, 0)); // Fond transparent
|
||||
setAlignmentX(Component.CENTER_ALIGNMENT); // Centrer horizontalement
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
int barWidth = width / (groupAverages.size() + 1); // Espacement entre les groupes
|
||||
int maxScore = groupAverages.stream().max(Integer::compare).orElse(0);
|
||||
|
||||
// Dessiner les barres et leurs étiquettes (moyennes des scores)
|
||||
for (int i = 0; i < groupAverages.size(); i++) {
|
||||
int barHeight = (int) ((double) groupAverages.get(i) / maxScore * (height - 50)); // Ajuster la hauteur des barres
|
||||
int xPosition = (i + 1) * barWidth; // Espacement entre les groupes
|
||||
|
||||
// Appliquer une couleur de barre (mettre en évidence le groupe du joueur en rouge, les autres en bleu)
|
||||
if (i == highlightedGroup) {
|
||||
g.setColor(new Color(204, 0, 0)); // Couleur rouge pour le groupe du joueur
|
||||
} else {
|
||||
g.setColor(new Color(0, 0, 204)); // Bleu pour les autres groupes
|
||||
}
|
||||
|
||||
// Ajouter des ombres à la barre pour un effet 3D
|
||||
g.fillRect(xPosition, height - barHeight - 30, barWidth - 5, barHeight);
|
||||
g.setColor(new Color(0, 0, 0, 60)); // Ombre
|
||||
g.fillRect(xPosition + 2, height - barHeight - 28, barWidth - 5, barHeight);
|
||||
|
||||
// Dessiner le texte (moyenne) au-dessus de chaque barre
|
||||
String avgScoreText = String.valueOf(groupAverages.get(i));
|
||||
FontMetrics metrics = g.getFontMetrics();
|
||||
int textWidth = metrics.stringWidth(avgScoreText);
|
||||
int textX = xPosition + (barWidth - textWidth) / 2; // Centrer le texte
|
||||
int textY = height - barHeight - 35; // Placer le texte juste au-dessus de la barre
|
||||
|
||||
g.setColor(Color.BLACK); // Couleur du texte
|
||||
g.drawString(avgScoreText, textX, textY);
|
||||
|
||||
// Ajouter un label pour préciser que c'est la "moyenne"
|
||||
g.setFont(new Font("Arial", Font.ITALIC, 12)); // Police italique plus petite pour le label "Moyenne"
|
||||
String label = "Score moyen : ";
|
||||
int labelWidth = metrics.stringWidth(label);
|
||||
g.drawString(label, xPosition + (barWidth - labelWidth) / 2, textY - 15); // Placer "Moyenne" au-dessus du score
|
||||
|
||||
// Dessiner l'étiquette de groupe (Groupe 1, Groupe 2, ...)
|
||||
String groupLabel = "Groupe " + (i + 1);
|
||||
g.setColor(Color.BLACK);
|
||||
g.setFont(new Font("Arial", Font.PLAIN, 14)); // Police plus petite pour les étiquettes
|
||||
int groupLabelWidth = g.getFontMetrics().stringWidth(groupLabel);
|
||||
g.drawString(groupLabel, xPosition + (barWidth - groupLabelWidth) / 2, height - 10); // Positionner l'étiquette sous la barre
|
||||
}
|
||||
}
|
||||
|
||||
}
|
104
src/fr/monkhanny/dorfromantik/gui/GameControlsMenu.java
Normal file
104
src/fr/monkhanny/dorfromantik/gui/GameControlsMenu.java
Normal file
@@ -0,0 +1,104 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.net.URL;
|
||||
|
||||
public class GameControlsMenu extends JPanel {
|
||||
private boolean isVisible = true;
|
||||
|
||||
// Chemin de base pour les icônes
|
||||
private static final String ICON_PATH = "/ressources/images/Icone/Keyboard-Mouse/";
|
||||
|
||||
public GameControlsMenu() {
|
||||
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); // Mise en page verticale
|
||||
setBackground(new Color(0, 0, 0, 150)); // Fond semi-transparent
|
||||
|
||||
// Augmenter la taille du menu
|
||||
setPreferredSize(new Dimension(350, 400)); // Taille du menu augmentée
|
||||
|
||||
// Ajouter des instructions avec des icônes pour chaque touche
|
||||
add(createPanel("Cacher/Montrer ce menu", "t.png"));
|
||||
add(createPanelWithMultipleIcons("Zoom avant/arrière", "ctrl.png", "mouse-middle.png"));
|
||||
add(createPanel("Déplacer le plateau", "keyboard-arrows.png"));
|
||||
add(createPanel("Ajuster la vue", "space.png"));
|
||||
add(createPanel("Placer une tuile", "mouse-left.png"));
|
||||
add(createPanel("Afficher le menu de pause", "esc.png"));
|
||||
|
||||
// Rendre le texte plus lisible
|
||||
setForeground(Color.WHITE);
|
||||
}
|
||||
|
||||
// Crée un JPanel avec l'icône et le texte aligné horizontalement
|
||||
private JPanel createPanel(String text, String iconName) {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 5)); // Alignement à gauche
|
||||
panel.setOpaque(false); // Transparent pour le fond
|
||||
|
||||
// Ajouter l'icône redimensionnée
|
||||
JLabel iconLabel = new JLabel(loadIcon(iconName));
|
||||
panel.add(iconLabel);
|
||||
|
||||
// Ajouter le texte avec une taille de police plus grande
|
||||
JLabel textLabel = new JLabel(text);
|
||||
textLabel.setForeground(Color.WHITE);
|
||||
textLabel.setFont(new Font("Arial", Font.PLAIN, 18)); // Augmenter la taille de la police
|
||||
panel.add(textLabel);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
// Crée un JPanel avec plusieurs icônes et un texte, en ajoutant un "+" entre les icônes
|
||||
private JPanel createPanelWithMultipleIcons(String text, String... iconNames) {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 5)); // Alignement à gauche
|
||||
panel.setOpaque(false); // Transparent pour le fond
|
||||
|
||||
// Ajouter les icônes et le signe "+" entre elles
|
||||
for (int i = 0; i < iconNames.length; i++) {
|
||||
JLabel iconLabel = new JLabel(loadIcon(iconNames[i]));
|
||||
panel.add(iconLabel);
|
||||
|
||||
// Si ce n'est pas la dernière icône, ajouter un "+" entre les icônes
|
||||
if (i < iconNames.length - 1) {
|
||||
JLabel plusLabel = new JLabel("+");
|
||||
plusLabel.setForeground(Color.WHITE); // Vous pouvez aussi styliser le "+"
|
||||
panel.add(plusLabel);
|
||||
}
|
||||
}
|
||||
|
||||
// Ajouter le texte avec une taille de police plus grande
|
||||
JLabel textLabel = new JLabel(text);
|
||||
textLabel.setForeground(Color.WHITE);
|
||||
textLabel.setFont(new Font("Arial", Font.PLAIN, 18)); // Augmenter la taille de la police
|
||||
panel.add(textLabel);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
// Charge l'icône depuis le répertoire spécifié et la redimensionne
|
||||
private ImageIcon loadIcon(String iconName) {
|
||||
// Utilisation de getClass().getResource() pour charger l'icône depuis le classpath
|
||||
URL iconURL = getClass().getResource(ICON_PATH + iconName);
|
||||
if (iconURL != null) {
|
||||
ImageIcon icon = new ImageIcon(iconURL);
|
||||
Image img = icon.getImage();
|
||||
// Redimensionner l'image à une taille plus grande
|
||||
Image scaledImg = img.getScaledInstance(55, 55, Image.SCALE_SMOOTH); // Augmenter la taille des icônes
|
||||
return new ImageIcon(scaledImg);
|
||||
} else {
|
||||
System.out.println("Icone non trouvée : " + iconName);
|
||||
return new ImageIcon();
|
||||
}
|
||||
}
|
||||
|
||||
public void toggleVisibility() {
|
||||
isVisible = !isVisible;
|
||||
setVisible(isVisible);
|
||||
}
|
||||
|
||||
public void setControlsMenuVisible(boolean visible) {
|
||||
isVisible = visible;
|
||||
setVisible(visible);
|
||||
}
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class GameModeFilterButtonActionListener implements ActionListener {
|
||||
private GameModeSelectionPanel panel;
|
||||
|
||||
public GameModeFilterButtonActionListener(GameModeSelectionPanel panel) {
|
||||
this.panel = panel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
panel.setCurrentPage(1); // Reset to first page when filtering
|
||||
panel.loadSeriesForCurrentPage();
|
||||
}
|
||||
}
|
@@ -1,46 +0,0 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import javax.swing.JButton;
|
||||
|
||||
public class GameModeHoverEffectMouseListener extends MouseAdapter {
|
||||
private Color defaultColor;
|
||||
private Color hoverColor;
|
||||
private Color clickColor;
|
||||
|
||||
public GameModeHoverEffectMouseListener(Color defaultColor, Color hoverColor, Color clickColor) {
|
||||
this.defaultColor = defaultColor;
|
||||
this.hoverColor = hoverColor;
|
||||
this.clickColor = clickColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
if (e.getSource() instanceof JButton button) {
|
||||
button.setBackground(hoverColor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
if (e.getSource() instanceof JButton button) {
|
||||
button.setBackground(defaultColor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.getSource() instanceof JButton button) {
|
||||
button.setBackground(clickColor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.getSource() instanceof JButton button) {
|
||||
button.setBackground(hoverColor);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class GameModeNextButtonActionListener implements ActionListener {
|
||||
private GameModeSelectionPanel panel;
|
||||
|
||||
public GameModeNextButtonActionListener(GameModeSelectionPanel panel) {
|
||||
this.panel = panel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
panel.setCurrentPage(panel.getCurrentPage() + 1);
|
||||
panel.loadSeriesForCurrentPage();
|
||||
}
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class GameModePrevButtonActionListener implements ActionListener {
|
||||
private GameModeSelectionPanel panel;
|
||||
|
||||
public GameModePrevButtonActionListener(GameModeSelectionPanel panel) {
|
||||
this.panel = panel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (panel.getCurrentPage() > 1) {
|
||||
panel.setCurrentPage(panel.getCurrentPage() - 1);
|
||||
panel.loadSeriesForCurrentPage();
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,6 +2,10 @@ package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.components.Title;
|
||||
import fr.monkhanny.dorfromantik.listeners.CloseButtonListener;
|
||||
import fr.monkhanny.dorfromantik.listeners.GameModeFilterButtonActionListener;
|
||||
import fr.monkhanny.dorfromantik.listeners.GameModeHoverEffectMouseListener;
|
||||
import fr.monkhanny.dorfromantik.listeners.GameModeNextButtonActionListener;
|
||||
import fr.monkhanny.dorfromantik.listeners.GameModePrevButtonActionListener;
|
||||
import fr.monkhanny.dorfromantik.utils.Database;
|
||||
|
||||
import javax.swing.*;
|
||||
|
176
src/fr/monkhanny/dorfromantik/gui/GameOver.java
Normal file
176
src/fr/monkhanny/dorfromantik/gui/GameOver.java
Normal file
@@ -0,0 +1,176 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.utils.Database;
|
||||
import fr.monkhanny.dorfromantik.listeners.GameMainMenuButtonListener;
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
import fr.monkhanny.dorfromantik.enums.Fonts;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GameOver extends JPanel {
|
||||
private JFrame gameFrame;
|
||||
|
||||
public GameOver(JFrame gameFrame, int finalScore, Database database, MainMenu mainMenu) {
|
||||
this.gameFrame = gameFrame;
|
||||
this.gameFrame.setTitle("Partie terminée - Dorfromantik");
|
||||
|
||||
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<Integer> allScores = database.getScoresBySeriesId(seriesId);
|
||||
|
||||
// Check if there are enough players to form groups
|
||||
int totalPlayers = allScores.size();
|
||||
if (totalPlayers >= 100) {
|
||||
int groupSize = totalPlayers / 10;
|
||||
int playerGroup = 0;
|
||||
|
||||
// Group data for bar chart
|
||||
List<Integer> groupAverages = new ArrayList<>();
|
||||
|
||||
// Calculate which group the player's score falls into and the average score for each group
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int startIdx = i * groupSize;
|
||||
int endIdx = Math.min((i + 1) * groupSize, totalPlayers);
|
||||
if (startIdx < totalPlayers) {
|
||||
List<Integer> groupScores = allScores.subList(startIdx, endIdx);
|
||||
int groupSum = 0;
|
||||
for (int score : groupScores) {
|
||||
groupSum += score;
|
||||
}
|
||||
groupAverages.add(groupSum / groupScores.size());
|
||||
if (scoreInGroup(allScores, finalScore, startIdx, endIdx)) {
|
||||
playerGroup = i + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Group information panel
|
||||
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);
|
||||
|
||||
BarChartPanel barChartPanel = new BarChartPanel(groupAverages, playerGroup - 1, mainPanel);
|
||||
barChartPanel.setPreferredSize(new Dimension(700, 400));
|
||||
barChartPanel.setAlignmentX(Component.CENTER_ALIGNMENT); // Centrer horizontalement
|
||||
groupPanel.add(barChartPanel);
|
||||
|
||||
groupPanel.add(Box.createVerticalStrut(30));
|
||||
|
||||
// Show a funny quote based on the group
|
||||
String 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);
|
||||
} else {
|
||||
// No groups, display a simple message instead
|
||||
JLabel noGroupsLabel = new JLabel("Pas mal !");
|
||||
noGroupsLabel.setFont(Fonts.SCORE.getFont(24));
|
||||
noGroupsLabel.setForeground(Color.WHITE);
|
||||
noGroupsLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
mainPanel.add(noGroupsLabel);
|
||||
}
|
||||
|
||||
} 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
|
||||
GameMainMenuButtonListener listener = new GameMainMenuButtonListener(gameFrame);
|
||||
returnButton.addActionListener(listener);
|
||||
|
||||
// Ajouter le bouton au panneau principal
|
||||
mainPanel.add(returnButton);
|
||||
}
|
||||
|
||||
|
||||
private boolean scoreInGroup(List<Integer> allScores, int finalScore, int startIdx, int endIdx) {
|
||||
for (int i = startIdx; i < endIdx; i++) {
|
||||
if (allScores.get(i) == finalScore) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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 vous n'êtes pas encore le roi du monde... ou du moins de ce jeu !";
|
||||
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 pour vous aider... ou de tricher !";
|
||||
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 "Félicitations ! Mais peut-être que vous voudriez réessayer sans les lunettes de soleil ?";
|
||||
case 10: return "L'important c'est de participer, non ? Mais vous pourriez essayer de jouer les yeux ouvert la prochaine fois !";
|
||||
default: return "Hé, on progresse ! Peut-être qu'un jour, vous dominerez le monde... ou du moins ce jeu !";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user