resolution bug score dans le mode 1 mais bug dans le mode 2,3 et 4
This commit is contained in:
BIN
TestV1/src/fr/.DS_Store
vendored
Normal file
BIN
TestV1/src/fr/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
TestV1/src/fr/monkhanny/.DS_Store
vendored
Normal file
BIN
TestV1/src/fr/monkhanny/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
TestV1/src/fr/monkhanny/dorfromantik/.DS_Store
vendored
Normal file
BIN
TestV1/src/fr/monkhanny/dorfromantik/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -1,14 +1,16 @@
|
||||
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.SettingsWindowListener;
|
||||
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;
|
||||
|
||||
@@ -20,37 +22,89 @@ import javax.swing.JFrame;
|
||||
* @see MainMenuResizeController
|
||||
*/
|
||||
public class Main {
|
||||
/**
|
||||
* Méthode principale du jeu
|
||||
* @param args Tableau de String contenant les arguments passé en paramètre au programme
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// Créer la fenêtre des paramètres
|
||||
JFrame settingsFrame = new JFrame("Paramètres");
|
||||
|
||||
// Créer la fenêtre du tutoriel
|
||||
JFrame howToPlayFrame = new JFrame("Comment jouer ?");
|
||||
private static JFrame gameModeFrame;
|
||||
private static JFrame gameFrame;
|
||||
private static JFrame settingsFrame;
|
||||
private static JFrame howToPlayFrame;
|
||||
private static JFrame rewardsFrame;
|
||||
|
||||
// Menu principal
|
||||
MusicPlayer.loadMusic(Musics.MAIN_MENU_MUSIC);
|
||||
MusicPlayer.playMusic();
|
||||
MainMenu mainMenu = new MainMenu();
|
||||
MainMenuResizeController MainMenuResizeController = new MainMenuResizeController(mainMenu);
|
||||
MainMenuButtonController MainMenuButtonController = new MainMenuButtonController(mainMenu,settingsFrame,howToPlayFrame);
|
||||
// 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
|
||||
}
|
||||
|
||||
// Fenêtre des paramètres
|
||||
SettingsWindowListener windowListener = new SettingsWindowListener(mainMenu, settingsFrame);
|
||||
SettingsPanel settingsPanel = new SettingsPanel(mainMenu, settingsFrame);
|
||||
settingsFrame.addWindowListener(windowListener);
|
||||
settingsFrame.add(settingsPanel);
|
||||
settingsFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
// 2. Réinitialiser les variables globales ou statiques si nécessaire
|
||||
Options.mainMenu = new MainMenu(); // Réinitialiser le menu principal
|
||||
|
||||
// Fenêtre du tutoriel
|
||||
TutorialController tutorialController = new TutorialController();
|
||||
howToPlayFrame.addWindowListener(windowListener);
|
||||
howToPlayFrame.add(tutorialController.getTutorialPanel());
|
||||
howToPlayFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
// 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.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();
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package fr.monkhanny.dorfromantik;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
|
||||
public class Options {
|
||||
|
||||
@@ -51,4 +52,18 @@ public class Options {
|
||||
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;
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -1,10 +1,7 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
import fr.monkhanny.dorfromantik.gui.SettingsPanel;
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
import fr.monkhanny.dorfromantik.gui.ButtonPanel;
|
||||
import fr.monkhanny.dorfromantik.listeners.SettingsWindowListener;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
@@ -12,46 +9,68 @@ 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) {
|
||||
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
|
||||
// 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);
|
||||
|
||||
// Créer la fenêtre des paramètres
|
||||
// Paramètrage de la fenêtre des paramètres
|
||||
this.settingsFrame = settingsFrame;
|
||||
this.settingsFrame.setLocationRelativeTo(null);
|
||||
this.settingsFrame.setVisible(false);
|
||||
configureFrame(this.settingsFrame);
|
||||
|
||||
// Créer la fenêtre du tutoriel
|
||||
// Paramètrage de la fenêtre du tutoriel
|
||||
this.howToPlayFrame = howToPlayFrame;
|
||||
this.howToPlayFrame.setLocationRelativeTo(null);
|
||||
this.howToPlayFrame.setVisible(false);
|
||||
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 "Nouvelle partie":
|
||||
case "Jouer":
|
||||
startNewGame();
|
||||
break;
|
||||
case "Continuer une partie":
|
||||
continueGame();
|
||||
case "Récompenses":
|
||||
openRecompense();
|
||||
break;
|
||||
case "Comment jouer ?":
|
||||
showHowToPlay();
|
||||
@@ -68,29 +87,21 @@ public class MainMenuButtonController implements ActionListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void startNewGame() {
|
||||
System.out.println("Démarrer une nouvelle partie...");
|
||||
// Logic to start a new game
|
||||
public void startNewGame() {
|
||||
adjustFrameDisplay(this.gameModeFrame);
|
||||
this.mainMenu.setVisible(false);
|
||||
this.gameModeFrame.setVisible(true);
|
||||
}
|
||||
|
||||
private void continueGame() {
|
||||
System.out.println("Continuer une partie...");
|
||||
// Logic to continue the game
|
||||
private void openRecompense() {
|
||||
adjustFrameDisplay(this.rewardsFrame);
|
||||
this.mainMenu.setVisible(false);
|
||||
this.rewardsFrame.setVisible(true);
|
||||
}
|
||||
|
||||
public void showHowToPlay() {
|
||||
// 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();
|
||||
|
||||
// Ajuster la fenêtre des paramètres pour qu'elle ait la même taille et position
|
||||
this.howToPlayFrame.setSize(mainMenuSize);
|
||||
this.howToPlayFrame.setLocation(mainMenuLocation);
|
||||
|
||||
// Cacher la fenêtre du menu principal
|
||||
adjustFrameDisplay(this.howToPlayFrame);
|
||||
this.mainMenu.setVisible(false);
|
||||
|
||||
// Afficher la fenêtre des paramètres
|
||||
this.howToPlayFrame.setVisible(true);
|
||||
}
|
||||
|
||||
@@ -100,18 +111,22 @@ public class MainMenuButtonController implements ActionListener {
|
||||
}
|
||||
|
||||
private void openSettings() {
|
||||
// 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();
|
||||
|
||||
// Ajuster la fenêtre des paramètres pour qu'elle ait la même taille et position
|
||||
this.settingsFrame.setSize(mainMenuSize);
|
||||
this.settingsFrame.setLocation(mainMenuLocation);
|
||||
|
||||
// Cacher la fenêtre du menu principal
|
||||
adjustFrameDisplay(this.settingsFrame);
|
||||
this.mainMenu.setVisible(false);
|
||||
|
||||
// Afficher la fenêtre des paramètres
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -4,8 +4,6 @@ import fr.monkhanny.dorfromantik.gui.ButtonPanel;
|
||||
import fr.monkhanny.dorfromantik.gui.ButtonHoverAnimator;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class MainMenuMouseController {
|
||||
|
||||
|
@@ -6,7 +6,6 @@ import fr.monkhanny.dorfromantik.gui.ButtonHoverAnimator;
|
||||
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import javax.swing.JButton;
|
||||
|
||||
public class MainMenuResizeHandler extends ComponentAdapter {
|
||||
|
||||
|
@@ -3,6 +3,7 @@ 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;
|
||||
@@ -11,14 +12,20 @@ import java.util.List;
|
||||
public class TutorialController {
|
||||
private TutorialPanel tutorialPanel;
|
||||
|
||||
public TutorialController() {
|
||||
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);
|
||||
tutorialPanel = new TutorialPanel(steps, this.mainMenu, this.tutorialFrame);
|
||||
}
|
||||
|
||||
public JPanel getTutorialPanel() {
|
||||
|
@@ -1,9 +1,12 @@
|
||||
package fr.monkhanny.dorfromantik.enums;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontFormatException;
|
||||
|
||||
public enum Fonts {
|
||||
TITLE, BUTTON;
|
||||
TITLE, BUTTON, SCORE;
|
||||
|
||||
public String getFontPath() {
|
||||
switch (this) {
|
||||
@@ -11,8 +14,29 @@ public enum Fonts {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
BIN
TestV1/src/fr/monkhanny/dorfromantik/game/.DS_Store
vendored
Normal file
BIN
TestV1/src/fr/monkhanny/dorfromantik/game/.DS_Store
vendored
Normal file
Binary file not shown.
24
TestV1/src/fr/monkhanny/dorfromantik/game/BiomeGroup.java
Normal file
24
TestV1/src/fr/monkhanny/dorfromantik/game/BiomeGroup.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package fr.monkhanny.dorfromantik.game;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Représente un groupe de poches pour un biome spécifique.
|
||||
*/
|
||||
public class BiomeGroup {
|
||||
private final List<Pocket> pockets;
|
||||
|
||||
public BiomeGroup() {
|
||||
this.pockets = new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<Pocket> getPockets() {
|
||||
return pockets;
|
||||
}
|
||||
|
||||
public void addPocket(Pocket pocket) {
|
||||
pockets.add(pocket);
|
||||
}
|
||||
}
|
||||
|
505
TestV1/src/fr/monkhanny/dorfromantik/game/Board.java
Normal file
505
TestV1/src/fr/monkhanny/dorfromantik/game/Board.java
Normal file
File diff suppressed because it is too large
Load Diff
110
TestV1/src/fr/monkhanny/dorfromantik/game/Cell.java
Normal file
110
TestV1/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
TestV1/src/fr/monkhanny/dorfromantik/game/Game.java
Normal file
27
TestV1/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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
226
TestV1/src/fr/monkhanny/dorfromantik/game/GameOver.java
Normal file
226
TestV1/src/fr/monkhanny/dorfromantik/game/GameOver.java
Normal file
@@ -0,0 +1,226 @@
|
||||
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
|
||||
funnyQuote = "Vous n'êtes que " + totalPlayers + " à avoir joué à cette partie personalisée...";
|
||||
// Display the funny quote directly
|
||||
JLabel quoteLabel = new JLabel(funnyQuote);
|
||||
quoteLabel.setFont(Fonts.SCORE.getFont(24));
|
||||
quoteLabel.setForeground(Color.WHITE);
|
||||
quoteLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
mainPanel.add(quoteLabel);
|
||||
} else {
|
||||
// Calculate which group the player's score falls into
|
||||
for (int i = 0; i < totalPlayers; i++) {
|
||||
if (allScores.get(i) <= finalScore) {
|
||||
playerGroup = i / groupSize + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Group information
|
||||
JPanel groupPanel = new JPanel();
|
||||
groupPanel.setOpaque(false);
|
||||
groupPanel.setLayout(new BoxLayout(groupPanel, BoxLayout.Y_AXIS));
|
||||
|
||||
JLabel groupTitleLabel = new JLabel("Vous êtes dans le groupe " + playerGroup + "/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;
|
||||
}
|
||||
|
||||
}
|
33
TestV1/src/fr/monkhanny/dorfromantik/game/Pocket.java
Normal file
33
TestV1/src/fr/monkhanny/dorfromantik/game/Pocket.java
Normal file
@@ -0,0 +1,33 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* Représente une poche de tuiles connectées pour un terrain donné.
|
||||
*/
|
||||
public class Pocket {
|
||||
private final Biome biome;
|
||||
private final Set<Tile> tiles;
|
||||
|
||||
public Pocket(Biome biome) {
|
||||
this.biome = biome;
|
||||
this.tiles = new HashSet<>();
|
||||
}
|
||||
|
||||
public Biome getBiome() {
|
||||
return biome;
|
||||
}
|
||||
|
||||
public Set<Tile> getTiles() {
|
||||
return tiles;
|
||||
}
|
||||
|
||||
public void addTile(Tile tile) {
|
||||
tiles.add(tile);
|
||||
}
|
||||
}
|
47
TestV1/src/fr/monkhanny/dorfromantik/game/ScoreManager.java
Normal file
47
TestV1/src/fr/monkhanny/dorfromantik/game/ScoreManager.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package fr.monkhanny.dorfromantik.game;
|
||||
|
||||
import fr.monkhanny.dorfromantik.enums.Biome;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Gère le calcul du score basé sur les poches de terrains connectées.
|
||||
*/
|
||||
public class ScoreManager {
|
||||
private final Map<Biome, BiomeGroup> biomeGroups;
|
||||
private int currentScore;
|
||||
|
||||
public ScoreManager(Map<Biome, BiomeGroup> biomeGroups) {
|
||||
this.biomeGroups = biomeGroups;
|
||||
this.currentScore = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour le score en recalculant toutes les poches.
|
||||
*/
|
||||
public void updateScore() {
|
||||
currentScore = 0;
|
||||
|
||||
for (BiomeGroup group : biomeGroups.values()) {
|
||||
Set<Pocket> uniquePockets = new HashSet<>(group.getPockets());
|
||||
for (Pocket pocket : uniquePockets) {
|
||||
int size = pocket.getTiles().size();
|
||||
System.out.println("Calculating score for pocket of biome " + pocket.getBiome() +
|
||||
": size=" + size + ", points=" + (size * size));
|
||||
currentScore += size * size;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Updated score: " + currentScore);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public int getCurrentScore() {
|
||||
return currentScore;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
254
TestV1/src/fr/monkhanny/dorfromantik/game/Tile.java
Normal file
254
TestV1/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();
|
||||
}
|
||||
}
|
@@ -1,11 +1,10 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
import fr.monkhanny.dorfromantik.controller.ButtonHoverAnimationListener;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class ButtonHoverAnimator {
|
||||
|
||||
@@ -13,24 +12,23 @@ public class ButtonHoverAnimator {
|
||||
private final Color originalColor;
|
||||
private static Font originalFont;
|
||||
private Timer animationTimer;
|
||||
private float currentScale = 1.0f;
|
||||
|
||||
|
||||
public ButtonHoverAnimator(JButton button) {
|
||||
this.button = button;
|
||||
this.originalColor = button.getForeground();
|
||||
this.originalFont = button.getFont();
|
||||
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);
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@ import fr.monkhanny.dorfromantik.components.Button;
|
||||
import fr.monkhanny.dorfromantik.controller.MainMenuMouseController;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -28,8 +27,8 @@ public class ButtonPanel extends JPanel {
|
||||
this.add(Box.createVerticalGlue());
|
||||
|
||||
// Créer les boutons avec un style personnalisé
|
||||
newGameButton = Button.createCustomTextButton("Nouvelle partie", fontSize);
|
||||
continueGameButton = Button.createCustomTextButton("Continuer une partie", fontSize);
|
||||
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);
|
||||
@@ -48,6 +47,7 @@ public class ButtonPanel extends JPanel {
|
||||
// Espacement extensible pour maintenir les icônes en bas
|
||||
this.add(Box.createVerticalGlue());
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
MainMenuMouseController gestionSouris = new MainMenuMouseController(this);
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,128 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
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) {
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
// Add background image
|
||||
JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg"));
|
||||
background.setLayout(new GridBagLayout());
|
||||
this.setLayout(new BorderLayout());
|
||||
this.add(background);
|
||||
|
||||
// Main content panel
|
||||
JPanel mainPanel = createMainPanel();
|
||||
background.add(mainPanel);
|
||||
|
||||
// Title
|
||||
titleLabel = new JLabel("Choisissez un mode de jeu", JLabel.CENTER);
|
||||
titleLabel.setFont(new Font("Arial", Font.BOLD, 40));
|
||||
titleLabel.setForeground(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 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
TestV1/src/fr/monkhanny/dorfromantik/gui/Leaderboard.java
Normal file
12
TestV1/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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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();
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -8,13 +8,14 @@ import fr.monkhanny.dorfromantik.Options;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
|
||||
|
||||
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
|
||||
@@ -39,10 +40,27 @@ public class MainMenu extends JFrame {
|
||||
this.titleLabel = new Title("Dorfromantik", Options.BASE_TITLE_FONT_SIZE);
|
||||
background.add(titleLabel, BorderLayout.NORTH);
|
||||
|
||||
// Panneau des boutons avec style personnalisé
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
34
TestV1/src/fr/monkhanny/dorfromantik/gui/Reward.java
Normal file
34
TestV1/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;
|
||||
}
|
||||
}
|
185
TestV1/src/fr/monkhanny/dorfromantik/gui/RewardsPanel.java
Normal file
185
TestV1/src/fr/monkhanny/dorfromantik/gui/RewardsPanel.java
Normal file
@@ -0,0 +1,185 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.utils.Database;
|
||||
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;
|
||||
|
||||
public RewardsPanel() {
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
// Ajouter le fond d'écran
|
||||
JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg"));
|
||||
background.setLayout(new GridBagLayout());
|
||||
this.setLayout(new BorderLayout());
|
||||
this.add(background);
|
||||
|
||||
// Titre du panneau
|
||||
JPanel titlePanel = createTitlePanel();
|
||||
background.add(titlePanel, createGridBagConstraints(0, 0, 1));
|
||||
|
||||
// Panel principal
|
||||
JPanel mainPanel = createMainPanel();
|
||||
background.add(mainPanel, createGridBagConstraints(0, 1, 1));
|
||||
|
||||
// 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); // Taille minimale pour éviter la réduction
|
||||
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));
|
||||
fetchButton.addActionListener(e -> {
|
||||
String username = usernameField.getText().trim();
|
||||
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
|
||||
updateRewardsPanel(rewards);
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(this, "Error fetching rewards: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Ajouter le bouton en bas
|
||||
JPanel buttonPanel = new JPanel();
|
||||
buttonPanel.setOpaque(false);
|
||||
buttonPanel.add(fetchButton);
|
||||
mainPanel.add(buttonPanel, createGridBagConstraints(0, 2, 1));
|
||||
}
|
||||
|
||||
private JPanel createTitlePanel() {
|
||||
JPanel titlePanel = new JPanel(new BorderLayout());
|
||||
titlePanel.setOpaque(false);
|
||||
|
||||
// Création du titre
|
||||
Title title = new Title("Récompenses", 70, Color.WHITE);
|
||||
title.setHorizontalAlignment(JLabel.CENTER); // Centrer le titre
|
||||
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;
|
||||
}
|
||||
|
||||
private void updateRewardsPanel(List<Reward> rewards) {
|
||||
rewardsDisplayPanel.removeAll(); // Clear previous contents
|
||||
|
||||
if (rewards.isEmpty()) {
|
||||
// If no rewards, show a message
|
||||
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)); // Ajustez la taille comme nécessaire
|
||||
this.scrollPane.setMinimumSize(new Dimension(600, 300));
|
||||
// Otherwise, display the rewards
|
||||
rewardsDisplayPanel.setLayout(new GridLayout(0, 3, 10, 10));
|
||||
|
||||
// Add each reward to the panel
|
||||
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;
|
||||
}
|
||||
}
|
@@ -3,7 +3,7 @@ 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.utils.MusicPlayer;
|
||||
import fr.monkhanny.dorfromantik.enums.Images;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -18,9 +18,11 @@ public class SettingsPanel extends JPanel {
|
||||
this.mainMenu = mainMenu;
|
||||
this.settingsFrame = settingsFrame;
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
initializeSettingsFrame();
|
||||
setupBackground();
|
||||
setupMainPanel();
|
||||
setupTopPanel(); // Nouveau panneau pour le titre et le bouton de retour
|
||||
setupMainPanel(); // Configuration du panneau principal pour les sliders et boutons
|
||||
}
|
||||
|
||||
private void initializeSettingsFrame() {
|
||||
@@ -30,87 +32,161 @@ public class SettingsPanel extends JPanel {
|
||||
private void setupBackground() {
|
||||
JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg"));
|
||||
background.setLayout(new GridBagLayout());
|
||||
this.setLayout(new BorderLayout());
|
||||
this.add(background);
|
||||
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 = createMainPanel();
|
||||
JLabel title = createTitle();
|
||||
|
||||
mainPanel.add(title, createGridBagConstraints(0, 0, 2));
|
||||
mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 1, 1));
|
||||
|
||||
// Musique Panel
|
||||
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, 2, 1));
|
||||
|
||||
mainPanel.add(Box.createVerticalStrut(30), createGridBagConstraints(0, 3, 1));
|
||||
|
||||
// SFX Panel
|
||||
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, 4, 1));
|
||||
|
||||
// Close Button
|
||||
JButton closeButton = createCloseButton();
|
||||
mainPanel.add(closeButton, createGridBagConstraints(0, 5, 1));
|
||||
|
||||
// Add to background
|
||||
((JLabel) this.getComponent(0)).add(mainPanel);
|
||||
}
|
||||
|
||||
private JPanel createMainPanel() {
|
||||
JPanel mainPanel = new JPanel(new GridBagLayout());
|
||||
mainPanel.setOpaque(false);
|
||||
return mainPanel;
|
||||
}
|
||||
|
||||
private Title createTitle() {
|
||||
Title title = new Title("Paramètres", 70, Color.WHITE);
|
||||
return title;
|
||||
}
|
||||
// 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));
|
||||
|
||||
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;
|
||||
// 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(new GridBagLayout());
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); // Utilisation de BoxLayout pour une disposition verticale
|
||||
panel.setOpaque(false);
|
||||
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.insets = new Insets(10, 10, 10, 10);
|
||||
gbc.gridx = 0;
|
||||
// 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);
|
||||
|
||||
panel.add(new JLabel(labelText), gbc);
|
||||
gbc.gridx++;
|
||||
panel.add(muteCheckBox, gbc);
|
||||
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);
|
||||
|
||||
gbc.gridx++;
|
||||
panel.add(createSliderPanel(volumeSlider), gbc);
|
||||
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);
|
||||
@@ -128,15 +204,31 @@ public class SettingsPanel extends JPanel {
|
||||
return sliderPanel;
|
||||
}
|
||||
|
||||
private JButton createCloseButton() {
|
||||
JButton closeButton = new JButton("Retour");
|
||||
closeButton.setFont(new Font("Roboto", Font.BOLD, 24));
|
||||
closeButton.setForeground(Color.BLACK);
|
||||
closeButton.setBackground(Color.WHITE);
|
||||
closeButton.setOpaque(true);
|
||||
closeButton.setPreferredSize(new Dimension(75, 50));
|
||||
closeButton.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
closeButton.addActionListener(new CloseButtonListener(mainMenu, settingsFrame));
|
||||
return closeButton;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,9 @@
|
||||
package fr.monkhanny.dorfromantik.gui;
|
||||
|
||||
import fr.monkhanny.dorfromantik.components.Title;
|
||||
import fr.monkhanny.dorfromantik.gui.Step;
|
||||
import fr.monkhanny.dorfromantik.listeners.CloseButtonListener;
|
||||
import fr.monkhanny.dorfromantik.listeners.TutorialButtonHoverListener;
|
||||
import fr.monkhanny.dorfromantik.enums.Images;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -11,16 +13,19 @@ 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) {
|
||||
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());
|
||||
@@ -29,12 +34,25 @@ public class TutorialPanel extends JPanel {
|
||||
title = new Title("Comment jouer ?", 70f, Color.WHITE);
|
||||
title.setHorizontalAlignment(JLabel.CENTER);
|
||||
title.setOpaque(false);
|
||||
add(title, BorderLayout.NORTH);
|
||||
|
||||
// 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
|
||||
centerPanel.setOpaque(false); // Rendre le conteneur transparent
|
||||
|
||||
// Utiliser GridBagConstraints pour centrer le contenu verticalement
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
@@ -46,19 +64,19 @@ public class TutorialPanel extends JPanel {
|
||||
// Conteneur pour le texte et l'image
|
||||
JPanel stepContainer = new JPanel();
|
||||
stepContainer.setLayout(new BoxLayout(stepContainer, BoxLayout.Y_AXIS));
|
||||
stepContainer.setOpaque(false); // Transparent
|
||||
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
|
||||
stepText.setAlignmentX(Component.CENTER_ALIGNMENT); // Centrer le texte horizontalement
|
||||
|
||||
stepImage = new JLabel();
|
||||
stepImage.setAlignmentX(Component.CENTER_ALIGNMENT); // Centrer l'image horizontalement
|
||||
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(Box.createVerticalStrut(10)); // Espace entre texte et image
|
||||
stepContainer.add(stepImage);
|
||||
|
||||
// Ajouter le conteneur d'étapes au centre du panel
|
||||
@@ -67,13 +85,19 @@ public class TutorialPanel extends JPanel {
|
||||
|
||||
// Panneau pour les boutons de navigation
|
||||
JPanel buttonPanel = new JPanel();
|
||||
buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); // Centrer les boutons
|
||||
buttonPanel.setOpaque(false); // Transparent
|
||||
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);
|
||||
|
||||
@@ -86,12 +110,12 @@ public class TutorialPanel extends JPanel {
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g); // Appel à super pour s'assurer que le panneau est dessiné
|
||||
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
|
||||
g.drawImage(image, 0, 0, getWidth(), getHeight(), this); // Dessiner l'image pour couvrir tout le panneau
|
||||
}
|
||||
|
||||
private void updateStepDisplay() {
|
||||
@@ -104,6 +128,25 @@ public class TutorialPanel extends JPanel {
|
||||
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--;
|
||||
@@ -117,4 +160,21 @@ public class TutorialPanel extends JPanel {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -6,20 +6,20 @@ import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import javax.swing.*;
|
||||
|
||||
public class SettingsWindowListener extends WindowAdapter {
|
||||
public class CloseWindowListener extends WindowAdapter {
|
||||
|
||||
private MainMenu mainMenu;
|
||||
private JFrame settingsFrame;
|
||||
private JFrame frame;
|
||||
|
||||
public SettingsWindowListener(MainMenu mainMenu, JFrame settingsFrame) {
|
||||
public CloseWindowListener(MainMenu mainMenu, JFrame frame) {
|
||||
this.mainMenu = mainMenu;
|
||||
this.settingsFrame = settingsFrame;
|
||||
this.frame = frame;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
// Réafficher la fenêtre du menu principal
|
||||
mainMenu.setVisible(true);
|
||||
settingsFrame.setVisible(false); // Fermer la fenêtre des paramètres
|
||||
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,88 @@
|
||||
package fr.monkhanny.dorfromantik.listeners;
|
||||
|
||||
import fr.monkhanny.dorfromantik.game.Board;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class TilePanningActionListener implements ActionListener {
|
||||
private Board board;
|
||||
private int targetOffsetX, targetOffsetY;
|
||||
private int steps; // Nombre d'étapes pour l'animation
|
||||
private Timer timer;
|
||||
|
||||
// Indicateur pour vérifier si l'animation est en cours
|
||||
private static boolean isAnimating = false;
|
||||
|
||||
// Variables pour suivre l'état de l'animation
|
||||
private int currentStep = 0;
|
||||
|
||||
public TilePanningActionListener(Board board, int targetOffsetX, int targetOffsetY, int steps) {
|
||||
this.board = board;
|
||||
this.targetOffsetX = targetOffsetX;
|
||||
this.targetOffsetY = targetOffsetY;
|
||||
this.steps = steps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int currentOffsetX = board.getOffsetX();
|
||||
int currentOffsetY = board.getOffsetY();
|
||||
|
||||
// Si l'animation a atteint la cible (exactement)
|
||||
if (currentStep >= steps) {
|
||||
board.setOffsetX(targetOffsetX);
|
||||
board.setOffsetY(targetOffsetY);
|
||||
stopAnimation();
|
||||
} else {
|
||||
// Calculer le delta pour chaque étape en utilisant des valeurs flottantes
|
||||
float deltaX = (float)(targetOffsetX - currentOffsetX) / (steps - currentStep);
|
||||
float deltaY = (float)(targetOffsetY - currentOffsetY) / (steps - currentStep);
|
||||
|
||||
// Appliquer la transition progressivement avec un arrondi à l'entier le plus proche
|
||||
board.setOffsetX(currentOffsetX + Math.round(deltaX));
|
||||
board.setOffsetY(currentOffsetY + Math.round(deltaY));
|
||||
|
||||
// Ne redessiner que si nécessaire
|
||||
if (currentStep % 2 == 0) { // Par exemple, redessiner toutes les 2 étapes
|
||||
board.repaint(); // Re-dessiner le plateau
|
||||
}
|
||||
|
||||
// Augmenter le compteur d'étapes
|
||||
currentStep++;
|
||||
}
|
||||
}
|
||||
|
||||
// Lancer l'animation
|
||||
public void startAnimation() {
|
||||
if (isAnimating) {
|
||||
stopCurrentAnimation();
|
||||
}
|
||||
|
||||
isAnimating = true;
|
||||
|
||||
// Réinitialiser les étapes
|
||||
currentStep = 0;
|
||||
|
||||
// Créer et démarrer le timer pour l'animation
|
||||
this.timer = new Timer(1000 / 60, this); // 60 FPS
|
||||
timer.start();
|
||||
}
|
||||
|
||||
// Arrêter l'animation proprement
|
||||
private void stopAnimation() {
|
||||
if (timer != null) {
|
||||
timer.stop(); // Arrêter le timer
|
||||
}
|
||||
isAnimating = false; // Réinitialiser l'indicateur d'animation
|
||||
}
|
||||
|
||||
// Annuler l'animation en cours
|
||||
private void stopCurrentAnimation() {
|
||||
if (timer != null) {
|
||||
timer.stop(); // Arrêter le timer de l'animation en cours
|
||||
}
|
||||
isAnimating = false; // Réinitialiser l'animation
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package fr.monkhanny.dorfromantik.listeners;
|
||||
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import javax.swing.JButton;
|
||||
import java.awt.Color;
|
||||
|
||||
public class TutorialButtonHoverListener extends MouseAdapter {
|
||||
|
||||
private final JButton button;
|
||||
private final Color hoverColor;
|
||||
private final Color originalColor;
|
||||
|
||||
public TutorialButtonHoverListener(JButton button, Color hoverColor, Color originalColor) {
|
||||
this.button = button;
|
||||
this.hoverColor = hoverColor;
|
||||
this.originalColor = originalColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent evt) {
|
||||
button.setBackground(hoverColor); // Couleur plus claire au survol
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent evt) {
|
||||
button.setBackground(originalColor); // Retour à la couleur originale
|
||||
}
|
||||
}
|
@@ -1,14 +1,25 @@
|
||||
package fr.monkhanny.dorfromantik.utils;
|
||||
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.Reward;
|
||||
|
||||
public class Database {
|
||||
// Chargement des variables d'environnement
|
||||
private static final String URL = Environnement.getEnv("DATABASE_URL_IUT");
|
||||
private static final String LOGIN = Environnement.getEnv("DATABASE_LOGIN_IUT");
|
||||
private static final String PASSWORD = Environnement.getEnv("DATABASE_PASSWORD_IUT");
|
||||
private static final String URL = "jdbc:mariadb://dwarves.iut-fbleau.fr/stiti";
|
||||
private static final String LOGIN = "stiti";
|
||||
private static final String PASSWORD = "stiti1234";
|
||||
|
||||
// Variable de passerelle entre le programme et la base de données
|
||||
private Connection database;
|
||||
@@ -40,6 +51,216 @@ public class Database {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Récupère le seed correspondant au mode de jeu (series_id)
|
||||
* @param seriesId L'ID de la série (mode de jeu)
|
||||
* @return Le seed associé à ce mode de jeu
|
||||
* @throws SQLException Si une erreur se produit lors de la récupération du seed
|
||||
*/
|
||||
public long getSeedBySeriesId(long seriesId) throws SQLException {
|
||||
String query = "SELECT series_id FROM Series WHERE series_id = " + seriesId;
|
||||
long seed = -1; // Valeur par défaut si le seed n'est pas trouvé
|
||||
|
||||
try (Statement stmt = this.database.createStatement();
|
||||
ResultSet rs = stmt.executeQuery(query)) {
|
||||
if (rs.next()) {
|
||||
seed = rs.getLong("series_id");
|
||||
}
|
||||
}
|
||||
|
||||
return seed;
|
||||
}
|
||||
|
||||
public List<PlayerScore> getAllScores(long seriesId) throws SQLException {
|
||||
List<PlayerScore> allScores = new ArrayList<>();
|
||||
|
||||
String query = "SELECT username, score FROM Scores WHERE series_id = ? ORDER BY score DESC";
|
||||
try (PreparedStatement stmt = this.database.prepareStatement(query)) {
|
||||
stmt.setLong(1, seriesId);
|
||||
try (ResultSet rs = stmt.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
String username = rs.getString("username");
|
||||
if (username == null || username.trim().isEmpty()) {
|
||||
username = "Joueur Anonyme"; // Default name if empty
|
||||
}
|
||||
int score = rs.getInt("score");
|
||||
allScores.add(new PlayerScore(username, score));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return allScores;
|
||||
}
|
||||
|
||||
|
||||
public long getSeedByName(String name) throws SQLException {
|
||||
String query = "SELECT series_id FROM Series WHERE name = " + "\'" + name + "\'" +";";
|
||||
long seed = -1; // Valeur par défaut si le seed n'est pas trouvé
|
||||
|
||||
try (Statement stmt = this.database.createStatement();
|
||||
ResultSet rs = stmt.executeQuery(query)) {
|
||||
if (rs.next()) {
|
||||
seed = rs.getLong("series_id");
|
||||
}
|
||||
}
|
||||
|
||||
return seed;
|
||||
}
|
||||
|
||||
public void addScore(String username, long seriesId, int score) throws SQLException {
|
||||
String insertQuery = "INSERT INTO Scores (username, series_id, score) VALUES (?, ?, ?)";
|
||||
try (PreparedStatement stmt = this.database.prepareStatement(insertQuery)) {
|
||||
stmt.setString(1, username);
|
||||
stmt.setLong(2, seriesId);
|
||||
stmt.setInt(3, score);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
System.err.println("Erreur lors de l'ajout du score: " + e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void addCustomSeed(String name, long customSeed) throws SQLException {
|
||||
// Vérifier si la seed existe déjà
|
||||
String checkQuery = "SELECT COUNT(*) FROM Series WHERE series_id = ?";
|
||||
try (PreparedStatement checkStmt = this.database.prepareStatement(checkQuery)) {
|
||||
checkStmt.setLong(1, customSeed);
|
||||
ResultSet rs = checkStmt.executeQuery();
|
||||
if (rs.next() && rs.getInt(1) > 0) {
|
||||
// la seed existe déjà
|
||||
return; // Ne pas insérer si la seed existe déjà
|
||||
}
|
||||
}
|
||||
|
||||
// Si la seed n'existe pas, procéder à l'insertion
|
||||
String insertQuery = "INSERT INTO Series (name, series_id, creation_date) VALUES (?, ?, CURRENT_TIMESTAMP)";
|
||||
try (PreparedStatement stmt = this.database.prepareStatement(insertQuery)) {
|
||||
stmt.setString(1, name);
|
||||
stmt.setLong(2, customSeed);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
System.err.println("Erreur lors de l'ajout de la seed custom: " + e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Récupère les meilleurs scores des joueurs (limite de 10 scores)
|
||||
* @return une liste de résultats sous forme de tableau d'objets contenant le nom du joueur et son score
|
||||
*/
|
||||
public List<PlayerScore> getTopPlayers() throws SQLException {
|
||||
List<PlayerScore> topPlayers = new ArrayList<>();
|
||||
|
||||
String query = "SELECT username, score FROM Scores ORDER BY score DESC LIMIT 10";
|
||||
try (Statement stmt = this.database.createStatement();
|
||||
ResultSet rs = stmt.executeQuery(query)) {
|
||||
|
||||
while (rs.next()) {
|
||||
String username = rs.getString("username");
|
||||
if (username == null || username.trim().isEmpty()) {
|
||||
username = "Joueur Anonyme"; // Remplacer par "Joueur Anonyme" si le pseudo est vide ou nul
|
||||
}
|
||||
int score = rs.getInt("score");
|
||||
topPlayers.add(new PlayerScore(username, score));
|
||||
}
|
||||
}
|
||||
|
||||
return topPlayers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les scores d'une série spécifique, triés en ordre décroissant (du plus élevé au plus bas)
|
||||
* @param seriesId L'ID de la série
|
||||
* @return Liste des scores pour la série donnée
|
||||
* @throws SQLException En cas d'erreur lors de la récupération des scores
|
||||
*/
|
||||
public List<Integer> getScoresBySeriesId(long seriesId) throws SQLException {
|
||||
List<Integer> scores = new ArrayList<>();
|
||||
|
||||
String query = "SELECT score FROM Scores WHERE series_id = ? ORDER BY score DESC";
|
||||
try (PreparedStatement stmt = this.database.prepareStatement(query)) {
|
||||
stmt.setLong(1, seriesId);
|
||||
try (ResultSet rs = stmt.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
scores.add(rs.getInt("score"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If you want the scores to be in descending order (from highest to lowest)
|
||||
Collections.sort(scores, Collections.reverseOrder());
|
||||
|
||||
return scores;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les récompenses d'un utilisateur spécifique
|
||||
* @param username Le nom d'utilisateur pour lequel récupérer les récompenses
|
||||
* @return Liste des récompenses de l'utilisateur
|
||||
* @throws SQLException En cas d'erreur lors de la récupération des récompenses
|
||||
*/
|
||||
public List<Reward> getRewardsByUsername(String username) throws SQLException {
|
||||
List<Reward> rewards = new ArrayList<>();
|
||||
String query = "SELECT r.name, r.description, r.icon_path, ur.is_unlocked " +
|
||||
"FROM UserRewards ur " +
|
||||
"JOIN Rewards r ON ur.reward_id = r.reward_id " +
|
||||
"WHERE ur.username = ?";
|
||||
|
||||
try (PreparedStatement stmt = this.database.prepareStatement(query)) {
|
||||
stmt.setString(1, username);
|
||||
|
||||
try (ResultSet rs = stmt.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
String name = rs.getString("name");
|
||||
String description = rs.getString("description");
|
||||
String iconPath = rs.getString("icon_path");
|
||||
boolean isUnlocked = rs.getBoolean("is_unlocked");
|
||||
|
||||
ImageIcon icon = (iconPath != null && !iconPath.isEmpty()) ? new ImageIcon(iconPath) : null;
|
||||
Reward reward = new Reward(name, description, isUnlocked, icon);
|
||||
rewards.add(reward);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rewards;
|
||||
}
|
||||
|
||||
public void unlockRewards(String username, int score) throws SQLException {
|
||||
// Vérifier les récompenses possibles en fonction du score du joueur
|
||||
String query = "SELECT reward_id FROM Rewards WHERE score_threshold <= ?";
|
||||
try (PreparedStatement stmt = this.database.prepareStatement(query)) {
|
||||
stmt.setInt(1, score);
|
||||
try (ResultSet rs = stmt.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
long rewardId = rs.getLong("reward_id");
|
||||
|
||||
// Ajouter la récompense à la table UserRewards si elle n'est pas déjà débloquée
|
||||
String checkQuery = "SELECT COUNT(*) FROM UserRewards WHERE username = ? AND reward_id = ?";
|
||||
try (PreparedStatement checkStmt = this.database.prepareStatement(checkQuery)) {
|
||||
checkStmt.setString(1, username);
|
||||
checkStmt.setLong(2, rewardId);
|
||||
|
||||
ResultSet checkRs = checkStmt.executeQuery();
|
||||
if (checkRs.next() && checkRs.getInt(1) == 0) {
|
||||
// Si la récompense n'est pas encore débloquée pour cet utilisateur, l'ajouter
|
||||
String insertQuery = "INSERT INTO UserRewards (username, reward_id, is_unlocked) VALUES (?, ?, 1)";
|
||||
try (PreparedStatement insertStmt = this.database.prepareStatement(insertQuery)) {
|
||||
insertStmt.setString(1, username);
|
||||
insertStmt.setLong(2, rewardId);
|
||||
insertStmt.executeUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
if (this.database != null && !this.database.isClosed()) {
|
||||
@@ -49,4 +270,4 @@ public class Database {
|
||||
System.err.println("Erreur lors de la fermeture de la base de données : " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
package fr.monkhanny.dorfromantik.utils;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class Environnement {
|
||||
private static final String ENV_FILE = ".env";
|
||||
private static final Properties properties = new Properties();
|
||||
|
||||
static {
|
||||
loadEnvironmentVariables();
|
||||
}
|
||||
|
||||
private static void loadEnvironmentVariables() {
|
||||
try (InputStream input = new FileInputStream(ENV_FILE)) {
|
||||
// Chargement des variables du fichier .env
|
||||
properties.load(input);
|
||||
} catch (IOException e) {
|
||||
System.err.println("Erreur lors du chargement du fichier .env : " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Méthode pour récupérer une variable d'environnement, renvoie null si non trouvé
|
||||
public static String getEnv(String key) {
|
||||
return properties.getProperty(key);
|
||||
}
|
||||
|
||||
// Méthode pour vérifier si une variable d'environnement est présente
|
||||
public static boolean hasEnv(String key) {
|
||||
return properties.containsKey(key);
|
||||
}
|
||||
}
|
22
TestV1/src/fr/monkhanny/dorfromantik/utils/PlayerScore.java
Normal file
22
TestV1/src/fr/monkhanny/dorfromantik/utils/PlayerScore.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package fr.monkhanny.dorfromantik.utils;
|
||||
|
||||
/**
|
||||
* Représente un score d'un joueur avec son nom et son score.
|
||||
*/
|
||||
public class PlayerScore {
|
||||
private String username;
|
||||
private int score;
|
||||
|
||||
public PlayerScore(String username, int score) {
|
||||
this.username = username;
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return score;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user