Un peu de ménage dans le git
This commit is contained in:
110
src/fr/monkhanny/dorfromantik/Main.java
Normal file
110
src/fr/monkhanny/dorfromantik/Main.java
Normal file
@@ -0,0 +1,110 @@
|
||||
package fr.monkhanny.dorfromantik;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
import fr.monkhanny.dorfromantik.gui.RewardsPanel;
|
||||
import fr.monkhanny.dorfromantik.controller.MainMenuResizeController;
|
||||
import fr.monkhanny.dorfromantik.controller.MainMenuButtonController;
|
||||
import fr.monkhanny.dorfromantik.utils.MusicPlayer;
|
||||
import fr.monkhanny.dorfromantik.enums.Musics;
|
||||
import fr.monkhanny.dorfromantik.listeners.CloseWindowListener;
|
||||
import fr.monkhanny.dorfromantik.gui.SettingsPanel;
|
||||
import fr.monkhanny.dorfromantik.controller.TutorialController;
|
||||
import fr.monkhanny.dorfromantik.controller.GameModeController;
|
||||
import fr.monkhanny.dorfromantik.gui.GameModeSelectionPanel;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
/**
|
||||
* Classe principale du jeu
|
||||
* @version 1.0
|
||||
* @author Moncef STITI
|
||||
* @see MainMenu
|
||||
* @see MainMenuResizeController
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
private static JFrame gameModeFrame;
|
||||
private static JFrame gameFrame;
|
||||
private static JFrame settingsFrame;
|
||||
private static JFrame howToPlayFrame;
|
||||
private static JFrame rewardsFrame;
|
||||
|
||||
// Variable statique pour savoir si la musique a été jouée
|
||||
private static boolean isMusicPlayed = false;
|
||||
|
||||
// Fonction pour réinitialiser tout le jeu
|
||||
public static void resetGame() {
|
||||
// 1. Fermer toutes les fenêtres ouvertes
|
||||
if (gameModeFrame != null) {
|
||||
gameModeFrame.dispose(); // Ferme la fenêtre du choix des modes de jeu
|
||||
}
|
||||
if (gameFrame != null) {
|
||||
gameFrame.dispose(); // Ferme la fenêtre de jeu
|
||||
}
|
||||
if (settingsFrame != null) {
|
||||
settingsFrame.dispose(); // Ferme la fenêtre des paramètres
|
||||
}
|
||||
if (howToPlayFrame != null) {
|
||||
howToPlayFrame.dispose(); // Ferme la fenêtre du tutoriel
|
||||
}
|
||||
if (rewardsFrame != null) {
|
||||
rewardsFrame.dispose(); // Ferme la fenêtre des récompenses
|
||||
}
|
||||
|
||||
// 2. Réinitialiser les variables globales ou statiques si nécessaire
|
||||
Options.mainMenu = new MainMenu(); // Réinitialiser le menu principal
|
||||
|
||||
// 3. Lancer la musique uniquement si ce n'est pas déjà fait
|
||||
if (!isMusicPlayed) {
|
||||
MusicPlayer.loadMusic(Musics.MAIN_MENU_MUSIC); // Recharger la musique du menu principal
|
||||
MusicPlayer.playMusic(); // Reprendre la musique
|
||||
isMusicPlayed = true; // Marquer la musique comme jouée
|
||||
}
|
||||
|
||||
// 4. Créer les fenêtres à nouveau comme au début
|
||||
gameModeFrame = new JFrame("Choix des modes de jeu - Dorfromantik");
|
||||
gameFrame = new JFrame("Jeu - Dorfromantik");
|
||||
settingsFrame = new JFrame("Paramètres - Dorfromantik");
|
||||
howToPlayFrame = new JFrame("Comment jouer ? - Dorfromantik");
|
||||
rewardsFrame = new JFrame("Récompenses - Dorfromantik");
|
||||
|
||||
// Re-créer et réinitialiser les panels et les contrôleurs
|
||||
MainMenuResizeController mainMenuResizeController = new MainMenuResizeController(Options.mainMenu);
|
||||
MainMenuButtonController mainMenuButtonController = new MainMenuButtonController(Options.mainMenu, settingsFrame, howToPlayFrame, gameModeFrame, gameFrame, rewardsFrame);
|
||||
|
||||
// Fenêtre des paramètres
|
||||
CloseWindowListener settingsWindowListener = new CloseWindowListener(Options.mainMenu, settingsFrame);
|
||||
SettingsPanel settingsPanel = new SettingsPanel(Options.mainMenu, settingsFrame);
|
||||
settingsFrame.addWindowListener(settingsWindowListener);
|
||||
settingsFrame.add(settingsPanel);
|
||||
|
||||
// Fenêtre du tutoriel
|
||||
CloseWindowListener howToPlayWindowListener = new CloseWindowListener(Options.mainMenu, howToPlayFrame);
|
||||
TutorialController tutorialController = new TutorialController(Options.mainMenu, howToPlayFrame);
|
||||
howToPlayFrame.addWindowListener(howToPlayWindowListener);
|
||||
howToPlayFrame.add(tutorialController.getTutorialPanel());
|
||||
|
||||
// Fenêtre du choix des modes de jeu
|
||||
CloseWindowListener gameModeWindowListener = new CloseWindowListener(Options.mainMenu, gameModeFrame);
|
||||
GameModeController gameModeController = new GameModeController(gameFrame, Options.mainMenu, gameModeFrame);
|
||||
GameModeSelectionPanel gameModeSelectionPanel = new GameModeSelectionPanel(gameModeController,gameModeFrame, Options.mainMenu);
|
||||
gameModeFrame.addWindowListener(gameModeWindowListener);
|
||||
gameModeController.setGameModeSelectionPanel(gameModeSelectionPanel);
|
||||
gameModeFrame.add(gameModeSelectionPanel);
|
||||
|
||||
// Fenêtre des récompenses
|
||||
CloseWindowListener rewardsWindowListener = new CloseWindowListener(Options.mainMenu, rewardsFrame);
|
||||
rewardsFrame.addWindowListener(rewardsWindowListener);
|
||||
RewardsPanel rewardsPanel = new RewardsPanel(Options.mainMenu,rewardsFrame);
|
||||
rewardsFrame.setContentPane(rewardsPanel);
|
||||
rewardsFrame.pack();
|
||||
|
||||
// Afficher à nouveau le menu principal
|
||||
Options.mainMenu.setVisible(true);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Appel initial pour créer les fenêtres et démarrer le jeu
|
||||
resetGame(); // Appel à la fonction de réinitialisation
|
||||
}
|
||||
}
|
69
src/fr/monkhanny/dorfromantik/Options.java
Normal file
69
src/fr/monkhanny/dorfromantik/Options.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package fr.monkhanny.dorfromantik;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
|
||||
public class Options {
|
||||
|
||||
/**
|
||||
* Taille de police de base pour les titres du menu principal
|
||||
*/
|
||||
public static final float BASE_TITLE_FONT_SIZE = 80f;
|
||||
|
||||
/**
|
||||
* Taille de police de base pour les boutons du menu principal
|
||||
*/
|
||||
public static final float BASE_BUTTON_FONT_SIZE = 45f;
|
||||
|
||||
/**
|
||||
* Niveau de volume par défaut
|
||||
*/
|
||||
public static final int DEFAULT_VOLUME = 60;
|
||||
|
||||
/**
|
||||
* Musique en sourdine ou non
|
||||
*/
|
||||
public static boolean MUSIC_MUTED = false;
|
||||
|
||||
/**
|
||||
* Sons en sourdine ou non
|
||||
*/
|
||||
public static boolean SOUNDS_MUTED = false;
|
||||
|
||||
/**
|
||||
* Couleur de subrillance des boutons
|
||||
*/
|
||||
public static final Color BUTTON_HOVER_COLOR = new Color(0, 130, 180);
|
||||
|
||||
|
||||
public static final float HOVER_FONT_SCALE = 1.1f;
|
||||
public static final int ANIMATION_STEPS = 10;
|
||||
public static final int ANIMATION_DELAY = 15;
|
||||
|
||||
/**
|
||||
* Volume de la musique
|
||||
*/
|
||||
public static int MUSIC_VOLUME = 60;
|
||||
|
||||
/**
|
||||
* Volume des bruitages
|
||||
*/
|
||||
public static int SOUNDS_VOLUME = 60;
|
||||
|
||||
public static final Dimension MINIMUM_FRAME_SIZE = new Dimension(700, 700);
|
||||
|
||||
public static boolean AUTO_FOCUS = false;
|
||||
|
||||
public static final int MAX_TILE_NUMBER = 50;
|
||||
|
||||
public static boolean FULL_SCREEN = false;
|
||||
|
||||
public static final float SCORE_SIZE = 30f;
|
||||
|
||||
public static long SEED = 0;
|
||||
|
||||
public static MainMenu mainMenu;
|
||||
|
||||
public static boolean isPlaying = false;
|
||||
}
|
48
src/fr/monkhanny/dorfromantik/components/Button.java
Normal file
48
src/fr/monkhanny/dorfromantik/components/Button.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package fr.monkhanny.dorfromantik.components;
|
||||
|
||||
import fr.monkhanny.dorfromantik.utils.FontManager;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Button {
|
||||
|
||||
public static JButton createCustomTextButton(String text, float fontSize) {
|
||||
JButton button = new JButton(text);
|
||||
button.setFocusPainted(false); // Retirer le focus
|
||||
button.setBackground(new Color(102, 178, 255)); // Couleur de fond
|
||||
button.setForeground(Color.WHITE); // Couleur du texte
|
||||
button.setFont(FontManager.getButtonFont(fontSize)); // Appliquer la police du bouton
|
||||
button.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20)); // Espacement autour du texte du bouton
|
||||
return button;
|
||||
}
|
||||
|
||||
public static JButton createCustomIconButton(String iconPath) {
|
||||
// Créer le bouton
|
||||
JButton button = new JButton();
|
||||
button.setFocusPainted(false); // Retirer le focus
|
||||
|
||||
// Charger l'icône depuis le chemin spécifié
|
||||
ImageIcon icon = new ImageIcon(iconPath);
|
||||
|
||||
// Calculer automatiquement la taille de l'icône pour l'adapter à la taille du bouton
|
||||
int buttonWidth = 100; // Taille du bouton (largeur)
|
||||
int buttonHeight = 100; // Taille du bouton (hauteur)
|
||||
|
||||
// Vous pouvez ajuster ces valeurs ou les calculer dynamiquement en fonction de la taille du bouton
|
||||
Image img = icon.getImage();
|
||||
Image resizedImage = img.getScaledInstance(buttonWidth, buttonHeight, Image.SCALE_SMOOTH);
|
||||
button.setIcon(new ImageIcon(resizedImage));
|
||||
|
||||
// Optionnel : changer la couleur de fond ou de bordure si nécessaire
|
||||
button.setBackground(new Color(102, 178, 255)); // Couleur de fond (facultatif)
|
||||
|
||||
// Retirer la bordure du bouton (facultatif)
|
||||
button.setBorder(BorderFactory.createEmptyBorder());
|
||||
|
||||
// Redimensionner le bouton pour s'adapter à l'icône si nécessaire
|
||||
button.setPreferredSize(new Dimension(buttonWidth, buttonHeight));
|
||||
|
||||
return button;
|
||||
}
|
||||
}
|
27
src/fr/monkhanny/dorfromantik/components/Title.java
Normal file
27
src/fr/monkhanny/dorfromantik/components/Title.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package fr.monkhanny.dorfromantik.components;
|
||||
|
||||
import fr.monkhanny.dorfromantik.utils.FontManager;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Title extends JLabel {
|
||||
|
||||
public Title(String text, float fontSize) {
|
||||
super(text, SwingConstants.CENTER);
|
||||
setFont(FontManager.getTitleFont(fontSize));
|
||||
setForeground(Color.WHITE);
|
||||
setBorder(BorderFactory.createEmptyBorder(20, 0, 20, 0));
|
||||
}
|
||||
|
||||
public Title(String text, float fontSize, Color textColor) {
|
||||
super(text, SwingConstants.CENTER);
|
||||
setFont(FontManager.getTitleFont(fontSize));
|
||||
setForeground(textColor);
|
||||
setBorder(BorderFactory.createEmptyBorder(20, 0, 20, 0));
|
||||
}
|
||||
|
||||
public void updateTitleFont(float fontSize) {
|
||||
setFont(FontManager.getTitleFont(fontSize));
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class ButtonHoverAnimationListener implements ActionListener {
|
||||
|
||||
private int step = 0;
|
||||
private final float scaleIncrement;
|
||||
private final boolean entering;
|
||||
private final JButton button;
|
||||
private final Color originalColor;
|
||||
private final Font originalFont;
|
||||
private float currentScale = 1.0f;
|
||||
|
||||
public ButtonHoverAnimationListener(boolean entering, JButton button, Color originalColor, Font originalFont) {
|
||||
this.entering = entering;
|
||||
this.button = button;
|
||||
this.originalColor = originalColor;
|
||||
this.originalFont = originalFont;
|
||||
this.scaleIncrement = (Options.HOVER_FONT_SCALE - 1.0f) / Options.ANIMATION_STEPS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
currentScale = entering ? (1.0f + step * scaleIncrement) : (Options.HOVER_FONT_SCALE - step * scaleIncrement);
|
||||
|
||||
button.setForeground(entering ? Options.BUTTON_HOVER_COLOR : originalColor);
|
||||
button.setFont(originalFont.deriveFont(originalFont.getSize2D() * currentScale));
|
||||
|
||||
step++;
|
||||
if (step >= Options.ANIMATION_STEPS) {
|
||||
((Timer) e.getSource()).stop();
|
||||
if (!entering) {
|
||||
button.setFont(originalFont); // Restore the original font
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.ButtonHoverAnimator;
|
||||
import fr.monkhanny.dorfromantik.utils.MusicPlayer;
|
||||
import fr.monkhanny.dorfromantik.enums.Sounds;
|
||||
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class ButtonHoverListener extends MouseAdapter {
|
||||
|
||||
private final ButtonHoverAnimator animator;
|
||||
|
||||
public ButtonHoverListener(ButtonHoverAnimator animator) {
|
||||
this.animator = animator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
animator.startAnimation(true);
|
||||
MusicPlayer.loadSound(Sounds.SOUNDS1); // Charge le son
|
||||
MusicPlayer.playSound(); // Joue le son
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
animator.startAnimation(false);
|
||||
}
|
||||
}
|
115
src/fr/monkhanny/dorfromantik/controller/GameModeController.java
Normal file
115
src/fr/monkhanny/dorfromantik/controller/GameModeController.java
Normal file
@@ -0,0 +1,115 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.GameModeSelectionPanel;
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
import fr.monkhanny.dorfromantik.game.Board;
|
||||
import fr.monkhanny.dorfromantik.utils.Database;
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.JFrame;
|
||||
import java.sql.SQLException;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Point;
|
||||
|
||||
public class GameModeController implements ActionListener {
|
||||
|
||||
private GameModeSelectionPanel gameModeSelectionPanel;
|
||||
private JFrame gameFrame;
|
||||
private MainMenu mainMenu;
|
||||
private Database database;
|
||||
private JFrame gameModeFrame;
|
||||
private static Board board;
|
||||
|
||||
// Constructeur sans le panneau
|
||||
public GameModeController(JFrame gameFrame, MainMenu mainMenu, JFrame gameModeFrame) {
|
||||
this.gameFrame = gameFrame;
|
||||
this.mainMenu = mainMenu;
|
||||
this.gameModeFrame = gameModeFrame;
|
||||
|
||||
// Connexion à la base de données
|
||||
try {
|
||||
this.database = new Database();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Erreur lors de la connexion à la base de données: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Méthode pour associer le panneau
|
||||
public void setGameModeSelectionPanel(GameModeSelectionPanel panel) {
|
||||
this.gameModeSelectionPanel = panel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String command = e.getActionCommand();
|
||||
|
||||
switch (command) {
|
||||
case "Mode 1":
|
||||
startGame("Mode 1", getSeedFromDatabaseByName("Mode 1"));
|
||||
break;
|
||||
case "Mode 2":
|
||||
startGame("Mode 2", getSeedFromDatabaseByName("Mode 2"));
|
||||
break;
|
||||
case "Mode 3":
|
||||
startGame("Mode 3", getSeedFromDatabaseByName("Mode 3"));
|
||||
break;
|
||||
case "Mode 4":
|
||||
startGame("Mode 4", getSeedFromDatabaseByName("Mode 4"));
|
||||
break;
|
||||
case "Démarrer":
|
||||
long seed = gameModeSelectionPanel.getLongSeed();
|
||||
startGame("Custom Mode", seed);
|
||||
addCustomSeedToDatabase("Custom Mode", seed);
|
||||
break;
|
||||
default:
|
||||
System.out.println("Commande inconnue: " + command);
|
||||
}
|
||||
}
|
||||
|
||||
private long getSeedFromDatabaseByName(String modeName) {
|
||||
try {
|
||||
Options.SEED = this.database.getSeedByName(modeName);
|
||||
return Options.SEED;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return -1; // Retourner une valeur par défaut si une erreur survient
|
||||
}
|
||||
}
|
||||
|
||||
private void addCustomSeedToDatabase(String name, long seed) {
|
||||
try {
|
||||
Options.SEED = seed;
|
||||
this.database.addCustomSeed(name, seed);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
System.err.println("Erreur lors de l'ajout de la seed custom.");
|
||||
}
|
||||
}
|
||||
|
||||
private void startGame(String mode, long seed) {
|
||||
// Supprimer la potentielle ancienne instance de board
|
||||
GameModeController.board = null;
|
||||
|
||||
// Cacher la fenêtre avant de faire des modifications
|
||||
this.gameFrame.setVisible(false);
|
||||
|
||||
if (Options.FULL_SCREEN) {
|
||||
gameFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); // Set frame to full screen
|
||||
} else {
|
||||
Dimension mainMenuSize = this.mainMenu.getSize();
|
||||
Point mainMenuLocation = this.mainMenu.getLocation();
|
||||
gameFrame.setSize(mainMenuSize);
|
||||
gameFrame.setLocation(mainMenuLocation);
|
||||
}
|
||||
GameModeController.board = new Board(this.gameFrame,seed);
|
||||
//this.gameModeFrame.setVisible(false);
|
||||
this.gameFrame.setVisible(true);
|
||||
this.gameFrame.add(board);
|
||||
}
|
||||
|
||||
public static Board getGameModeBoard() {
|
||||
return board;
|
||||
}
|
||||
}
|
@@ -0,0 +1,132 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
import fr.monkhanny.dorfromantik.gui.ButtonPanel;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Point;
|
||||
|
||||
|
||||
|
||||
public class MainMenuButtonController implements ActionListener {
|
||||
|
||||
private MainMenu mainMenu;
|
||||
|
||||
private JFrame settingsFrame;
|
||||
private JFrame howToPlayFrame;
|
||||
private JFrame gameModeFrame;
|
||||
private JFrame gameFrame;
|
||||
private JFrame rewardsFrame;
|
||||
|
||||
public MainMenuButtonController(MainMenu mainMenu, JFrame settingsFrame, JFrame howToPlayFrame, JFrame gameModeFrame, JFrame gameFrame, JFrame rewardsFrame) {
|
||||
this.mainMenu = mainMenu;
|
||||
// Ajouter les écouteurs d'événements sur les boutons
|
||||
ButtonPanel buttonPanel = mainMenu.getButtonPanel();
|
||||
|
||||
// Attacher les actions aux boutons du menu principal
|
||||
buttonPanel.getNewGameButton().addActionListener(this);
|
||||
buttonPanel.getContinueGameButton().addActionListener(this);
|
||||
buttonPanel.getHowToPlayButton().addActionListener(this);
|
||||
buttonPanel.getSettingsButton().addActionListener(this);
|
||||
buttonPanel.getExitButton().addActionListener(this);
|
||||
|
||||
// Paramètrage de la fenêtre des paramètres
|
||||
this.settingsFrame = settingsFrame;
|
||||
configureFrame(this.settingsFrame);
|
||||
|
||||
// Paramètrage de la fenêtre du tutoriel
|
||||
this.howToPlayFrame = howToPlayFrame;
|
||||
configureFrame(this.howToPlayFrame);
|
||||
|
||||
// Paramètrage de la fenêtre du jeu
|
||||
this.gameModeFrame = gameModeFrame;
|
||||
configureFrame(this.gameModeFrame);
|
||||
|
||||
// Paramètrage de la fenêtre du jeu
|
||||
this.gameFrame = gameFrame;
|
||||
configureFrame(this.gameFrame);
|
||||
|
||||
// Paramètrage de la fenêtre des récompenses
|
||||
this.rewardsFrame = rewardsFrame;
|
||||
configureFrame(this.rewardsFrame);
|
||||
}
|
||||
|
||||
private void configureFrame(JFrame frame) {
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setVisible(false);
|
||||
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String command = e.getActionCommand();
|
||||
|
||||
switch (command) {
|
||||
case "Jouer":
|
||||
startNewGame();
|
||||
break;
|
||||
case "Récompenses":
|
||||
openRecompense();
|
||||
break;
|
||||
case "Comment jouer ?":
|
||||
showHowToPlay();
|
||||
break;
|
||||
case "Paramètres":
|
||||
openSettings();
|
||||
break;
|
||||
case "Quitter":
|
||||
exitGame();
|
||||
break;
|
||||
default:
|
||||
System.out.println("Commande inconnue: " + command);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void startNewGame() {
|
||||
adjustFrameDisplay(this.gameModeFrame);
|
||||
this.mainMenu.setVisible(false);
|
||||
this.gameModeFrame.setVisible(true);
|
||||
}
|
||||
|
||||
private void openRecompense() {
|
||||
adjustFrameDisplay(this.rewardsFrame);
|
||||
this.mainMenu.setVisible(false);
|
||||
this.rewardsFrame.setVisible(true);
|
||||
}
|
||||
|
||||
public void showHowToPlay() {
|
||||
adjustFrameDisplay(this.howToPlayFrame);
|
||||
this.mainMenu.setVisible(false);
|
||||
this.howToPlayFrame.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
private void exitGame() {
|
||||
System.exit(0); // Fermer l'application
|
||||
}
|
||||
|
||||
private void openSettings() {
|
||||
adjustFrameDisplay(this.settingsFrame);
|
||||
this.mainMenu.setVisible(false);
|
||||
this.settingsFrame.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
private void adjustFrameDisplay(JFrame frame) {
|
||||
boolean wasVisible = frame.isVisible(); // Vérifier si la fenêtre était déjà visible
|
||||
|
||||
if(!wasVisible){
|
||||
// Récupérer la taille et la position de la fenêtre du menu principal
|
||||
Dimension mainMenuSize = this.mainMenu.getSize();
|
||||
Point mainMenuLocation = this.mainMenu.getLocation();
|
||||
frame.setSize(mainMenuSize);
|
||||
frame.setLocation(mainMenuLocation);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.ButtonPanel;
|
||||
import fr.monkhanny.dorfromantik.gui.ButtonHoverAnimator;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class MainMenuMouseController {
|
||||
|
||||
private final ButtonPanel buttonPanel;
|
||||
|
||||
public MainMenuMouseController(ButtonPanel buttonPanel) {
|
||||
this.buttonPanel = buttonPanel;
|
||||
initMouseListeners();
|
||||
}
|
||||
|
||||
private void initMouseListeners() {
|
||||
addButtonHoverListener(buttonPanel.getNewGameButton());
|
||||
addButtonHoverListener(buttonPanel.getContinueGameButton());
|
||||
addButtonHoverListener(buttonPanel.getHowToPlayButton());
|
||||
addButtonHoverListener(buttonPanel.getSettingsButton());
|
||||
addButtonHoverListener(buttonPanel.getExitButton());
|
||||
}
|
||||
|
||||
private void addButtonHoverListener(JButton button) {
|
||||
ButtonHoverAnimator animator = new ButtonHoverAnimator(button);
|
||||
button.addMouseListener(new ButtonHoverListener(animator));
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
|
||||
public class MainMenuResizeController {
|
||||
|
||||
private MainMenu mainMenu;
|
||||
private MainMenuResizeHandler resizeHandler;
|
||||
|
||||
public MainMenuResizeController(MainMenu mainMenu) {
|
||||
this.mainMenu = mainMenu;
|
||||
this.resizeHandler = new MainMenuResizeHandler(mainMenu);
|
||||
addComponentListener();
|
||||
}
|
||||
|
||||
private void addComponentListener() {
|
||||
mainMenu.addComponentListener(resizeHandler);
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
import fr.monkhanny.dorfromantik.gui.ButtonHoverAnimator;
|
||||
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
|
||||
public class MainMenuResizeHandler extends ComponentAdapter {
|
||||
|
||||
private MainMenu mainMenu;
|
||||
|
||||
public MainMenuResizeHandler(MainMenu mainMenu) {
|
||||
this.mainMenu = mainMenu;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
int mainMenuWidth = mainMenu.getWidth();
|
||||
|
||||
// Ajuster la taille de la police du titre en fonction de la taille de la fenêtre
|
||||
float newFontSize = Options.BASE_TITLE_FONT_SIZE * (mainMenuWidth / 900f);
|
||||
mainMenu.getTitleLabel().updateTitleFont(newFontSize);
|
||||
|
||||
// Mettre à jour les polices des boutons
|
||||
mainMenu.getButtonPanel().updateButtonFonts(mainMenuWidth);
|
||||
ButtonHoverAnimator.updateOriginalFont(mainMenuWidth / 30f); // On passe la nouvelle taille de police pour chaque bouton
|
||||
}
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.RewardsPanel;
|
||||
import fr.monkhanny.dorfromantik.gui.Reward;
|
||||
import fr.monkhanny.dorfromantik.utils.Database;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class RewardsPanelController {
|
||||
|
||||
private RewardsPanel rewardsPanel;
|
||||
|
||||
public RewardsPanelController(RewardsPanel rewardsPanel) {
|
||||
this.rewardsPanel = rewardsPanel;
|
||||
}
|
||||
|
||||
public ActionListener getFetchRewardsAction() {
|
||||
return new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String username = rewardsPanel.getUsername();
|
||||
if (!username.isEmpty()) {
|
||||
try {
|
||||
// Récupérer les récompenses pour l'utilisateur
|
||||
Database db = new Database();
|
||||
List<Reward> rewards = db.getRewardsByUsername(username);
|
||||
db.close();
|
||||
|
||||
// Mettre à jour le panneau
|
||||
rewardsPanel.updateRewardsPanel(rewards);
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(rewardsPanel, "Error fetching rewards: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public ActionListener getBackButtonAction() {
|
||||
return new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
rewardsPanel.getMainMenuFrame().setVisible(true);
|
||||
rewardsPanel.getRewardsFrame().setVisible(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.TutorialPanel;
|
||||
import fr.monkhanny.dorfromantik.gui.Step;
|
||||
import fr.monkhanny.dorfromantik.enums.Images;
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TutorialController {
|
||||
private TutorialPanel tutorialPanel;
|
||||
|
||||
private MainMenu mainMenu;
|
||||
private JFrame tutorialFrame;
|
||||
|
||||
public TutorialController(MainMenu mainMenu, JFrame tutorialFrame) {
|
||||
this.mainMenu = mainMenu;
|
||||
this.tutorialFrame = tutorialFrame;
|
||||
|
||||
List<Step> steps = new ArrayList<>();
|
||||
steps.add(new Step("Étape n°1", "Explication de la première étape ici.", Images.TUTORIAL_GIF1.getImagePath()));
|
||||
steps.add(new Step("Étape n°2", "Explication de la deuxième étape ici.", Images.TUTORIAL_GIF2.getImagePath()));
|
||||
steps.add(new Step("Étape n°3", "Explication de la troisième étape ici.", Images.TUTORIAL_GIF3.getImagePath()));
|
||||
steps.add(new Step("Étape n°4", "Explication de la quatrième étape ici.", Images.TUTORIAL_GIF4.getImagePath()));
|
||||
|
||||
tutorialPanel = new TutorialPanel(steps, this.mainMenu, this.tutorialFrame);
|
||||
}
|
||||
|
||||
public JPanel getTutorialPanel() {
|
||||
return tutorialPanel;
|
||||
}
|
||||
}
|
24
src/fr/monkhanny/dorfromantik/enums/Biome.java
Normal file
24
src/fr/monkhanny/dorfromantik/enums/Biome.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package fr.monkhanny.dorfromantik.enums;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
public enum Biome {
|
||||
SEA, FIELD, PRE, FOREST, MOUNTAIN;
|
||||
|
||||
public Color[] getBiomeColors() {
|
||||
switch (this) {
|
||||
case SEA:
|
||||
return new Color[] { new Color(25, 133, 208), new Color(53, 159, 235), new Color(0, 103, 178) };
|
||||
case FIELD:
|
||||
return new Color[] { new Color(232, 214, 28), new Color(247, 228, 28), new Color(210, 195, 0) };
|
||||
case PRE:
|
||||
return new Color[] { new Color(110, 190, 110), new Color(130, 210, 130), new Color(90, 170, 90) };
|
||||
case FOREST:
|
||||
return new Color[] { new Color(15, 110, 65), new Color(35, 130, 85), new Color(0, 90, 45) };
|
||||
case MOUNTAIN:
|
||||
return new Color[] { new Color(110, 110, 110), new Color(130, 130, 130), new Color(90, 90, 90) };
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown Biome : " + this);
|
||||
}
|
||||
}
|
||||
}
|
42
src/fr/monkhanny/dorfromantik/enums/Fonts.java
Normal file
42
src/fr/monkhanny/dorfromantik/enums/Fonts.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package fr.monkhanny.dorfromantik.enums;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontFormatException;
|
||||
|
||||
public enum Fonts {
|
||||
TITLE, BUTTON, SCORE;
|
||||
|
||||
public String getFontPath() {
|
||||
switch (this) {
|
||||
case TITLE:
|
||||
return "./ressources/fonts/Contage-Black.ttf";
|
||||
case BUTTON:
|
||||
return "./ressources/fonts/Contage-Regular.ttf";
|
||||
case SCORE:
|
||||
return "./ressources/fonts/Contage-Bold.ttf";
|
||||
default:
|
||||
throw new IllegalArgumentException("Unexpected value: " + this);
|
||||
}
|
||||
}
|
||||
|
||||
public Font getFont(float size) {
|
||||
try {
|
||||
switch (this) {
|
||||
case TITLE:
|
||||
return Font.createFont(Font.TRUETYPE_FONT, new File("./ressources/fonts/Contage-Black.ttf")).deriveFont(size);
|
||||
case BUTTON:
|
||||
return Font.createFont(Font.TRUETYPE_FONT, new File("./ressources/fonts/Contage-Regular.ttf")).deriveFont(size);
|
||||
case SCORE:
|
||||
return Font.createFont(Font.TRUETYPE_FONT, new File("./ressources/fonts/Contage-Bold.ttf")).deriveFont(size);
|
||||
default:
|
||||
throw new IllegalArgumentException("Unexpected value: " + this);
|
||||
}
|
||||
} catch (IOException | FontFormatException e) {
|
||||
e.printStackTrace();
|
||||
// Retourner une police de secours si le fichier est introuvable ou s'il y a une erreur
|
||||
return new Font("Arial", Font.PLAIN, (int) size);
|
||||
}
|
||||
}
|
||||
}
|
25
src/fr/monkhanny/dorfromantik/enums/Images.java
Normal file
25
src/fr/monkhanny/dorfromantik/enums/Images.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package fr.monkhanny.dorfromantik.enums;
|
||||
|
||||
|
||||
public enum Images {
|
||||
SETTINGS_ICON, EXIT_ICON, TUTORIAL_GIF1, TUTORIAL_GIF2, TUTORIAL_GIF3, TUTORIAL_GIF4;
|
||||
|
||||
public String getImagePath() {
|
||||
switch (this) {
|
||||
case SETTINGS_ICON:
|
||||
return "./ressources/images/Icone/SettingsIcon.png";
|
||||
case EXIT_ICON:
|
||||
return "./ressources/images/Icone/ExitIcon.png";
|
||||
case TUTORIAL_GIF1:
|
||||
return "./ressources/images/Tutorial/Gif1.gif";
|
||||
case TUTORIAL_GIF2:
|
||||
return "./ressources/images/Tutorial/Gif2.gif";
|
||||
case TUTORIAL_GIF3:
|
||||
return "./ressources/images/Tutorial/Gif3.gif";
|
||||
case TUTORIAL_GIF4:
|
||||
return "./ressources/images/Tutorial/Gif4.gif";
|
||||
default:
|
||||
throw new IllegalArgumentException("Unexpected value: " + this);
|
||||
}
|
||||
}
|
||||
}
|
14
src/fr/monkhanny/dorfromantik/enums/Musics.java
Normal file
14
src/fr/monkhanny/dorfromantik/enums/Musics.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package fr.monkhanny.dorfromantik.enums;
|
||||
|
||||
public enum Musics {
|
||||
MAIN_MENU_MUSIC;
|
||||
|
||||
public String getSoundsPath() {
|
||||
switch (this) {
|
||||
case MAIN_MENU_MUSIC:
|
||||
return "./ressources/sounds/Music/mainMenuMusic.wav";
|
||||
default:
|
||||
throw new IllegalArgumentException("Unexpected value: " + this);
|
||||
}
|
||||
}
|
||||
}
|
16
src/fr/monkhanny/dorfromantik/enums/Sounds.java
Normal file
16
src/fr/monkhanny/dorfromantik/enums/Sounds.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package fr.monkhanny.dorfromantik.enums;
|
||||
|
||||
public enum Sounds {
|
||||
SOUNDS1, SOUNDS2;
|
||||
|
||||
public String getSoundsPath() {
|
||||
switch (this) {
|
||||
case SOUNDS1:
|
||||
return "./ressources/sounds/SFX/1.wav";
|
||||
case SOUNDS2:
|
||||
return "./ressources/sounds/SFX/2.wav";
|
||||
default:
|
||||
throw new IllegalArgumentException("Unexpected value: " + this);
|
||||
}
|
||||
}
|
||||
}
|
26
src/fr/monkhanny/dorfromantik/enums/TileOrientation.java
Normal file
26
src/fr/monkhanny/dorfromantik/enums/TileOrientation.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package fr.monkhanny.dorfromantik.enums;
|
||||
|
||||
|
||||
public enum TileOrientation {
|
||||
NORTH, NORTH_EAST, SOUTH_EAST, SOUTH, SOUTH_WEST, NORTH_WEST;
|
||||
|
||||
|
||||
public TileOrientation oppositeOrientation() {
|
||||
switch (this) {
|
||||
case NORTH:
|
||||
return SOUTH;
|
||||
case NORTH_EAST:
|
||||
return SOUTH_WEST;
|
||||
case SOUTH_EAST:
|
||||
return NORTH_WEST;
|
||||
case SOUTH:
|
||||
return NORTH;
|
||||
case SOUTH_WEST:
|
||||
return NORTH_EAST;
|
||||
case NORTH_WEST:
|
||||
return SOUTH_EAST;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown TileOrientation: " + this);
|
||||
}
|
||||
}
|
||||
}
|
29
src/fr/monkhanny/dorfromantik/game/BiomeGroup.java
Normal file
29
src/fr/monkhanny/dorfromantik/game/BiomeGroup.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package fr.monkhanny.dorfromantik.game;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BiomeGroup {
|
||||
private List<Pocket> pockets;
|
||||
|
||||
public BiomeGroup() {
|
||||
pockets = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addPocket(Pocket pocket) {
|
||||
pockets.add(pocket);
|
||||
}
|
||||
|
||||
public List<Pocket> getPockets() {
|
||||
return pockets;
|
||||
}
|
||||
|
||||
public int calculateTotalScore() {
|
||||
int totalScore = 0;
|
||||
for (Pocket pocket : pockets) {
|
||||
totalScore += pocket.calculateScore();
|
||||
}
|
||||
return totalScore;
|
||||
}
|
||||
}
|
||||
|
462
src/fr/monkhanny/dorfromantik/game/Board.java
Normal file
462
src/fr/monkhanny/dorfromantik/game/Board.java
Normal file
@@ -0,0 +1,462 @@
|
||||
package fr.monkhanny.dorfromantik.game;
|
||||
|
||||
import fr.monkhanny.dorfromantik.listeners.GameZoomListener;
|
||||
import fr.monkhanny.dorfromantik.listeners.GameArrowKeyListener;
|
||||
import fr.monkhanny.dorfromantik.listeners.GameSpaceKeyListener;
|
||||
import fr.monkhanny.dorfromantik.listeners.GameMouseClickListener;
|
||||
import fr.monkhanny.dorfromantik.listeners.GameMouseWheelListener;
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
import fr.monkhanny.dorfromantik.enums.Biome;
|
||||
import fr.monkhanny.dorfromantik.enums.Fonts;
|
||||
import fr.monkhanny.dorfromantik.enums.TileOrientation;
|
||||
import fr.monkhanny.dorfromantik.controller.GameModeController;
|
||||
import fr.monkhanny.dorfromantik.utils.Database;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.awt.Graphics;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JFrame;
|
||||
import java.awt.Point;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Font;
|
||||
|
||||
// TEMPORAIRE :
|
||||
import java.awt.event.MouseMotionAdapter; // Import pour MouseMotionAdapter
|
||||
import java.awt.AlphaComposite;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* Représente le plateau de jeu.
|
||||
*/
|
||||
public class Board extends JPanel{
|
||||
private List<Tile> tiles;
|
||||
private List<Point> availablePositions;
|
||||
private Random random;
|
||||
private Game game;
|
||||
private JFrame gameFrame;
|
||||
private Tile centralTile;
|
||||
private double zoomFactor = 1.0; // Facteur de zoom initial
|
||||
private int offsetX = 0; // Décalage horizontal du plateau
|
||||
private int offsetY = 0; // Décalage vertical du plateau
|
||||
private Tile nextTile;
|
||||
private Map<Biome, BiomeGroup> biomeGroups;
|
||||
private Point mousePosition;
|
||||
private ScoreManager scoreManager;
|
||||
private int currentScore;
|
||||
private Database database;
|
||||
|
||||
// Constructeur avec seed
|
||||
public Board(JFrame gameFrame, long seed) {
|
||||
this.gameFrame = gameFrame;
|
||||
this.tiles = new ArrayList<>();
|
||||
this.biomeGroups = new HashMap<>();
|
||||
this.availablePositions = new ArrayList<>();
|
||||
this.random = new Random(seed);
|
||||
this.game = new Game(seed);
|
||||
|
||||
this.scoreManager = new ScoreManager(biomeGroups);
|
||||
|
||||
for (Biome biome : Biome.values()) {
|
||||
biomeGroups.put(biome, new BiomeGroup());
|
||||
}
|
||||
|
||||
// Placer une tuile centrale au démarrage
|
||||
initializeCentralTile();
|
||||
|
||||
// Ajouter un écouteur de molette de souris pour gérer le zoom
|
||||
gameFrame.addMouseWheelListener(new GameZoomListener(this));
|
||||
|
||||
// Ajouter un écouteur de clavier pour déplacer le plateau
|
||||
gameFrame.addKeyListener(new GameArrowKeyListener(this));
|
||||
gameFrame.setFocusable(true);
|
||||
|
||||
this.addMouseWheelListener(new GameMouseWheelListener(this));
|
||||
|
||||
|
||||
gameFrame.addKeyListener(new GameSpaceKeyListener(this));
|
||||
|
||||
this.addMouseListener(new GameMouseClickListener(this));
|
||||
|
||||
this.addMouseMotionListener(new MouseMotionAdapter() {
|
||||
@Override
|
||||
public void mouseMoved(java.awt.event.MouseEvent e) {
|
||||
handleMouseMove(e);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void handleMouseMove(java.awt.event.MouseEvent e) {
|
||||
// Récupérer les coordonnées du curseur
|
||||
Point cursorPoint = e.getPoint();
|
||||
|
||||
// Ajuster la position de la souris en fonction du zoom et des offsets
|
||||
int adjustedX = (int)((cursorPoint.x - offsetX) / zoomFactor);
|
||||
int adjustedY = (int)((cursorPoint.y - offsetY) / zoomFactor);
|
||||
|
||||
// Vérifier si la souris est proche d'une des positions disponibles
|
||||
for (Point position : availablePositions) {
|
||||
if (new Point(adjustedX, adjustedY).distance(position) < 20) {
|
||||
mousePosition = position;
|
||||
repaint(); // Redessiner le plateau avec la tuile transparente
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Si la souris n'est pas proche d'une position valide, ne rien faire
|
||||
mousePosition = null;
|
||||
repaint(); // Redessiner sans la tuile transparente
|
||||
}
|
||||
|
||||
|
||||
private void initializeNextTile() {
|
||||
int offsetX = 50; // Décalage pour la position en haut à gauche
|
||||
int offsetY = 50; // Décalage pour la position en haut à gauche
|
||||
this.nextTile = new Tile(this, offsetX, offsetY, 50); // Création de la nouvelle tuile
|
||||
|
||||
}
|
||||
|
||||
public Tile getNextTile() { return nextTile; }
|
||||
|
||||
public void handleSpaceKeyPress() {
|
||||
// Calculer les dimensions totales du plateau (largeur et hauteur des tuiles)
|
||||
int totalWidth = 0;
|
||||
int totalHeight = 0;
|
||||
|
||||
// Calculer la largeur et la hauteur totale de toutes les tuiles
|
||||
for (Tile tile : tiles) {
|
||||
totalWidth = Math.max(totalWidth, tile.getXCoord() + tile.getRadius());
|
||||
totalHeight = Math.max(totalHeight, tile.getYCoord() + tile.getRadius());
|
||||
}
|
||||
|
||||
// Ajouter une petite marge pour les bords
|
||||
totalWidth += 50; // Marge pour éviter que les tuiles ne soient collées au bord
|
||||
totalHeight += 50; // Marge pour éviter que les tuiles ne soient collées au bord
|
||||
|
||||
// Calculer le facteur de zoom pour que toutes les tuiles tiennent sur l'écran
|
||||
double horizontalZoom = (double) getWidth() / totalWidth;
|
||||
double verticalZoom = (double) getHeight() / totalHeight;
|
||||
|
||||
// Choisir le zoom le plus petit pour éviter que les tuiles ne sortent de l'écran
|
||||
zoomFactor = Math.min(horizontalZoom, verticalZoom);
|
||||
|
||||
// Ajuster les offsets pour centrer les tuiles après le dézoom
|
||||
adjustOffsets(totalWidth, totalHeight);
|
||||
|
||||
// Recalculer les positions disponibles et redessiner le plateau
|
||||
repaint();
|
||||
}
|
||||
|
||||
private void adjustOffsets(int totalWidth, int totalHeight) {
|
||||
// Calculer les décalages nécessaires pour centrer le plateau
|
||||
int targetOffsetX = (int) ((getWidth() - totalWidth * zoomFactor) / 2);
|
||||
int targetOffsetY = (int) ((getHeight() - totalHeight * zoomFactor) / 2);
|
||||
|
||||
// Appliquer les nouveaux offsets
|
||||
setOffsetX(targetOffsetX);
|
||||
setOffsetY(targetOffsetY);
|
||||
}
|
||||
|
||||
|
||||
public void handleMouseClick(java.awt.event.MouseEvent e) {
|
||||
// Récupérer les coordonnées du clic
|
||||
Point clickedPoint = e.getPoint();
|
||||
|
||||
// Ajuster les coordonnées du clic en tenant compte du zoom et des déplacements
|
||||
// Annuler l'effet du zoom et du déplacement
|
||||
int adjustedX = (int)((clickedPoint.x - offsetX) / zoomFactor);
|
||||
int adjustedY = (int)((clickedPoint.y - offsetY) / zoomFactor);
|
||||
|
||||
// Vérifiez si la position ajustée est dans la liste des positions disponibles et si la distance est suffisante
|
||||
for (Point position : availablePositions) {
|
||||
// Vérifiez la distance entre le clic ajusté et la position
|
||||
if (new Point(adjustedX, adjustedY).distance(position) < 20) {
|
||||
placeTileAtPosition(position); // Place une tuile à cette position
|
||||
break; // Si une tuile est ajoutée, on peut sortir de la boucle
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void initializeCentralTile() {
|
||||
int centerX = gameFrame.getWidth() / 2;
|
||||
int centerY = gameFrame.getHeight() / 2;
|
||||
|
||||
this.centralTile = new Tile(this, centerX, centerY, 50);
|
||||
addTile(centralTile);
|
||||
|
||||
// Calculer les positions disponibles autour de la tuile centrale
|
||||
calculateAvailablePositions(centralTile);
|
||||
initializeNextTile();
|
||||
}
|
||||
|
||||
public void addTile(Tile tile) {
|
||||
tiles.add(tile);
|
||||
updatePockets(tile);
|
||||
calculateCurrentScore();
|
||||
}
|
||||
|
||||
private void updatePockets(Tile newTile) {
|
||||
for (TileOrientation orientation : TileOrientation.values()) {
|
||||
Biome biome = newTile.getBiome(orientation);
|
||||
BiomeGroup biomeGroup = biomeGroups.get(biome);
|
||||
|
||||
// Vérifier si la nouvelle tuile peut être connectée à une poche existante
|
||||
Pocket connectedPocket = null;
|
||||
for (Pocket pocket : biomeGroup.getPockets()) {
|
||||
if (isConnectedToPocket(newTile, pocket)) {
|
||||
connectedPocket = pocket;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (connectedPocket != null) {
|
||||
// Connecte la tuile à une poche existante
|
||||
connectedPocket.addTile(newTile);
|
||||
} else {
|
||||
// Crée une nouvelle poche pour ce biome
|
||||
Pocket newPocket = new Pocket(biome);
|
||||
newPocket.addTile(newTile);
|
||||
biomeGroup.addPocket(newPocket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Méthode pour vérifier si une tuile est connectée à une poche existante
|
||||
private boolean isConnectedToPocket(Tile tile, Pocket pocket) {
|
||||
for (Tile connectedTile : pocket.getTiles()) {
|
||||
if (areTilesConnected(tile, connectedTile)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Vérifie si deux tuiles sont connectées par un même biome
|
||||
private boolean areTilesConnected(Tile tile1, Tile tile2) {
|
||||
for (TileOrientation orientation : TileOrientation.values()) {
|
||||
if (tile1.getBiome(orientation).equals(tile2.getBiome(orientation.oppositeOrientation()))) {
|
||||
// Vérifier si les tuiles sont adjacentes (logique à adapter selon vos besoins)
|
||||
// Exemple : si elles partagent un côté commun
|
||||
return tile1.isAdjacentTo(tile2);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void calculateCurrentScore() {
|
||||
scoreManager.updateScore(); // Met à jour le score
|
||||
currentScore = scoreManager.getCurrentScore(); // Récupère le score actuel
|
||||
}
|
||||
|
||||
public int getCurrentScore() {
|
||||
return currentScore;
|
||||
}
|
||||
|
||||
public Random getRandom() { return random; }
|
||||
|
||||
public Game getGame() { return game; }
|
||||
|
||||
/**
|
||||
* Calcule les positions disponibles autour de la tuile donnée.
|
||||
* Les points rouges seront générés autour de cette tuile.
|
||||
*
|
||||
* @param tile La tuile pour laquelle on calcule les positions disponibles
|
||||
*/
|
||||
private void calculateAvailablePositions(Tile tile) {
|
||||
int tileX = tile.getXCoord();
|
||||
int tileY = tile.getYCoord();
|
||||
int radius = (int) (tile.getRadius() * 1.72); // Utiliser un rayon uniforme pour toutes les directions
|
||||
|
||||
// Définir les directions possibles autour de la tuile (6 directions pour une tuile hexagonale)
|
||||
Point[] directions = {
|
||||
new Point(0, -radius), // Nord
|
||||
new Point((int)(radius * Math.sqrt(3) / 2), -radius / 2), // Nord-Est (ajuster horizontalement)
|
||||
new Point((int)(radius * Math.sqrt(3) / 2), radius / 2), // Sud-Est (ajuster horizontalement)
|
||||
new Point(0, radius), // Sud
|
||||
new Point(-(int)(radius * Math.sqrt(3) / 2), radius / 2), // Sud-Ouest (ajuster horizontalement)
|
||||
new Point(-(int)(radius * Math.sqrt(3) / 2), -radius / 2) // Nord-Ouest (ajuster horizontalement)
|
||||
};
|
||||
|
||||
// Calculer les positions disponibles autour de la tuile
|
||||
for (Point direction : directions) {
|
||||
Point newPoint = new Point(tileX + direction.x, tileY + direction.y);
|
||||
if (!isTileAtPosition(newPoint)) {
|
||||
availablePositions.add(newPoint); // Ajouter la position si une tuile n'est pas déjà là
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Vérifie si une tuile existe déjà à la position donnée.
|
||||
*
|
||||
* @param position La position à vérifier
|
||||
* @return true si une tuile est présente à cette position, false sinon
|
||||
*/
|
||||
private boolean isTileAtPosition(Point position) {
|
||||
for (Tile t : tiles) {
|
||||
if (t.getXCoord() == position.x && t.getYCoord() == position.y) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lorsqu'un utilisateur clique, ajoute une nouvelle tuile à la position sélectionnée.
|
||||
*
|
||||
* @param position La position où ajouter la tuile
|
||||
*/
|
||||
public void placeTileAtPosition(Point position) {
|
||||
// Vérifie si la position est disponible et que la tuile n'est pas déjà placée à cet endroit
|
||||
if (availablePositions.contains(position) && !isTileAtPosition(position)) {
|
||||
if (tiles.size() < Options.MAX_TILE_NUMBER) {
|
||||
// Vérifiez si la nextTile existe, sinon on ignore
|
||||
if (nextTile != null) {
|
||||
// Place la nextTile à la position choisie
|
||||
nextTile.setPosition(position.x, position.y);
|
||||
addTile(nextTile); // Ajoute la nextTile au tableau des tuiles
|
||||
calculateAvailablePositions(nextTile); // Calcule de nouvelles positions disponibles
|
||||
repaint(); // Redessine le plateau
|
||||
autoReFocus(nextTile);
|
||||
|
||||
// Initialiser une nouvelle nextTile pour le prochain tour
|
||||
initializeNextTile();
|
||||
}
|
||||
|
||||
} else {
|
||||
try {
|
||||
this.database = new Database();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Erreur lors de la connexion à la base de données: " + e.getMessage());
|
||||
}
|
||||
GameOver gameOverPanel = new GameOver(gameFrame, currentScore, database,Options.mainMenu);
|
||||
gameFrame.getContentPane().removeAll(); // Supprime l'ancien contenu
|
||||
gameFrame.getContentPane().add(gameOverPanel); // Ajoute le GameOver
|
||||
gameFrame.revalidate(); // Revalidate pour mettre à jour la fenêtre
|
||||
gameFrame.repaint(); // Repaint pour afficher les modifications
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void autoReFocus(Tile newlyPlacedTile) {
|
||||
if (Options.AUTO_FOCUS) {
|
||||
// Récupérer les coordonnées de la nouvelle tuile
|
||||
int newlyPlacedTileX = newlyPlacedTile.getXCoord();
|
||||
int newlyPlacedTileY = newlyPlacedTile.getYCoord();
|
||||
|
||||
// Calculer les décalages nécessaires pour centrer la tuile
|
||||
// Nous utilisons la largeur et la hauteur du panneau de jeu (getWidth et getHeight)
|
||||
// Divisé par 2 pour centrer la nouvelle tuile dans la fenêtre.
|
||||
int targetOffsetX = (int) ((getWidth() - newlyPlacedTile.getRadius() * 2) / 2 - newlyPlacedTileX);
|
||||
int targetOffsetY = (int) ((getHeight() - newlyPlacedTile.getRadius() * 2) / 2 - newlyPlacedTileY);
|
||||
|
||||
TilePanningTransition panningTransition = new TilePanningTransition(this, targetOffsetX, targetOffsetY, 15);
|
||||
panningTransition.start();
|
||||
}
|
||||
}
|
||||
|
||||
public double getZoomFactor() { return zoomFactor;}
|
||||
|
||||
public void setZoomFactor(double zoomFactor) { this.zoomFactor = zoomFactor; }
|
||||
|
||||
public int getOffsetX() { return offsetX; }
|
||||
|
||||
public void setOffsetX(int offsetX) { this.offsetX = offsetX; }
|
||||
|
||||
public int getOffsetY() { return offsetY; }
|
||||
|
||||
public void setOffsetY(int offsetY) { this.offsetY = offsetY; }
|
||||
|
||||
public void zoomIn() {
|
||||
zoomFactor *= 1.1; // Augmenter le facteur de zoom
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void zoomOut() {
|
||||
zoomFactor /= 1.1; // Diminuer le facteur de zoom
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void moveBoard(int dx, int dy) {
|
||||
offsetX += dx;
|
||||
offsetY += dy;
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Afficher les points rouges pour indiquer les positions disponibles.
|
||||
*
|
||||
* @param g Le contexte graphique
|
||||
*/
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
|
||||
// Appliquer l'échelle de zoom et le déplacement
|
||||
g2d.scale(zoomFactor, zoomFactor); // Appliquer le zoom
|
||||
g2d.translate(offsetX / zoomFactor, offsetY / zoomFactor); // Appliquer le déplacement (en tenant compte du zoom)
|
||||
|
||||
// Dessiner les points rouges pour les positions disponibles
|
||||
for (Point position : availablePositions) {
|
||||
g.setColor(Color.RED);
|
||||
g.fillOval(position.x - 5, position.y - 5, 10, 10); // Dessiner un point rouge
|
||||
}
|
||||
|
||||
// Dessiner les tuiles existantes
|
||||
for (Tile tile : tiles) {
|
||||
int tileX = tile.getXCoord();
|
||||
int tileY = tile.getYCoord();
|
||||
|
||||
tile.drawTileAt(g,tileX-50,tileY-50,1f);
|
||||
}
|
||||
|
||||
// Vérifier si la position de la souris est valide et ne pas dessiner si elle est occupée
|
||||
if (mousePosition != null && nextTile != null && !isTileAtPosition(mousePosition)) {
|
||||
int nextTileX = mousePosition.x;
|
||||
int nextTileY = mousePosition.y;
|
||||
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); // Rendre la tuile transparente
|
||||
nextTile.drawTileAt(g, nextTileX - 50, nextTileY - 50, 1f);
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f)); // Rétablir l'opacité
|
||||
}
|
||||
|
||||
// Obtenez la police SCORE avec une taille ajustée (par exemple, 30 points)
|
||||
Font scoreFont = Fonts.SCORE.getFont(30f); // Vous pouvez ajuster la taille ici
|
||||
g.setFont(scoreFont);
|
||||
|
||||
// Calculer la position du score (avec zoom et décalage)
|
||||
g.setColor(Color.BLACK);
|
||||
int scoreX = (int) ((getWidth() / (2 * zoomFactor) - offsetX / zoomFactor) - 20);
|
||||
int scoreY = (int) (40 / zoomFactor - offsetY / zoomFactor);
|
||||
|
||||
// Dessiner le texte du score
|
||||
g.drawString("Score : " + currentScore, scoreX, scoreY);
|
||||
|
||||
if (nextTile != null) {
|
||||
// Calculer la position correcte de la nextTile (en tenant compte du zoom et des décalages)
|
||||
int nextTileX = 0; // Position x dans l'espace global
|
||||
int nextTileY = 0; // Position y dans l'espace global
|
||||
|
||||
// Appliquer la transformation inverse (ne pas zoomer ni déplacer la nextTile)
|
||||
g2d.scale(1 / zoomFactor, 1 / zoomFactor); // Inverser le zoom
|
||||
g2d.translate(-offsetX, -offsetY); // Inverser le décalage (revenir à l'espace global)
|
||||
|
||||
// Dessiner la nextTile à sa position d'origine (0,0)
|
||||
nextTile.drawTileAt(g, nextTileX, nextTileY, 1f);
|
||||
|
||||
// Rétablir les transformations pour les autres éléments (tuiles existantes, etc.)
|
||||
g2d.translate(offsetX / zoomFactor, offsetY / zoomFactor); // Re-appliquer le décalage
|
||||
g2d.scale(zoomFactor, zoomFactor); // Re-appliquer le zoom
|
||||
|
||||
}
|
||||
}
|
||||
}
|
110
src/fr/monkhanny/dorfromantik/game/Cell.java
Normal file
110
src/fr/monkhanny/dorfromantik/game/Cell.java
Normal file
@@ -0,0 +1,110 @@
|
||||
package fr.monkhanny.dorfromantik.game;
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* Représente une cellule de base sur le plateau de jeu.
|
||||
* C'est la classe parente pour la classe Tile.
|
||||
*/
|
||||
public class Cell extends JComponent {
|
||||
private Board board; // Le plateau de jeu auquel cette cellule appartient
|
||||
public int x; // Coordonnée x du centre de la cellule
|
||||
public int y; // Coordonnée y du centre de la cellule
|
||||
public int radius; // Rayon de la cellule (si on parle d'un hexagone, c'est le rayon de l'hexagone)
|
||||
|
||||
/**
|
||||
* Constructeur de la classe Cell.
|
||||
*
|
||||
* @param board Le plateau de jeu auquel cette cellule appartient
|
||||
* @param x La coordonnée x du centre de la cellule
|
||||
* @param y La coordonnée y du centre de la cellule
|
||||
* @param radius Le rayon de la cellule
|
||||
*/
|
||||
public Cell(Board board, int x, int y, int radius) {
|
||||
this.board = board;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.radius = radius;
|
||||
|
||||
// Définir la taille du composant pour l'affichage
|
||||
this.setSize(2 * radius, 2 * radius);
|
||||
this.setLocation(x - radius, y - radius);
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le plateau de jeu auquel cette cellule appartient.
|
||||
*
|
||||
* @return Le plateau de jeu
|
||||
*/
|
||||
public Board getBoard() {
|
||||
return board;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère la coordonnée x du centre de la cellule.
|
||||
*
|
||||
* @return La coordonnée x
|
||||
*/
|
||||
public int getXCoord() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère la coordonnée y du centre de la cellule.
|
||||
*
|
||||
* @return La coordonnée y
|
||||
*/
|
||||
public int getYCoord() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le rayon de la cellule.
|
||||
*
|
||||
* @return Le rayon de la cellule
|
||||
*/
|
||||
public int getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convertit une coordonnée en degrés en une valeur de 0 à 360.
|
||||
*
|
||||
* @param angle L'angle en degrés
|
||||
* @return La valeur normalisée entre 0 et 360 degrés
|
||||
*/
|
||||
public static double to360Degrees(double angle) {
|
||||
angle = angle % 360;
|
||||
if (angle < 0) {
|
||||
angle += 360;
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de changer la position de la cellule.
|
||||
* Cette méthode met à jour les coordonnées x et y et déplace la cellule dans le composant graphique.
|
||||
*
|
||||
* @param x La nouvelle coordonnée x du centre de la cellule
|
||||
* @param y La nouvelle coordonnée y du centre de la cellule
|
||||
*/
|
||||
public void setPosition(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
// Mettre à jour la position de la cellule sur le plateau
|
||||
this.setLocation(x - radius, y - radius);
|
||||
}
|
||||
|
||||
/**
|
||||
* Méthode pour redessiner la cellule si nécessaire.
|
||||
* Elle sera surchargée par les classes dérivées comme Tile.
|
||||
*
|
||||
* @param g Le contexte graphique
|
||||
*/
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
}
|
||||
}
|
27
src/fr/monkhanny/dorfromantik/game/Game.java
Normal file
27
src/fr/monkhanny/dorfromantik/game/Game.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package fr.monkhanny.dorfromantik.game;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Représente un objet de jeu qui gère les fonctionnalités générales.
|
||||
*/
|
||||
public class Game {
|
||||
private Random random;
|
||||
|
||||
// Nouveau constructeur qui accepte un seed
|
||||
public Game(long seed) {
|
||||
this.random = new Random(seed);
|
||||
}
|
||||
|
||||
// Constructeur par défaut pour conserver la flexibilité
|
||||
public Game() {
|
||||
this.random = new Random();
|
||||
}
|
||||
|
||||
public int getRandomInt(int max) {
|
||||
return random.nextInt(max);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
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;
|
||||
}
|
||||
|
||||
}
|
43
src/fr/monkhanny/dorfromantik/game/Pocket.java
Normal file
43
src/fr/monkhanny/dorfromantik/game/Pocket.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package fr.monkhanny.dorfromantik.game;
|
||||
|
||||
import fr.monkhanny.dorfromantik.enums.Biome;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class Pocket {
|
||||
private Biome biome;
|
||||
private Set<Tile> tiles; // Ensemble des tuiles de la poche
|
||||
|
||||
public Pocket(Biome biome) {
|
||||
this.biome = biome;
|
||||
this.tiles = new HashSet<>();
|
||||
}
|
||||
|
||||
public void addTile(Tile tile) {
|
||||
tiles.add(tile);
|
||||
}
|
||||
|
||||
public boolean containsTile(Tile tile) {
|
||||
return tiles.contains(tile);
|
||||
}
|
||||
|
||||
public Biome getBiome() {
|
||||
return biome;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return tiles.size();
|
||||
}
|
||||
|
||||
public int calculateScore() {
|
||||
// Calcul du score basé sur la taille de la poche
|
||||
return getSize() * getSize();
|
||||
}
|
||||
|
||||
public List<Tile> getTiles() {
|
||||
return new ArrayList<>(tiles);
|
||||
}
|
||||
}
|
44
src/fr/monkhanny/dorfromantik/game/ScoreManager.java
Normal file
44
src/fr/monkhanny/dorfromantik/game/ScoreManager.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package fr.monkhanny.dorfromantik.game;
|
||||
|
||||
import java.util.Map;
|
||||
import fr.monkhanny.dorfromantik.enums.Biome;
|
||||
|
||||
/**
|
||||
* Classe responsable du calcul et de la gestion du score.
|
||||
*/
|
||||
public class ScoreManager {
|
||||
private int currentScore = 0;
|
||||
private Map<Biome, BiomeGroup> biomeGroups;
|
||||
|
||||
// Constructeur avec la référence aux groupes de biomes
|
||||
public ScoreManager(Map<Biome, BiomeGroup> biomeGroups) {
|
||||
this.biomeGroups = biomeGroups;
|
||||
}
|
||||
|
||||
// Méthode pour calculer le score en fonction des groupes de biomes
|
||||
public void calculateScore() {
|
||||
int totalScore = 0;
|
||||
|
||||
for (BiomeGroup group : biomeGroups.values()) {
|
||||
totalScore += group.calculateTotalScore();
|
||||
}
|
||||
|
||||
currentScore = totalScore;
|
||||
}
|
||||
|
||||
// Récupérer le score actuel
|
||||
public int getCurrentScore() {
|
||||
return currentScore;
|
||||
}
|
||||
|
||||
// Mettre à jour le score (si nécessaire)
|
||||
public void updateScore() {
|
||||
calculateScore();
|
||||
}
|
||||
|
||||
// Réinitialiser le score
|
||||
public void resetScore() {
|
||||
currentScore = 0;
|
||||
}
|
||||
|
||||
}
|
254
src/fr/monkhanny/dorfromantik/game/Tile.java
Normal file
254
src/fr/monkhanny/dorfromantik/game/Tile.java
Normal file
@@ -0,0 +1,254 @@
|
||||
package fr.monkhanny.dorfromantik.game;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.RenderingHints;
|
||||
import java.util.HashMap;
|
||||
import java.util.Arrays;
|
||||
|
||||
import fr.monkhanny.dorfromantik.enums.Biome;
|
||||
import fr.monkhanny.dorfromantik.enums.TileOrientation;
|
||||
import fr.monkhanny.dorfromantik.utils.Hexagon;
|
||||
|
||||
|
||||
public class Tile extends Cell {
|
||||
|
||||
private HashMap<TileOrientation, Biome> sideBiomes = new HashMap<>();
|
||||
|
||||
|
||||
public Tile(Board board, int x, int y, int radius, Biome... biomes) {
|
||||
super(board, x, y, radius);
|
||||
TileOrientation[] sides = TileOrientation.values();
|
||||
for (int i = 0; i < sides.length; i++) {
|
||||
this.sideBiomes.put(sides[i], biomes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Tile(Board board, int x, int y, int radius) {
|
||||
super(board, x, y, radius);
|
||||
this.assignRandomBiomes();
|
||||
}
|
||||
|
||||
|
||||
public Tile(Board board, Point center, int radius, Biome... biomes) {
|
||||
this(board, center.x, center.y, radius, biomes);
|
||||
}
|
||||
|
||||
|
||||
public Tile(Board board, Point center, int radius) {
|
||||
this(board, center.x, center.y, radius);
|
||||
}
|
||||
|
||||
|
||||
public void setBiomes(Biome... biomes) {
|
||||
TileOrientation[] sides = TileOrientation.values();
|
||||
for (int i = 0; i < sides.length; i++) {
|
||||
this.sideBiomes.put(sides[i], biomes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void assignRandomBiomes() {
|
||||
Game game = this.getBoard().getGame();
|
||||
Biome[] biomes = Biome.values();
|
||||
TileOrientation[] sides = TileOrientation.values();
|
||||
|
||||
this.sideBiomes.clear();
|
||||
|
||||
Biome firstBiome = biomes[game.getRandomInt(biomes.length)];
|
||||
biomes = Arrays.stream(biomes).filter(b -> b != firstBiome).toArray(Biome[]::new);
|
||||
Biome secondBiome = biomes[game.getRandomInt(biomes.length)];
|
||||
|
||||
int firstBiomeSideCount = game.getRandomInt(sides.length + 1);
|
||||
int firstBiomeSideOffset = game.getRandomInt(sides.length);
|
||||
|
||||
for (int i = 0; i < sides.length; i++) {
|
||||
TileOrientation side = sides[(i + firstBiomeSideOffset) % sides.length];
|
||||
Biome assignedBiome = (i < firstBiomeSideCount) ? firstBiome : secondBiome;
|
||||
this.sideBiomes.put(side, assignedBiome);
|
||||
}
|
||||
}
|
||||
|
||||
public Biome getBiome(TileOrientation side) {
|
||||
return this.sideBiomes.get(side);
|
||||
}
|
||||
|
||||
|
||||
private Biome getDominantBiome() {
|
||||
TileOrientation[] sides = TileOrientation.values();
|
||||
|
||||
int firstBiomeCount = 0;
|
||||
int secondBiomeCount = 0;
|
||||
Biome firstBiome = this.getBiome(sides[0]);
|
||||
Biome secondBiome = null;
|
||||
|
||||
for (TileOrientation side : sides) {
|
||||
Biome currentBiome = this.getBiome(side);
|
||||
if (currentBiome.equals(firstBiome)) {
|
||||
firstBiomeCount++;
|
||||
} else {
|
||||
secondBiome = currentBiome;
|
||||
secondBiomeCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (firstBiomeCount > secondBiomeCount) {
|
||||
return firstBiome;
|
||||
} else if (firstBiomeCount < secondBiomeCount) {
|
||||
return secondBiome;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Biome[] getBiomes() {
|
||||
Biome[] biomes = new Biome[TileOrientation.values().length];
|
||||
for (TileOrientation side : TileOrientation.values()) {
|
||||
biomes[side.ordinal()] = this.getBiome(side);
|
||||
}
|
||||
return biomes;
|
||||
}
|
||||
|
||||
|
||||
public void rotate(boolean clockwise) {
|
||||
TileOrientation[] sides = TileOrientation.values();
|
||||
HashMap<TileOrientation, Biome> newBiomesMap = new HashMap<>();
|
||||
|
||||
for (int i = 0; i < sides.length; i++) {
|
||||
TileOrientation side = sides[i];
|
||||
TileOrientation newSide = clockwise ? sides[(i + 1) % sides.length] : sides[(i + sides.length - 1) % sides.length];
|
||||
newBiomesMap.put(newSide, this.sideBiomes.get(side));
|
||||
}
|
||||
|
||||
this.sideBiomes = newBiomesMap;
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
|
||||
public boolean containsBiome(Biome biome) {
|
||||
for (TileOrientation side : TileOrientation.values()) {
|
||||
if (this.getBiome(side) == biome) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isAdjacentTo(Tile otherTile) {
|
||||
// Obtenir le rayon de la tuile
|
||||
int tileRadius = this.getRadius();
|
||||
|
||||
// Compute the distance between the center of this tile and the other tile
|
||||
int deltaX = this.getX() - otherTile.getX();
|
||||
int deltaY = this.getY() - otherTile.getY();
|
||||
|
||||
// Calculate the Euclidean distance between the two tiles
|
||||
double distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
|
||||
// In a hexagonal grid, two tiles are adjacent if their distance is equal to the diameter (2 * radius)
|
||||
return distance <= (2 * tileRadius);
|
||||
}
|
||||
|
||||
private TileOrientation determineSide(int x, int y) {
|
||||
int radius = this.getRadius();
|
||||
TileOrientation[] sides = TileOrientation.values();
|
||||
double angle = Cell.to360Degrees(Math.toDegrees(Math.atan2(y - radius, x - radius)) + 120);
|
||||
|
||||
int floorSide = (int) Math.floor(Cell.to360Degrees(angle - 2) / 60);
|
||||
int ceilSide = (int) Math.floor(Cell.to360Degrees(angle + 2) / 60);
|
||||
|
||||
if (floorSide == ceilSide) {
|
||||
return sides[floorSide];
|
||||
}
|
||||
|
||||
Biome floorBiome = this.getBiome(sides[floorSide]);
|
||||
Biome dominantBiome = this.getDominantBiome();
|
||||
|
||||
if (dominantBiome == null && y > radius) {
|
||||
return TileOrientation.SOUTH;
|
||||
}
|
||||
|
||||
if (dominantBiome == null && y < radius) {
|
||||
return TileOrientation.NORTH;
|
||||
}
|
||||
|
||||
return floorBiome.equals(dominantBiome) ? sides[ceilSide] : sides[floorSide];
|
||||
}
|
||||
|
||||
|
||||
private void drawHexagonRow(Graphics2D g2d, double rowX, double rowY, double radius, int rowLength) {
|
||||
int gRadius = this.getRadius();
|
||||
|
||||
for (int i = 0; i < rowLength; i++) {
|
||||
Color[] colors;
|
||||
int x = (int) Math.round(rowX + radius * Math.sqrt(3) * i);
|
||||
int y = (int) Math.round(rowY);
|
||||
|
||||
if (x == Math.round(gRadius) && y == Math.round(gRadius)) {
|
||||
Biome dominantBiome = this.getDominantBiome();
|
||||
colors = (dominantBiome != null) ? dominantBiome.getBiomeColors() : this.getBiome(TileOrientation.SOUTH).getBiomeColors();
|
||||
} else {
|
||||
colors = this.getBiome(this.determineSide(x, y)).getBiomeColors();
|
||||
}
|
||||
|
||||
g2d.setColor(colors[i % colors.length]);
|
||||
g2d.fillPolygon(new Hexagon(x, y, (int) Math.ceil(radius), 90));
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawTileAt(Graphics g, int x, int y, float scale) {
|
||||
// Sauvegarde de l'état actuel du graphique
|
||||
Graphics2D g2d = (Graphics2D) g.create();
|
||||
|
||||
// Déplacement du contexte graphique à la position souhaitée
|
||||
g2d.translate(x, y);
|
||||
|
||||
// Appel de la méthode de dessin de la tuile à la nouvelle position
|
||||
paintTile(g2d, scale);
|
||||
g2d.dispose();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Méthode principale de dessin de la tuile.
|
||||
*
|
||||
* @param g Le contexte graphique
|
||||
* @param scale L'échelle de la tuile
|
||||
*/
|
||||
protected void paintTile(Graphics g, float scale) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g.create();
|
||||
int radius = this.getRadius();
|
||||
Point center = new Point(radius, radius);
|
||||
radius = (int) (radius * scale);
|
||||
Hexagon hexagon = new Hexagon(center, radius);
|
||||
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2d.setClip(hexagon);
|
||||
|
||||
double hexRadius = radius / Math.sqrt(3) / 3;
|
||||
double paddingX = center.x - radius;
|
||||
double paddingY = center.y - radius;
|
||||
|
||||
this.drawHexagonRow(g2d, paddingX + radius * 0.5, paddingY + radius - radius * Math.sqrt(3) / 2, hexRadius, 4);
|
||||
this.drawHexagonRow(g2d, paddingX, paddingY + radius - radius * Math.sqrt(3) / 3, hexRadius, 6);
|
||||
this.drawHexagonRow(g2d, paddingX - radius * 0.5, paddingY + radius - radius * Math.sqrt(3) / 6, hexRadius, 8);
|
||||
this.drawHexagonRow(g2d, paddingX - radius, paddingY + radius, hexRadius, 10);
|
||||
this.drawHexagonRow(g2d, paddingX - radius * 0.5, paddingY + radius + radius * Math.sqrt(3) / 6, hexRadius, 8);
|
||||
this.drawHexagonRow(g2d, paddingX, paddingY + radius + radius * Math.sqrt(3) / 3, hexRadius, 6);
|
||||
this.drawHexagonRow(g2d, paddingX + radius * 0.5, paddingY + radius + radius * Math.sqrt(3) / 2, hexRadius, 4);
|
||||
|
||||
g2d.setClip(null);
|
||||
g2d.setStroke(new BasicStroke((int) radius / 15));
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawPolygon(hexagon);
|
||||
|
||||
g2d.dispose();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
package fr.monkhanny.dorfromantik.game;
|
||||
|
||||
import fr.monkhanny.dorfromantik.listeners.TilePanningActionListener;
|
||||
|
||||
|
||||
public class TilePanningTransition {
|
||||
private Board board;
|
||||
private int targetOffsetX, targetOffsetY;
|
||||
private int steps;
|
||||
|
||||
public TilePanningTransition(Board board, int targetOffsetX, int targetOffsetY, int steps) {
|
||||
this.board = board;
|
||||
this.targetOffsetX = targetOffsetX;
|
||||
this.targetOffsetY = targetOffsetY;
|
||||
this.steps = steps;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
// Créer un listener d'animation
|
||||
TilePanningActionListener listener = new TilePanningActionListener(board, targetOffsetX, targetOffsetY, steps);
|
||||
|
||||
// Démarrer l'animation si aucune n'est en cours
|
||||
listener.startAnimation();
|
||||
}
|
||||
}
|
36
src/fr/monkhanny/dorfromantik/gui/ButtonHoverAnimator.java
Normal file
36
src/fr/monkhanny/dorfromantik/gui/ButtonHoverAnimator.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
import fr.monkhanny.dorfromantik.controller.ButtonHoverAnimationListener;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class ButtonHoverAnimator {
|
||||
|
||||
private final JButton button;
|
||||
private final Color originalColor;
|
||||
private static Font originalFont;
|
||||
private Timer animationTimer;
|
||||
|
||||
public ButtonHoverAnimator(JButton button) {
|
||||
this.button = button;
|
||||
this.originalColor = button.getForeground();
|
||||
ButtonHoverAnimator.originalFont = button.getFont();
|
||||
}
|
||||
|
||||
public void startAnimation(boolean entering) {
|
||||
if (animationTimer != null && animationTimer.isRunning()) {
|
||||
animationTimer.stop();
|
||||
}
|
||||
|
||||
// Create a new ActionListener instance
|
||||
animationTimer = new Timer(Options.ANIMATION_DELAY, new ButtonHoverAnimationListener(entering, button, originalColor, originalFont));
|
||||
animationTimer.start();
|
||||
}
|
||||
|
||||
public static void updateOriginalFont(float newFontSize) {
|
||||
originalFont = originalFont.deriveFont(newFontSize);
|
||||
}
|
||||
|
||||
}
|
87
src/fr/monkhanny/dorfromantik/gui/ButtonPanel.java
Normal file
87
src/fr/monkhanny/dorfromantik/gui/ButtonPanel.java
Normal file
@@ -0,0 +1,87 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.utils.FontManager;
|
||||
import fr.monkhanny.dorfromantik.components.Button;
|
||||
import fr.monkhanny.dorfromantik.controller.MainMenuMouseController;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
public class ButtonPanel extends JPanel {
|
||||
|
||||
private JButton newGameButton;
|
||||
private JButton continueGameButton;
|
||||
private JButton howToPlayButton;
|
||||
private JButton settingsButton;
|
||||
private JButton exitButton;
|
||||
|
||||
public ButtonPanel(float fontSize) {
|
||||
// Paramétrage de l'apparence du panneau
|
||||
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||
this.setOpaque(false); // Rendre le panneau transparent
|
||||
this.setBorder(BorderFactory.createEmptyBorder(50, 30, 30, 30)); // Marge à gauche et en bas
|
||||
|
||||
// Espacement vertical extensible pour centrer les boutons principaux verticalement
|
||||
this.add(Box.createVerticalGlue());
|
||||
|
||||
// Créer les boutons avec un style personnalisé
|
||||
newGameButton = Button.createCustomTextButton("Jouer", fontSize);
|
||||
continueGameButton = Button.createCustomTextButton("Récompenses", fontSize);
|
||||
howToPlayButton = Button.createCustomTextButton("Comment jouer ?", fontSize);
|
||||
settingsButton = Button.createCustomTextButton("Paramètres", fontSize);
|
||||
exitButton = Button.createCustomTextButton("Quitter", fontSize);
|
||||
|
||||
// Ajouter les boutons au panneau
|
||||
this.add(newGameButton);
|
||||
this.add(Box.createVerticalStrut(10)); // Espace entre les boutons
|
||||
this.add(continueGameButton);
|
||||
this.add(Box.createVerticalStrut(10));
|
||||
this.add(howToPlayButton);
|
||||
this.add(Box.createVerticalStrut(10));
|
||||
this.add(settingsButton);
|
||||
this.add(Box.createVerticalStrut(10));
|
||||
this.add(exitButton);
|
||||
|
||||
// Espacement extensible pour maintenir les icônes en bas
|
||||
this.add(Box.createVerticalGlue());
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
MainMenuMouseController gestionSouris = new MainMenuMouseController(this);
|
||||
}
|
||||
|
||||
public JButton getNewGameButton() {
|
||||
return newGameButton;
|
||||
}
|
||||
|
||||
public JButton getContinueGameButton() {
|
||||
return continueGameButton;
|
||||
}
|
||||
|
||||
public JButton getHowToPlayButton() {
|
||||
return howToPlayButton;
|
||||
}
|
||||
|
||||
public JButton getSettingsButton() {
|
||||
return settingsButton;
|
||||
}
|
||||
|
||||
public JButton getExitButton() {
|
||||
return exitButton;
|
||||
}
|
||||
|
||||
public List<JButton> getButtons() {
|
||||
return Arrays.asList(newGameButton, continueGameButton, howToPlayButton, settingsButton, exitButton);
|
||||
}
|
||||
|
||||
public void updateButtonFonts(int windowWidth) {
|
||||
// Mettre à jour la police des boutons avec la taille ajustée
|
||||
float newFontSize = windowWidth / 30f;
|
||||
newGameButton.setFont(FontManager.getTitleFont(newFontSize));
|
||||
continueGameButton.setFont(FontManager.getTitleFont(newFontSize));
|
||||
howToPlayButton.setFont(FontManager.getTitleFont(newFontSize));
|
||||
settingsButton.setFont(FontManager.getTitleFont(newFontSize));
|
||||
exitButton.setFont(FontManager.getTitleFont(newFontSize));
|
||||
}
|
||||
}
|
165
src/fr/monkhanny/dorfromantik/gui/GameModeSelectionPanel.java
Normal file
165
src/fr/monkhanny/dorfromantik/gui/GameModeSelectionPanel.java
Normal file
@@ -0,0 +1,165 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.components.Title;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class GameModeSelectionPanel extends JPanel {
|
||||
|
||||
private JLabel titleLabel;
|
||||
private JButton mode1Button;
|
||||
private JButton mode2Button;
|
||||
private JButton mode3Button;
|
||||
private JButton mode4Button;
|
||||
private JTextField seedField;
|
||||
private JButton startButton;
|
||||
|
||||
|
||||
public GameModeSelectionPanel(ActionListener buttonListener, JFrame gameModeFrame, MainMenu mainMenu) {
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
// Ajouter l'image de fond
|
||||
JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg"));
|
||||
background.setLayout(new BorderLayout()); // Utilisation de BorderLayout ici
|
||||
this.add(background);
|
||||
|
||||
// Créer un topPanel avec le bouton de retour
|
||||
JPanel topPanel = createTopPanel(gameModeFrame, mainMenu);
|
||||
background.add(topPanel, BorderLayout.NORTH); // Placer topPanel en haut à gauche
|
||||
|
||||
// Panel principal (au centre)
|
||||
JPanel mainPanel = createMainPanel();
|
||||
background.add(mainPanel, BorderLayout.CENTER); // Placer le contenu principal sous le bouton
|
||||
|
||||
// Title
|
||||
titleLabel = new Title("Choisissez un mode de jeu", 60f, Color.WHITE);
|
||||
mainPanel.add(titleLabel, createGridBagConstraints(0, 0, 2));
|
||||
|
||||
mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 1, 1));
|
||||
|
||||
// Mode buttons - now horizontally aligned
|
||||
JPanel modePanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10)); // Centered with horizontal spacing
|
||||
modePanel.setOpaque(false);
|
||||
|
||||
mode1Button = createGameModeButton("Mode 1", buttonListener);
|
||||
mode2Button = createGameModeButton("Mode 2", buttonListener);
|
||||
mode3Button = createGameModeButton("Mode 3", buttonListener);
|
||||
mode4Button = createGameModeButton("Mode 4", buttonListener);
|
||||
|
||||
modePanel.add(mode1Button);
|
||||
modePanel.add(mode2Button);
|
||||
modePanel.add(mode3Button);
|
||||
modePanel.add(mode4Button);
|
||||
|
||||
mainPanel.add(modePanel, createGridBagConstraints(0, 2, 2)); // Span across 2 columns
|
||||
|
||||
mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 3, 1));
|
||||
|
||||
// Seed input and start button
|
||||
JPanel seedPanel = createSeedPanel(buttonListener);
|
||||
mainPanel.add(seedPanel, createGridBagConstraints(0, 4, 2));
|
||||
}
|
||||
|
||||
private JPanel createTopPanel(JFrame gameModeFrame, MainMenu mainMenu) {
|
||||
// Utilisation de BorderLayout pour aligner correctement le bouton à gauche
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
topPanel.setOpaque(false);
|
||||
|
||||
// Création du bouton de retour
|
||||
JButton returnButton = createReturnButtonWithIcon(gameModeFrame, mainMenu);
|
||||
|
||||
// Ajouter le bouton de retour à gauche (West)
|
||||
topPanel.add(returnButton, BorderLayout.WEST);
|
||||
|
||||
return topPanel;
|
||||
}
|
||||
|
||||
private JButton createReturnButtonWithIcon(JFrame gameModeFrame, MainMenu mainMenu) {
|
||||
ImageIcon originalIcon = new ImageIcon("./ressources/images/Icone/ExitIcon.png");
|
||||
Image scaledImage = originalIcon.getImage().getScaledInstance(50, 50, Image.SCALE_SMOOTH);
|
||||
ImageIcon resizedIcon = new ImageIcon(scaledImage);
|
||||
|
||||
JButton returnButton = new JButton(resizedIcon);
|
||||
returnButton.setPreferredSize(new Dimension(50, 50));
|
||||
returnButton.setContentAreaFilled(false);
|
||||
returnButton.setBorderPainted(false);
|
||||
returnButton.setFocusPainted(false);
|
||||
returnButton.addActionListener(e -> {
|
||||
gameModeFrame.setVisible(false);
|
||||
mainMenu.setVisible(true);
|
||||
});
|
||||
|
||||
return returnButton;
|
||||
}
|
||||
|
||||
private JPanel createMainPanel() {
|
||||
JPanel mainPanel = new JPanel(new GridBagLayout());
|
||||
mainPanel.setOpaque(false);
|
||||
return mainPanel;
|
||||
}
|
||||
|
||||
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(20, 30, 20, 30);
|
||||
return gbc;
|
||||
}
|
||||
|
||||
|
||||
private JButton createGameModeButton(String modeName, ActionListener buttonListener) {
|
||||
JButton button = new JButton(modeName);
|
||||
button.setFont(new Font("Arial", Font.BOLD, 24));
|
||||
button.setBackground(new Color(0, 122, 255));
|
||||
button.setForeground(Color.WHITE);
|
||||
button.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
||||
button.setFocusPainted(false);
|
||||
button.addActionListener(buttonListener);
|
||||
button.setPreferredSize(new Dimension(150, 50)); // Adjust the size of the buttons
|
||||
return button;
|
||||
}
|
||||
|
||||
private JPanel createSeedPanel(ActionListener buttonListener) {
|
||||
JPanel seedPanel = new JPanel();
|
||||
seedPanel.setOpaque(false);
|
||||
seedPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
|
||||
JLabel seedLabel = new JLabel("Entrez votre seed:");
|
||||
seedLabel.setForeground(Color.WHITE);
|
||||
seedPanel.add(seedLabel);
|
||||
|
||||
seedField = new JTextField(20);
|
||||
seedField.setFont(new Font("Arial", Font.PLAIN, 18));
|
||||
seedField.setPreferredSize(new Dimension(250, 40));
|
||||
seedField.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
||||
seedPanel.add(seedField);
|
||||
|
||||
startButton = new JButton("Démarrer");
|
||||
startButton.setFont(new Font("Arial", Font.BOLD, 24));
|
||||
startButton.setBackground(new Color(0, 255, 0));
|
||||
startButton.setForeground(Color.WHITE);
|
||||
startButton.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
||||
startButton.setPreferredSize(new Dimension(150, 50));
|
||||
startButton.addActionListener(buttonListener);
|
||||
seedPanel.add(startButton);
|
||||
|
||||
return seedPanel;
|
||||
}
|
||||
|
||||
public String getStringSeed() {
|
||||
return seedField.getText();
|
||||
}
|
||||
|
||||
public long getLongSeed(){
|
||||
try{
|
||||
return Long.parseLong(seedField.getText());
|
||||
} catch (NumberFormatException e){
|
||||
System.err.println("Invalid seed, using current time as seed");
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
}
|
12
src/fr/monkhanny/dorfromantik/gui/Leaderboard.java
Normal file
12
src/fr/monkhanny/dorfromantik/gui/Leaderboard.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public abstract class Leaderboard extends JPanel {
|
||||
public Leaderboard() {
|
||||
setLayout(new BorderLayout());
|
||||
}
|
||||
|
||||
public abstract void refresh(); // Méthode pour actualiser le contenu
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class LeaderboardBarChartPanel extends JPanel {
|
||||
private int totalPlayers;
|
||||
private int rank;
|
||||
|
||||
public LeaderboardBarChartPanel(int totalPlayers, int rank) {
|
||||
this.totalPlayers = totalPlayers;
|
||||
this.rank = rank;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
int spacing = 10; // Espacement entre les barres
|
||||
int barHeight = 20; // Hauteur de la barre
|
||||
int totalBars = 10; // Nombre de tranches
|
||||
int maxWidth = (getWidth() - (totalBars + 1) * spacing) / totalBars;
|
||||
|
||||
// Dessiner chaque barre pour chaque tranche
|
||||
for (int i = 0; i < totalBars; i++) {
|
||||
int x = spacing + i * (maxWidth + spacing);
|
||||
int y = 50; // Position verticale de la barre
|
||||
|
||||
// Déterminer la couleur : colorier la tranche actuelle
|
||||
if (i == (rank - 1) / (totalPlayers / 10)) {
|
||||
g.setColor(new Color(0, 255, 0)); // Vert pour la tranche actuelle
|
||||
} else {
|
||||
g.setColor(new Color(255, 0, 0)); // Rouge pour les autres tranches
|
||||
}
|
||||
|
||||
// Dessiner la barre
|
||||
g.fillRect(x, y, maxWidth, barHeight);
|
||||
}
|
||||
}
|
||||
}
|
64
src/fr/monkhanny/dorfromantik/gui/LeaderboardByTier.java
Normal file
64
src/fr/monkhanny/dorfromantik/gui/LeaderboardByTier.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
// @TODO : MODIFIER CAR C'EST PAS BEAU + BDD
|
||||
public class LeaderboardByTier extends Leaderboard {
|
||||
|
||||
public LeaderboardByTier() {
|
||||
super();
|
||||
refresh(); // Charge les données initiales
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
removeAll(); // Supprime tout contenu existant
|
||||
setBackground(new Color(64, 0, 128));
|
||||
|
||||
// Titre
|
||||
JLabel titleLabel = new JLabel("CLASSEMENT PAR TRANCHE");
|
||||
titleLabel.setForeground(Color.WHITE);
|
||||
titleLabel.setFont(new Font("Arial", Font.BOLD, 24));
|
||||
titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
add(titleLabel, BorderLayout.NORTH);
|
||||
|
||||
// Contenu
|
||||
JPanel tierPanel = new JPanel();
|
||||
tierPanel.setLayout(new BoxLayout(tierPanel, BoxLayout.Y_AXIS));
|
||||
tierPanel.setBackground(new Color(64, 0, 128));
|
||||
|
||||
// Exemple de tranche
|
||||
int totalPlayers = 1000;
|
||||
int rank = 237; // Exemple : rang du joueur
|
||||
int tierSize = totalPlayers / 10;
|
||||
int tier = (rank - 1) / tierSize + 1;
|
||||
|
||||
// Label indiquant la tranche dans laquelle le joueur se trouve
|
||||
JLabel infoLabel = new JLabel("Vous êtes dans la tranche : " + tier);
|
||||
infoLabel.setFont(new Font("Arial", Font.PLAIN, 18));
|
||||
infoLabel.setForeground(Color.WHITE);
|
||||
infoLabel.setAlignmentX(CENTER_ALIGNMENT);
|
||||
|
||||
// Pourcentage du joueur
|
||||
double percentage = (double) rank / totalPlayers * 100;
|
||||
JLabel percentageLabel = new JLabel(String.format("Vous faites partie des %.2f%% des joueurs", percentage));
|
||||
percentageLabel.setFont(new Font("Arial", Font.PLAIN, 18));
|
||||
percentageLabel.setForeground(Color.WHITE);
|
||||
percentageLabel.setAlignmentX(CENTER_ALIGNMENT);
|
||||
|
||||
// Ajouter les labels à la JPanel
|
||||
tierPanel.add(Box.createVerticalStrut(20));
|
||||
tierPanel.add(infoLabel);
|
||||
tierPanel.add(percentageLabel);
|
||||
|
||||
// Ajouter le diagramme en barres pour les tranches
|
||||
LeaderboardBarChartPanel barChartPanel = new LeaderboardBarChartPanel(totalPlayers, rank);
|
||||
tierPanel.add(Box.createVerticalStrut(20)); // Espacement
|
||||
tierPanel.add(barChartPanel);
|
||||
|
||||
add(tierPanel, BorderLayout.CENTER);
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
}
|
160
src/fr/monkhanny/dorfromantik/gui/LeaderboardWorldWide.java
Normal file
160
src/fr/monkhanny/dorfromantik/gui/LeaderboardWorldWide.java
Normal file
@@ -0,0 +1,160 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.utils.Database;
|
||||
import fr.monkhanny.dorfromantik.utils.PlayerScore;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class LeaderboardWorldWide extends Leaderboard {
|
||||
|
||||
public LeaderboardWorldWide() {
|
||||
super();
|
||||
refresh(); // Charge les données initiales
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
removeAll(); // Supprime tout contenu existant
|
||||
setBackground(new Color(245, 245, 245)); // Gris clair plus chaleureux
|
||||
|
||||
// Panel principal pour centrer le leaderboard
|
||||
JPanel mainPanel = new JPanel();
|
||||
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
|
||||
mainPanel.setBackground(new Color(245, 245, 245)); // Gris clair
|
||||
mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
||||
|
||||
// Titre
|
||||
JLabel titleLabel = new JLabel("Classement mondial");
|
||||
titleLabel.setForeground(new Color(76, 175, 80)); // Vert plus doux et moderne
|
||||
titleLabel.setFont(new Font("Roboto", Font.BOLD, 32)); // Police moderne
|
||||
titleLabel.setAlignmentX(CENTER_ALIGNMENT);
|
||||
|
||||
// Panel pour les trois premiers
|
||||
JPanel topThreePanel = new JPanel(new GridBagLayout());
|
||||
topThreePanel.setBackground(new Color(245, 245, 245)); // Gris clair
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.insets = new Insets(0, 10, 0, 10);
|
||||
|
||||
// Récupérer les meilleurs joueurs depuis la base de données
|
||||
Database db = null;
|
||||
List<PlayerScore> topPlayers = null;
|
||||
try {
|
||||
db = new Database();
|
||||
topPlayers = db.getTopPlayers();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (db != null) {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (topPlayers != null && topPlayers.size() >= 3) {
|
||||
// Ajout des trois premiers joueurs avec médailles
|
||||
gbc.gridx = 0;
|
||||
gbc.weightx = 0.4;
|
||||
topThreePanel.add(createTopPlayerPanel(topPlayers.get(1).getUsername(), topPlayers.get(1).getScore(),
|
||||
"./ressources/images/MainMenu/Leaderboard/2.png", false), gbc);
|
||||
|
||||
gbc.gridx = 1;
|
||||
gbc.weightx = 0.5;
|
||||
topThreePanel.add(createTopPlayerPanel(topPlayers.get(0).getUsername(), topPlayers.get(0).getScore(),
|
||||
"./ressources/images/MainMenu/Leaderboard/1.png", true), gbc);
|
||||
|
||||
gbc.gridx = 2;
|
||||
gbc.weightx = 0.4;
|
||||
topThreePanel.add(createTopPlayerPanel(topPlayers.get(2).getUsername(), topPlayers.get(2).getScore(),
|
||||
"./ressources/images/MainMenu/Leaderboard/3.png", false), gbc);
|
||||
}
|
||||
|
||||
// Panel pour les autres joueurs
|
||||
JPanel playersPanel = new JPanel();
|
||||
playersPanel.setLayout(new BoxLayout(playersPanel, BoxLayout.Y_AXIS));
|
||||
playersPanel.setBackground(new Color(255, 255, 255)); // Blanc cassé
|
||||
|
||||
// Ajout des joueurs restants (de 4 à 10)
|
||||
if (topPlayers != null) {
|
||||
for (int i = 3; i < topPlayers.size(); i++) {
|
||||
PlayerScore player = topPlayers.get(i);
|
||||
playersPanel.add(createPlayerPanel(player.getUsername(), player.getScore(), i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
// Ajoute tout au panneau principal
|
||||
mainPanel.add(titleLabel);
|
||||
mainPanel.add(Box.createRigidArea(new Dimension(0, 20)));
|
||||
mainPanel.add(topThreePanel);
|
||||
mainPanel.add(Box.createRigidArea(new Dimension(0, 20)));
|
||||
mainPanel.add(playersPanel);
|
||||
|
||||
add(mainPanel, BorderLayout.CENTER);
|
||||
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
private JPanel createPlayerPanel(String playerName, int score, int rank) {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BorderLayout());
|
||||
panel.setBackground(new Color(250, 250, 250)); // Blanc cassé
|
||||
panel.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 0, new Color(220, 220, 220))); // Bordure gris clair
|
||||
|
||||
JLabel rankLabel = new JLabel(rank + ". ");
|
||||
rankLabel.setFont(new Font("Roboto", Font.BOLD, 18));
|
||||
rankLabel.setForeground(new Color(76, 175, 80)); // Vert doux pour le rang
|
||||
rankLabel.setPreferredSize(new Dimension(40, 40));
|
||||
|
||||
JLabel nameLabel = new JLabel(playerName);
|
||||
nameLabel.setFont(new Font("Roboto", Font.PLAIN, 18));
|
||||
nameLabel.setForeground(new Color(60, 60, 60)); // Gris foncé pour le nom
|
||||
|
||||
JLabel scoreLabel = new JLabel(Integer.toString(score));
|
||||
scoreLabel.setFont(new Font("Roboto", Font.BOLD, 18));
|
||||
scoreLabel.setForeground(new Color(255, 140, 0)); // Orange moderne pour le score
|
||||
|
||||
panel.add(rankLabel, BorderLayout.WEST);
|
||||
panel.add(nameLabel, BorderLayout.CENTER);
|
||||
panel.add(scoreLabel, BorderLayout.EAST);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
private ImageIcon resizeIcon(String path, int width, int height) {
|
||||
ImageIcon icon = new ImageIcon(path);
|
||||
Image img = icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH);
|
||||
return new ImageIcon(img);
|
||||
}
|
||||
|
||||
private JPanel createTopPlayerPanel(String playerName, int score, String medalPath, boolean isFirst) {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||
panel.setBackground(isFirst ? new Color(255, 215, 0) : new Color(144, 238, 144)); // Or doré pour le premier, vert clair pour les autres
|
||||
panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
||||
|
||||
// Ajout de l'icône de médaille redimensionnée
|
||||
JLabel medalLabel = new JLabel(resizeIcon(medalPath, isFirst ? 80 : 60, isFirst ? 80 : 60));
|
||||
medalLabel.setAlignmentX(CENTER_ALIGNMENT);
|
||||
|
||||
JLabel nameLabel = new JLabel(playerName);
|
||||
nameLabel.setFont(new Font("Roboto", isFirst ? Font.BOLD : Font.PLAIN, 20));
|
||||
nameLabel.setForeground(new Color(76, 175, 80)); // Vert doux pour le nom
|
||||
nameLabel.setAlignmentX(CENTER_ALIGNMENT);
|
||||
|
||||
JLabel scoreLabel = new JLabel(Integer.toString(score));
|
||||
scoreLabel.setFont(new Font("Roboto", Font.BOLD, isFirst ? 32 : 28));
|
||||
scoreLabel.setForeground(new Color(60, 60, 60)); // Gris foncé pour le score
|
||||
scoreLabel.setAlignmentX(CENTER_ALIGNMENT);
|
||||
|
||||
panel.add(medalLabel);
|
||||
panel.add(Box.createRigidArea(new Dimension(0, 5)));
|
||||
panel.add(nameLabel);
|
||||
panel.add(Box.createRigidArea(new Dimension(0, 5)));
|
||||
panel.add(scoreLabel);
|
||||
|
||||
return panel;
|
||||
}
|
||||
}
|
74
src/fr/monkhanny/dorfromantik/gui/MainMenu.java
Normal file
74
src/fr/monkhanny/dorfromantik/gui/MainMenu.java
Normal file
@@ -0,0 +1,74 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.utils.FontManager;
|
||||
import fr.monkhanny.dorfromantik.utils.ImageLoader;
|
||||
import fr.monkhanny.dorfromantik.enums.Fonts;
|
||||
import fr.monkhanny.dorfromantik.components.Title;
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
|
||||
public class MainMenu extends JFrame {
|
||||
|
||||
private Title titleLabel;
|
||||
private ButtonPanel buttonPanel;
|
||||
private JPanel leaderboardContainer; // Conteneur pour le leaderboard
|
||||
private Leaderboard currentLeaderboard; // Référence au leaderboard actuel
|
||||
|
||||
public MainMenu() {
|
||||
// Charger les polices pour le titre et les boutons
|
||||
FontManager.loadCustomFont(Fonts.TITLE); // Charge la police pour le titre
|
||||
FontManager.loadCustomFont(Fonts.BUTTON); // Charge la police pour les boutons
|
||||
|
||||
// Paramétrage de la fenêtre principale
|
||||
this.setTitle("Dorfromantik - Menu Principal");
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
super.setIconImage(ImageLoader.APPLICATION_ICON);
|
||||
this.setMinimumSize(Options.MINIMUM_FRAME_SIZE);
|
||||
this.setSize(1200, 800);
|
||||
this.setLocationRelativeTo(null); // Centrer la fenêtre
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
// Arrière plan du menu principal
|
||||
JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/background.jpg"));
|
||||
background.setLayout(new BorderLayout());
|
||||
this.setContentPane(background);
|
||||
|
||||
// Ajouter le titre en haut au centre
|
||||
this.titleLabel = new Title("Dorfromantik", Options.BASE_TITLE_FONT_SIZE);
|
||||
background.add(titleLabel, BorderLayout.NORTH);
|
||||
|
||||
// Panneau des boutons avec style personnalisé (à gauche)
|
||||
this.buttonPanel = new ButtonPanel(Options.BASE_BUTTON_FONT_SIZE);
|
||||
background.add(buttonPanel, BorderLayout.WEST);
|
||||
|
||||
// Panel contenant le leaderboard avec espace à droite (pour pas qu'il soit collé au bord)
|
||||
JPanel leaderboardWrapper = new JPanel();
|
||||
leaderboardWrapper.setLayout(new BorderLayout());
|
||||
leaderboardWrapper.setOpaque(false); // Fond transparent pour laisser voir le background
|
||||
leaderboardWrapper.setBorder(BorderFactory.createEmptyBorder(20, 10, 20, 20)); // Ajout de marges internes
|
||||
|
||||
// Conteneur du leaderboard
|
||||
leaderboardContainer = new JPanel();
|
||||
leaderboardContainer.setLayout(new BorderLayout());
|
||||
leaderboardContainer.setOpaque(false); // Fond transparent pour laisser voir le background
|
||||
leaderboardWrapper.add(leaderboardContainer, BorderLayout.CENTER);
|
||||
background.add(leaderboardWrapper, BorderLayout.EAST);
|
||||
|
||||
// Initialisation du premier leaderboard (LeaderboardWorldwide)
|
||||
currentLeaderboard = new LeaderboardWorldWide();
|
||||
leaderboardContainer.add(currentLeaderboard, BorderLayout.CENTER);
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
public Title getTitleLabel() {
|
||||
return titleLabel;
|
||||
}
|
||||
|
||||
public ButtonPanel getButtonPanel() {
|
||||
return buttonPanel;
|
||||
}
|
||||
}
|
34
src/fr/monkhanny/dorfromantik/gui/Reward.java
Normal file
34
src/fr/monkhanny/dorfromantik/gui/Reward.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
// Classe pour représenter une récompense
|
||||
public class Reward {
|
||||
private String name;
|
||||
private String description;
|
||||
private boolean isUnlocked;
|
||||
private ImageIcon icon;
|
||||
|
||||
public Reward(String name, String description, boolean isUnlocked, ImageIcon icon) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.isUnlocked = isUnlocked;
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public boolean isUnlocked() {
|
||||
return isUnlocked;
|
||||
}
|
||||
|
||||
public ImageIcon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
}
|
217
src/fr/monkhanny/dorfromantik/gui/RewardsPanel.java
Normal file
217
src/fr/monkhanny/dorfromantik/gui/RewardsPanel.java
Normal file
@@ -0,0 +1,217 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.controller.RewardsPanelController;
|
||||
import fr.monkhanny.dorfromantik.components.Title;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
|
||||
public class RewardsPanel extends JPanel {
|
||||
|
||||
private JTextField usernameField;
|
||||
private JPanel rewardsDisplayPanel;
|
||||
private JScrollPane scrollPane;
|
||||
private JFrame mainMenuFrame;
|
||||
private JFrame rewardsFrame;
|
||||
private RewardsPanelController controller;
|
||||
|
||||
public RewardsPanel(JFrame mainMenuFrame, JFrame rewardsFrame) {
|
||||
this.mainMenuFrame = mainMenuFrame;
|
||||
this.rewardsFrame = rewardsFrame;
|
||||
this.controller = new RewardsPanelController(this);
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
// Ajouter le fond d'écran
|
||||
JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg"));
|
||||
background.setLayout(new BorderLayout());
|
||||
this.setLayout(new BorderLayout());
|
||||
this.add(background);
|
||||
|
||||
// Créer un panneau pour le bouton de retour en haut
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
topPanel.setOpaque(false);
|
||||
background.add(topPanel, BorderLayout.NORTH);
|
||||
|
||||
// Ajouter le bouton de retour en haut à gauche
|
||||
JPanel backButtonPanel = createBackButtonPanel();
|
||||
topPanel.add(backButtonPanel, BorderLayout.WEST);
|
||||
|
||||
// Titre du panneau
|
||||
JPanel titlePanel = createTitlePanel();
|
||||
topPanel.add(titlePanel, BorderLayout.CENTER);
|
||||
|
||||
// Panel principal
|
||||
JPanel mainPanel = createMainPanel();
|
||||
background.add(mainPanel, BorderLayout.CENTER);
|
||||
|
||||
// Panel d'entrée (nom d'utilisateur)
|
||||
JPanel inputPanel = createInputPanel();
|
||||
mainPanel.add(inputPanel, createGridBagConstraints(0, 0, 1));
|
||||
|
||||
// Panel pour afficher les récompenses
|
||||
rewardsDisplayPanel = new JPanel(new GridLayout(0, 3, 10, 10));
|
||||
this.scrollPane = new JScrollPane(rewardsDisplayPanel);
|
||||
mainPanel.add(this.scrollPane, createGridBagConstraints(0, 1, 1));
|
||||
|
||||
// Action du bouton pour afficher les récompenses
|
||||
JButton fetchButton = new JButton("Afficher les récompenses de l'utilisateur");
|
||||
fetchButton.setFont(new Font("Arial", Font.BOLD, 20));
|
||||
fetchButton.setBackground(new Color(0, 122, 255));
|
||||
fetchButton.setForeground(Color.WHITE);
|
||||
fetchButton.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
||||
fetchButton.setPreferredSize(new Dimension(500, 50));
|
||||
|
||||
// Utilisation du controller pour gérer l'action du bouton
|
||||
fetchButton.addActionListener(controller.getFetchRewardsAction());
|
||||
|
||||
// Ajouter le bouton en bas
|
||||
JPanel buttonPanel = new JPanel();
|
||||
buttonPanel.setOpaque(false);
|
||||
buttonPanel.add(fetchButton);
|
||||
mainPanel.add(buttonPanel, createGridBagConstraints(0, 2, 1));
|
||||
}
|
||||
|
||||
private JPanel createBackButtonPanel() {
|
||||
JPanel backButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
||||
backButtonPanel.setOpaque(false);
|
||||
|
||||
ImageIcon icon = new ImageIcon("./ressources/images/Icone/ExitIcon.png");
|
||||
Image scaledImage = icon.getImage().getScaledInstance(50, 50, Image.SCALE_SMOOTH);
|
||||
ImageIcon scaledIcon = new ImageIcon(scaledImage);
|
||||
|
||||
JButton backButton = new JButton(scaledIcon);
|
||||
backButton.setContentAreaFilled(false);
|
||||
backButton.setBorderPainted(false);
|
||||
backButton.setFocusPainted(false);
|
||||
backButton.setPreferredSize(new Dimension(50, 50));
|
||||
|
||||
// Utilisation du controller pour gérer l'action du bouton retour
|
||||
backButton.addActionListener(controller.getBackButtonAction());
|
||||
|
||||
backButtonPanel.add(backButton);
|
||||
return backButtonPanel;
|
||||
}
|
||||
|
||||
private JPanel createTitlePanel() {
|
||||
JPanel titlePanel = new JPanel(new BorderLayout());
|
||||
titlePanel.setOpaque(false);
|
||||
|
||||
Title title = new Title("Récompenses", 70, Color.WHITE);
|
||||
title.setHorizontalAlignment(JLabel.CENTER);
|
||||
titlePanel.add(title, BorderLayout.CENTER);
|
||||
|
||||
return titlePanel;
|
||||
}
|
||||
|
||||
private JPanel createMainPanel() {
|
||||
JPanel mainPanel = new JPanel(new GridBagLayout());
|
||||
mainPanel.setOpaque(false);
|
||||
return mainPanel;
|
||||
}
|
||||
|
||||
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(20, 30, 20, 30);
|
||||
return gbc;
|
||||
}
|
||||
|
||||
private JPanel createInputPanel() {
|
||||
JPanel inputPanel = new JPanel();
|
||||
inputPanel.setOpaque(false);
|
||||
inputPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
|
||||
|
||||
JLabel usernameLabel = new JLabel("Entrer le nom d'utilisateur :");
|
||||
usernameLabel.setForeground(Color.WHITE);
|
||||
usernameLabel.setFont(new Font("Arial", Font.BOLD, 20));
|
||||
inputPanel.add(usernameLabel);
|
||||
|
||||
usernameField = new JTextField(20);
|
||||
usernameField.setFont(new Font("Arial", Font.PLAIN, 18));
|
||||
usernameField.setPreferredSize(new Dimension(250, 40));
|
||||
usernameField.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
|
||||
inputPanel.add(usernameField);
|
||||
|
||||
return inputPanel;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return usernameField.getText().trim();
|
||||
}
|
||||
|
||||
public JFrame getMainMenuFrame() {
|
||||
return mainMenuFrame;
|
||||
}
|
||||
|
||||
public JFrame getRewardsFrame() {
|
||||
return rewardsFrame;
|
||||
}
|
||||
|
||||
public void updateRewardsPanel(List<Reward> rewards) {
|
||||
rewardsDisplayPanel.removeAll();
|
||||
|
||||
if (rewards.isEmpty()) {
|
||||
JLabel noRewardsLabel = new JLabel("Aucune récompense trouvée...", JLabel.CENTER);
|
||||
noRewardsLabel.setFont(new Font("Arial", Font.BOLD, 18));
|
||||
noRewardsLabel.setForeground(Color.RED);
|
||||
rewardsDisplayPanel.add(noRewardsLabel);
|
||||
} else {
|
||||
this.scrollPane.setPreferredSize(new Dimension(600, 300));
|
||||
this.scrollPane.setMinimumSize(new Dimension(600, 300));
|
||||
|
||||
rewardsDisplayPanel.setLayout(new GridLayout(0, 3, 10, 10));
|
||||
|
||||
for (Reward reward : rewards) {
|
||||
JPanel rewardPanel = createRewardPanel(reward);
|
||||
rewardsDisplayPanel.add(rewardPanel);
|
||||
}
|
||||
}
|
||||
|
||||
rewardsDisplayPanel.revalidate();
|
||||
rewardsDisplayPanel.repaint();
|
||||
this.revalidate();
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
private JPanel createRewardPanel(Reward reward) {
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
panel.setPreferredSize(new Dimension(180, 220));
|
||||
|
||||
Color backgroundColor = reward.isUnlocked() ? new Color(230, 255, 230) : new Color(255, 245, 235);
|
||||
panel.setBackground(backgroundColor);
|
||||
|
||||
panel.setBorder(BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createLineBorder(new Color(150, 200, 150), 1),
|
||||
BorderFactory.createEmptyBorder(10, 10, 10, 10)
|
||||
));
|
||||
|
||||
JLabel iconLabel = new JLabel();
|
||||
if (reward.getIcon() != null) {
|
||||
iconLabel.setIcon(reward.getIcon());
|
||||
} else {
|
||||
iconLabel.setText("No Icon");
|
||||
}
|
||||
iconLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||
panel.add(iconLabel, BorderLayout.CENTER);
|
||||
|
||||
JLabel nameLabel = new JLabel(reward.getName());
|
||||
nameLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||
nameLabel.setFont(new Font("Segoe UI", Font.BOLD, 16));
|
||||
nameLabel.setForeground(new Color(80, 120, 80));
|
||||
nameLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||
panel.add(nameLabel, BorderLayout.NORTH);
|
||||
|
||||
JLabel descriptionLabel = new JLabel("<html><body style='text-align: center;'>" + reward.getDescription() + "</body></html>");
|
||||
descriptionLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||
descriptionLabel.setFont(new Font("Segoe UI", Font.PLAIN, 12));
|
||||
descriptionLabel.setForeground(new Color(90, 90, 90));
|
||||
panel.add(descriptionLabel, BorderLayout.SOUTH);
|
||||
|
||||
return panel;
|
||||
}
|
||||
}
|
234
src/fr/monkhanny/dorfromantik/gui/SettingsPanel.java
Normal file
234
src/fr/monkhanny/dorfromantik/gui/SettingsPanel.java
Normal file
@@ -0,0 +1,234 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
import fr.monkhanny.dorfromantik.components.Title;
|
||||
import fr.monkhanny.dorfromantik.listeners.*;
|
||||
import fr.monkhanny.dorfromantik.enums.Images;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
public class SettingsPanel extends JPanel {
|
||||
|
||||
private MainMenu mainMenu;
|
||||
private JFrame settingsFrame;
|
||||
|
||||
public SettingsPanel(MainMenu mainMenu, JFrame settingsFrame) {
|
||||
this.mainMenu = mainMenu;
|
||||
this.settingsFrame = settingsFrame;
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
initializeSettingsFrame();
|
||||
setupBackground();
|
||||
setupTopPanel(); // Nouveau panneau pour le titre et le bouton de retour
|
||||
setupMainPanel(); // Configuration du panneau principal pour les sliders et boutons
|
||||
}
|
||||
|
||||
private void initializeSettingsFrame() {
|
||||
settingsFrame.setMinimumSize(Options.MINIMUM_FRAME_SIZE);
|
||||
}
|
||||
|
||||
private void setupBackground() {
|
||||
JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg"));
|
||||
background.setLayout(new GridBagLayout());
|
||||
this.add(background, BorderLayout.CENTER); // Déplacer l'ajout du fond au centre
|
||||
}
|
||||
|
||||
private void setupTopPanel() {
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
topPanel.setOpaque(false);
|
||||
|
||||
Title title = new Title("Paramètres", 70, Color.WHITE);
|
||||
title.setHorizontalAlignment(JLabel.CENTER);
|
||||
topPanel.add(title, BorderLayout.CENTER);
|
||||
|
||||
JButton returnButton = createReturnButtonWithIcon();
|
||||
JPanel leftPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
leftPanel.setOpaque(false);
|
||||
leftPanel.add(returnButton);
|
||||
topPanel.add(leftPanel, BorderLayout.WEST);
|
||||
|
||||
this.add(topPanel, BorderLayout.NORTH);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
ImageIcon backgroundImage = new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg");
|
||||
g.drawImage(backgroundImage.getImage(), 0, 0, getWidth(), getHeight(), this);
|
||||
}
|
||||
|
||||
private void setupMainPanel() {
|
||||
JPanel mainPanel = new JPanel(new GridBagLayout());
|
||||
mainPanel.setOpaque(false);
|
||||
|
||||
// Section Musique
|
||||
JSlider musicSlider = new JSlider(0, 100, Options.MUSIC_MUTED ? 0 : Options.MUSIC_VOLUME);
|
||||
JPanel musicPanel = createSoundPanel("Musique", musicSlider, new MusicVolumeChangeListener(musicSlider), new MuteCheckBoxListener("Musique"));
|
||||
mainPanel.add(musicPanel, createGridBagConstraints(0, 0, 1));
|
||||
|
||||
// Section SFX
|
||||
JSlider sfxSlider = new JSlider(0, 100, Options.SOUNDS_MUTED ? 0 : Options.SOUNDS_VOLUME);
|
||||
JPanel sfxPanel = createSoundPanel("SFX", sfxSlider, new SoundsVolumeChangeListener(sfxSlider), new MuteCheckBoxListener("SFX"));
|
||||
mainPanel.add(sfxPanel, createGridBagConstraints(0, 1, 1));
|
||||
|
||||
// Section Auto Focus
|
||||
JPanel autoFocusPanel = createAutoFocusPanel();
|
||||
mainPanel.add(autoFocusPanel, createGridBagConstraints(0, 2, 1));
|
||||
|
||||
mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 3, 1));
|
||||
this.add(mainPanel, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
private JPanel createSoundPanel(String labelText, JSlider volumeSlider, ChangeListener sliderChangeListener, MuteCheckBoxListener muteCheckBoxListener) {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); // Utilisation de BoxLayout pour une disposition verticale
|
||||
panel.setOpaque(false);
|
||||
|
||||
// Titre de la section (ex: "Musique" ou "SFX")
|
||||
JLabel titleLabel = new JLabel(labelText);
|
||||
titleLabel.setFont(new Font("Roboto", Font.BOLD, 30));
|
||||
titleLabel.setAlignmentX(Component.CENTER_ALIGNMENT); // Alignement à gauche
|
||||
panel.add(titleLabel);
|
||||
panel.add(Box.createVerticalStrut(10)); // Espacement vertical
|
||||
|
||||
// Panneau pour le bouton "Couper le son"
|
||||
JPanel mutePanel = new JPanel();
|
||||
mutePanel.setLayout(new BoxLayout(mutePanel, BoxLayout.X_AXIS)); // Disposition horizontale pour inverser l'ordre
|
||||
mutePanel.setOpaque(false);
|
||||
|
||||
JLabel muteLabel = new JLabel("Couper le son");
|
||||
muteLabel.setFont(new Font("Roboto", Font.PLAIN, 18)); // Augmentation de la taille du texte
|
||||
muteLabel.setAlignmentX(Component.LEFT_ALIGNMENT); // Aligner le texte à gauche
|
||||
mutePanel.add(muteLabel);
|
||||
|
||||
// Ajouter la checkbox après le texte pour qu'elle soit à droite
|
||||
JCheckBox muteCheckBox = new JCheckBox();
|
||||
muteCheckBox.setFont(new Font("Roboto", Font.PLAIN, 18)); // Optionnel, si le style du texte dans la case est souhaité
|
||||
muteCheckBox.setFocusPainted(false);
|
||||
muteCheckBox.setOpaque(false);
|
||||
muteCheckBox.setBorderPainted(false);
|
||||
muteCheckBox.setMargin(new Insets(5, 5, 5, 5));
|
||||
muteCheckBox.setSelected(!("Musique".equals(labelText) ? Options.MUSIC_MUTED : Options.SOUNDS_MUTED));
|
||||
muteCheckBox.addActionListener(muteCheckBoxListener);
|
||||
|
||||
mutePanel.add(Box.createHorizontalGlue()); // Espace flexible entre le texte et la checkbox
|
||||
mutePanel.add(muteCheckBox);
|
||||
|
||||
panel.add(mutePanel);
|
||||
panel.add(Box.createVerticalStrut(10)); // Espace vertical
|
||||
|
||||
// Panneau pour le slider "Gérer le son"
|
||||
JPanel volumePanel = new JPanel(new BorderLayout());
|
||||
volumePanel.setOpaque(false);
|
||||
JLabel manageVolumeLabel = new JLabel("Gérer le son");
|
||||
manageVolumeLabel.setFont(new Font("Roboto", Font.PLAIN, 18));
|
||||
volumePanel.add(manageVolumeLabel, BorderLayout.NORTH);
|
||||
|
||||
// Création et ajout du slider
|
||||
volumeSlider.setPreferredSize(new Dimension(200, 50));
|
||||
volumeSlider.setMajorTickSpacing(50);
|
||||
volumeSlider.setPaintTicks(true);
|
||||
volumeSlider.setPaintLabels(true);
|
||||
volumeSlider.setFont(new Font("Roboto", Font.PLAIN, 16));
|
||||
volumeSlider.addChangeListener(sliderChangeListener);
|
||||
volumePanel.add(createSliderPanel(volumeSlider), BorderLayout.CENTER);
|
||||
|
||||
panel.add(volumePanel);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
private JPanel createAutoFocusPanel() {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); // Disposition verticale
|
||||
panel.setOpaque(false); // Assurer que le fond est transparent
|
||||
|
||||
// Titre de la section
|
||||
JLabel titleLabel = new JLabel("Focus Automatique");
|
||||
titleLabel.setFont(new Font("Roboto", Font.BOLD, 30));
|
||||
titleLabel.setAlignmentX(Component.CENTER_ALIGNMENT); // Aligner le texte au centre
|
||||
panel.add(titleLabel);
|
||||
panel.add(Box.createVerticalStrut(10)); // Espacement vertical
|
||||
|
||||
// Panneau contenant texte et case à cocher sur la même ligne
|
||||
JPanel checkBoxPanel = new JPanel();
|
||||
checkBoxPanel.setLayout(new BoxLayout(checkBoxPanel, BoxLayout.X_AXIS)); // Disposition horizontale
|
||||
checkBoxPanel.setOpaque(false); // Assurer que le fond est transparent
|
||||
|
||||
// Texte explicatif avant la case à cocher
|
||||
JLabel descriptionLabel = new JLabel("Gestion du focus automatique (nécessite une bonne carte graphique) :");
|
||||
descriptionLabel.setFont(new Font("Roboto", Font.PLAIN, 18));
|
||||
descriptionLabel.setAlignmentX(Component.LEFT_ALIGNMENT); // Aligner à gauche
|
||||
checkBoxPanel.add(descriptionLabel); // Ajouter le texte dans le panneau
|
||||
|
||||
// Ajouter un espace flexible entre le texte et la case à cocher
|
||||
checkBoxPanel.add(Box.createHorizontalGlue()); // Cela pousse la case à cocher vers la droite
|
||||
|
||||
// Case à cocher
|
||||
JCheckBox autoFocusCheckBox = new JCheckBox();
|
||||
autoFocusCheckBox.setFont(new Font("Roboto", Font.PLAIN, 18));
|
||||
autoFocusCheckBox.setFocusPainted(false);
|
||||
autoFocusCheckBox.setOpaque(false);
|
||||
autoFocusCheckBox.setBorderPainted(false);
|
||||
autoFocusCheckBox.setMargin(new Insets(5, 5, 5, 5));
|
||||
autoFocusCheckBox.setSelected(Options.AUTO_FOCUS); // État initial selon la valeur actuelle de AUTO_FOCUS
|
||||
autoFocusCheckBox.addActionListener(e -> {
|
||||
Options.AUTO_FOCUS = autoFocusCheckBox.isSelected(); // Mettre à jour la variable auto-focus
|
||||
});
|
||||
|
||||
checkBoxPanel.add(autoFocusCheckBox); // Ajouter la case à cocher
|
||||
|
||||
// Ajouter le panneau contenant texte + case à cocher
|
||||
panel.add(checkBoxPanel);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
|
||||
private JPanel createSliderPanel(JSlider volumeSlider) {
|
||||
JPanel sliderPanel = new JPanel(new BorderLayout());
|
||||
sliderPanel.setOpaque(false);
|
||||
|
||||
JLabel lowLabel = new JLabel("Faible");
|
||||
lowLabel.setFont(new Font("Roboto", Font.PLAIN, 18));
|
||||
sliderPanel.add(lowLabel, BorderLayout.WEST);
|
||||
|
||||
sliderPanel.add(volumeSlider, BorderLayout.CENTER);
|
||||
|
||||
JLabel highLabel = new JLabel("Élevé");
|
||||
highLabel.setFont(new Font("Roboto", Font.PLAIN, 18));
|
||||
sliderPanel.add(highLabel, BorderLayout.EAST);
|
||||
|
||||
return sliderPanel;
|
||||
}
|
||||
|
||||
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(20, 30, 20, 30);
|
||||
return gbc;
|
||||
}
|
||||
|
||||
|
||||
private JButton createReturnButtonWithIcon() {
|
||||
ImageIcon originalIcon = new ImageIcon(Images.EXIT_ICON.getImagePath());
|
||||
|
||||
// Redimensionner l'image à la taille du bouton
|
||||
Image scaledImage = originalIcon.getImage().getScaledInstance(50, 50, Image.SCALE_SMOOTH);
|
||||
ImageIcon resizedIcon = new ImageIcon(scaledImage);
|
||||
|
||||
JButton returnButton = new JButton(resizedIcon);
|
||||
returnButton.setPreferredSize(new Dimension(50, 50)); // Ajuster la taille du bouton selon l'icône
|
||||
returnButton.setContentAreaFilled(false); // Bouton transparent
|
||||
returnButton.setBorderPainted(false); // Pas de bordure
|
||||
returnButton.setFocusPainted(false); // Pas de focus
|
||||
returnButton.addActionListener(new CloseButtonListener(mainMenu, settingsFrame));
|
||||
|
||||
return returnButton;
|
||||
}
|
||||
}
|
25
src/fr/monkhanny/dorfromantik/gui/Step.java
Normal file
25
src/fr/monkhanny/dorfromantik/gui/Step.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
public class Step {
|
||||
private String title;
|
||||
private String text;
|
||||
private String imagePath;
|
||||
|
||||
public Step(String title, String text, String imagePath) {
|
||||
this.title = title;
|
||||
this.text = text;
|
||||
this.imagePath = imagePath;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public String getImagePath() {
|
||||
return imagePath;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
}
|
180
src/fr/monkhanny/dorfromantik/gui/TutorialPanel.java
Normal file
180
src/fr/monkhanny/dorfromantik/gui/TutorialPanel.java
Normal file
@@ -0,0 +1,180 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.components.Title;
|
||||
import fr.monkhanny.dorfromantik.listeners.CloseButtonListener;
|
||||
import fr.monkhanny.dorfromantik.listeners.TutorialButtonHoverListener;
|
||||
import fr.monkhanny.dorfromantik.enums.Images;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
|
||||
public class TutorialPanel extends JPanel {
|
||||
|
||||
private List<Step> steps;
|
||||
private int currentStepIndex;
|
||||
private Title title;
|
||||
private JLabel stepText;
|
||||
private JLabel stepImage;
|
||||
private JButton nextButton;
|
||||
private JButton prevButton;
|
||||
private MainMenu mainMenu;
|
||||
private JFrame tutorialFrame;
|
||||
|
||||
public TutorialPanel(List<Step> steps, MainMenu mainMenu, JFrame tutorialFrame) {
|
||||
this.steps = steps;
|
||||
this.currentStepIndex = 0;
|
||||
this.mainMenu = mainMenu;
|
||||
this.tutorialFrame = tutorialFrame;
|
||||
|
||||
// Utiliser BorderLayout pour la disposition principale
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
// Création du titre centré en haut
|
||||
title = new Title("Comment jouer ?", 70f, Color.WHITE);
|
||||
title.setHorizontalAlignment(JLabel.CENTER);
|
||||
title.setOpaque(false);
|
||||
|
||||
// Panneau contenant le titre et le bouton de retour
|
||||
JPanel northPanel = new JPanel(new BorderLayout());
|
||||
northPanel.setOpaque(false);
|
||||
northPanel.add(title, BorderLayout.CENTER);
|
||||
|
||||
// Ajouter l'icône de retour à droite du panneau nord
|
||||
JButton returnButton = createReturnButtonWithIcon();
|
||||
JPanel topRightPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
topRightPanel.setOpaque(false);
|
||||
topRightPanel.add(returnButton);
|
||||
northPanel.add(topRightPanel, BorderLayout.WEST);
|
||||
|
||||
add(northPanel, BorderLayout.NORTH);
|
||||
|
||||
// Conteneur principal pour les étapes, centré
|
||||
JPanel centerPanel = new JPanel();
|
||||
centerPanel.setLayout(new GridBagLayout());
|
||||
centerPanel.setOpaque(false); // Rendre le conteneur transparent
|
||||
|
||||
// Utiliser GridBagConstraints pour centrer le contenu verticalement
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 0;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.insets = new Insets(10, 0, 10, 0);
|
||||
|
||||
// Conteneur pour le texte et l'image
|
||||
JPanel stepContainer = new JPanel();
|
||||
stepContainer.setLayout(new BoxLayout(stepContainer, BoxLayout.Y_AXIS));
|
||||
stepContainer.setOpaque(false); // Transparent
|
||||
|
||||
stepText = new JLabel();
|
||||
stepText.setFont(new Font("Arial", Font.BOLD, 28));
|
||||
stepText.setForeground(Color.WHITE);
|
||||
stepText.setAlignmentX(Component.CENTER_ALIGNMENT); // Centrer le texte horizontalement
|
||||
|
||||
stepImage = new JLabel();
|
||||
stepImage.setAlignmentX(Component.CENTER_ALIGNMENT); // Centrer l'image horizontalement
|
||||
|
||||
// Ajouter les composants au conteneur d'étapes
|
||||
stepContainer.add(stepText);
|
||||
stepContainer.add(Box.createVerticalStrut(10)); // Espace entre texte et image
|
||||
stepContainer.add(stepImage);
|
||||
|
||||
// Ajouter le conteneur d'étapes au centre du panel
|
||||
centerPanel.add(stepContainer, gbc);
|
||||
add(centerPanel, BorderLayout.CENTER);
|
||||
|
||||
// Panneau pour les boutons de navigation
|
||||
JPanel buttonPanel = new JPanel();
|
||||
buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); // Centrer les boutons
|
||||
buttonPanel.setOpaque(false); // Transparent
|
||||
|
||||
prevButton = new JButton("Précédent");
|
||||
nextButton = new JButton("Suivant");
|
||||
|
||||
// Personnalisation des boutons
|
||||
styleButton(prevButton);
|
||||
styleButton(nextButton);
|
||||
|
||||
prevButton.addActionListener(e -> showPreviousStep());
|
||||
nextButton.addActionListener(e -> showNextStep());
|
||||
|
||||
buttonPanel.add(prevButton);
|
||||
buttonPanel.add(nextButton);
|
||||
|
||||
// Ajouter le panneau des boutons en bas
|
||||
add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
// Affichage initial de l'étape
|
||||
updateStepDisplay();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g); // Appel à super pour s'assurer que le panneau est dessiné
|
||||
|
||||
// Dessin de l'image de fond pour couvrir tout le panneau
|
||||
ImageIcon backgroundImage = new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg");
|
||||
Image image = backgroundImage.getImage();
|
||||
g.drawImage(image, 0, 0, getWidth(), getHeight(), this); // Dessiner l'image pour couvrir tout le panneau
|
||||
}
|
||||
|
||||
private void updateStepDisplay() {
|
||||
Step currentStep = steps.get(currentStepIndex);
|
||||
stepText.setText(currentStep.getText());
|
||||
stepImage.setIcon(new ImageIcon(currentStep.getImagePath()));
|
||||
stepImage.setHorizontalAlignment(JLabel.CENTER);
|
||||
stepImage.setVerticalAlignment(JLabel.CENTER);
|
||||
prevButton.setEnabled(currentStepIndex > 0);
|
||||
nextButton.setEnabled(currentStepIndex < steps.size() - 1);
|
||||
}
|
||||
|
||||
private void styleButton(JButton button) {
|
||||
// Police et taille
|
||||
button.setFont(new Font("Arial", Font.BOLD, 18));
|
||||
button.setForeground(Color.WHITE);
|
||||
|
||||
// Taille et forme des boutons
|
||||
button.setPreferredSize(new Dimension(150, 50)); // Ajuster la taille des boutons
|
||||
button.setBackground(new Color(34, 34, 34)); // Couleur de fond sombre
|
||||
button.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2)); // Bordure blanche
|
||||
|
||||
// Effet au survol
|
||||
button.setRolloverEnabled(true);
|
||||
button.setContentAreaFilled(true);
|
||||
button.setFocusPainted(false); // Pas de focus visible
|
||||
|
||||
// Ajout de l'effet de survol
|
||||
button.addMouseListener(new TutorialButtonHoverListener(button, new Color(60,60,60), new Color(34,34,34)));
|
||||
}
|
||||
|
||||
private void showPreviousStep() {
|
||||
if (currentStepIndex > 0) {
|
||||
currentStepIndex--;
|
||||
updateStepDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
private void showNextStep() {
|
||||
if (currentStepIndex < steps.size() - 1) {
|
||||
currentStepIndex++;
|
||||
updateStepDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
private JButton createReturnButtonWithIcon() {
|
||||
ImageIcon originalIcon = new ImageIcon(Images.EXIT_ICON.getImagePath());
|
||||
|
||||
// Redimensionnement de l'image à la taille du bouton
|
||||
Image scaledImage = originalIcon.getImage().getScaledInstance(50, 50, Image.SCALE_SMOOTH);
|
||||
ImageIcon resizedIcon = new ImageIcon(scaledImage);
|
||||
|
||||
JButton returnButton = new JButton(resizedIcon);
|
||||
returnButton.setPreferredSize(new Dimension(50, 50)); // Ajuste la taille du bouton selon l'icône
|
||||
returnButton.setContentAreaFilled(false); // Bouton transparent
|
||||
returnButton.setBorderPainted(false); // Pas de bordure
|
||||
returnButton.setFocusPainted(false); // Pas de focus
|
||||
returnButton.addActionListener(new CloseButtonListener(mainMenu, tutorialFrame));
|
||||
|
||||
return returnButton;
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package fr.monkhanny.dorfromantik.listeners;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class CloseButtonListener implements ActionListener {
|
||||
private MainMenu mainMenu;
|
||||
private JFrame settingsFrame;
|
||||
|
||||
public CloseButtonListener(MainMenu mainMenu, JFrame settingsFrame) {
|
||||
this.mainMenu = mainMenu;
|
||||
this.settingsFrame = settingsFrame;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// Réafficher la fenêtre du menu principal
|
||||
mainMenu.setVisible(true);
|
||||
settingsFrame.setVisible(false); // Fermer la fenêtre des paramètres
|
||||
}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
package fr.monkhanny.dorfromantik.listeners;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import javax.swing.*;
|
||||
|
||||
public class CloseWindowListener extends WindowAdapter {
|
||||
|
||||
private MainMenu mainMenu;
|
||||
private JFrame frame;
|
||||
|
||||
public CloseWindowListener(MainMenu mainMenu, JFrame frame) {
|
||||
this.mainMenu = mainMenu;
|
||||
this.frame = frame;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
// Réafficher la fenêtre du menu principal
|
||||
mainMenu.setVisible(true);
|
||||
frame.setVisible(false);
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package fr.monkhanny.dorfromantik.listeners;
|
||||
|
||||
import fr.monkhanny.dorfromantik.game.Board;
|
||||
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
public class GameArrowKeyListener extends KeyAdapter {
|
||||
private Board board;
|
||||
|
||||
public GameArrowKeyListener(Board board) {
|
||||
this.board = board;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
switch (e.getKeyCode()) {
|
||||
case KeyEvent.VK_UP:
|
||||
board.moveBoard(0, -10); // Déplacer vers le haut
|
||||
break;
|
||||
case KeyEvent.VK_DOWN:
|
||||
board.moveBoard(0, 10); // Déplacer vers le bas
|
||||
break;
|
||||
case KeyEvent.VK_LEFT:
|
||||
board.moveBoard(-10, 0); // Déplacer vers la gauche
|
||||
break;
|
||||
case KeyEvent.VK_RIGHT:
|
||||
board.moveBoard(10, 0); // Déplacer vers la droite
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package fr.monkhanny.dorfromantik.listeners;
|
||||
|
||||
import fr.monkhanny.dorfromantik.game.Board;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class GameMouseClickListener extends MouseAdapter {
|
||||
private Board board;
|
||||
|
||||
public GameMouseClickListener(Board board) {
|
||||
this.board = board;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
board.handleMouseClick(e);
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package fr.monkhanny.dorfromantik.listeners;
|
||||
|
||||
import fr.monkhanny.dorfromantik.game.Board;
|
||||
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
|
||||
public class GameMouseWheelListener implements MouseWheelListener {
|
||||
private Board board;
|
||||
|
||||
// Constructeur de la classe
|
||||
public GameMouseWheelListener(Board board) {
|
||||
this.board = board;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseWheelMoved(MouseWheelEvent e) {
|
||||
if (board.getNextTile() != null) {
|
||||
boolean clockwise = e.getWheelRotation() < 0; // Si la molette va vers le haut, rotation horaire
|
||||
board.getNextTile().rotate(clockwise); // Applique la rotation sur la tuile
|
||||
board.repaint();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package fr.monkhanny.dorfromantik.listeners;
|
||||
|
||||
import fr.monkhanny.dorfromantik.game.Board;
|
||||
|
||||
public class GameSpaceKeyListener extends java.awt.event.KeyAdapter {
|
||||
private Board board;
|
||||
|
||||
public GameSpaceKeyListener(Board board) {
|
||||
this.board = board;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(java.awt.event.KeyEvent e) {
|
||||
if (e.getKeyCode() == java.awt.event.KeyEvent.VK_SPACE) {
|
||||
board.handleSpaceKeyPress(); // Appeler la méthode dans Board pour dézoomer
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
package fr.monkhanny.dorfromantik.listeners;
|
||||
|
||||
import fr.monkhanny.dorfromantik.game.Board;
|
||||
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
|
||||
public class GameZoomListener extends MouseAdapter {
|
||||
private Board board;
|
||||
|
||||
public GameZoomListener(Board board) {
|
||||
this.board = board;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseWheelMoved(MouseWheelEvent e) {
|
||||
// Vérifier si la touche Ctrl est enfoncée et la direction de la molette
|
||||
if (e.isControlDown()) {
|
||||
// Si la molette tourne vers le bas (zoom arrière)
|
||||
if (e.getWheelRotation() < 0) {
|
||||
board.zoomIn(); // Zoom avant
|
||||
} else {
|
||||
board.zoomOut(); // Zoom arrière
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package fr.monkhanny.dorfromantik.listeners;
|
||||
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
import fr.monkhanny.dorfromantik.utils.MusicPlayer;
|
||||
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.JSlider;
|
||||
|
||||
public class MusicVolumeChangeListener implements ChangeListener {
|
||||
private JSlider slider;
|
||||
|
||||
public MusicVolumeChangeListener(JSlider slider) {
|
||||
this.slider = slider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
// Récupérer la valeur du slider spécifique
|
||||
Options.MUSIC_VOLUME = slider.getValue();
|
||||
MusicPlayer.setVolume(MusicPlayer.getMusicClip(), Options.MUSIC_VOLUME);
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package fr.monkhanny.dorfromantik.listeners;
|
||||
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
import fr.monkhanny.dorfromantik.utils.MusicPlayer;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class MuteCheckBoxListener implements ActionListener {
|
||||
private String label;
|
||||
|
||||
public MuteCheckBoxListener(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JCheckBox checkBox = (JCheckBox) e.getSource();
|
||||
|
||||
if ("Musique".equals(label)) {
|
||||
Options.MUSIC_MUTED = !checkBox.isSelected();
|
||||
if (Options.MUSIC_MUTED) {
|
||||
MusicPlayer.pauseMusic();
|
||||
} else {
|
||||
MusicPlayer.playMusic();
|
||||
}
|
||||
} else if ("SFX".equals(label)) {
|
||||
Options.SOUNDS_MUTED = !checkBox.isSelected();
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user