Un peu de ménage dans le git

This commit is contained in:
2024-12-02 20:51:28 +01:00
parent 0e6450f8c8
commit 9b2a314262
102 changed files with 49818 additions and 27 deletions

View File

@@ -0,0 +1,43 @@
package fr.monkhanny.dorfromantik.controller;
import fr.monkhanny.dorfromantik.Options;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ButtonHoverAnimationListener implements ActionListener {
private int step = 0;
private final float scaleIncrement;
private final boolean entering;
private final JButton button;
private final Color originalColor;
private final Font originalFont;
private float currentScale = 1.0f;
public ButtonHoverAnimationListener(boolean entering, JButton button, Color originalColor, Font originalFont) {
this.entering = entering;
this.button = button;
this.originalColor = originalColor;
this.originalFont = originalFont;
this.scaleIncrement = (Options.HOVER_FONT_SCALE - 1.0f) / Options.ANIMATION_STEPS;
}
@Override
public void actionPerformed(ActionEvent e) {
currentScale = entering ? (1.0f + step * scaleIncrement) : (Options.HOVER_FONT_SCALE - step * scaleIncrement);
button.setForeground(entering ? Options.BUTTON_HOVER_COLOR : originalColor);
button.setFont(originalFont.deriveFont(originalFont.getSize2D() * currentScale));
step++;
if (step >= Options.ANIMATION_STEPS) {
((Timer) e.getSource()).stop();
if (!entering) {
button.setFont(originalFont); // Restore the original font
}
}
}
}

View File

@@ -0,0 +1,29 @@
package fr.monkhanny.dorfromantik.controller;
import fr.monkhanny.dorfromantik.gui.ButtonHoverAnimator;
import fr.monkhanny.dorfromantik.utils.MusicPlayer;
import fr.monkhanny.dorfromantik.enums.Sounds;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class ButtonHoverListener extends MouseAdapter {
private final ButtonHoverAnimator animator;
public ButtonHoverListener(ButtonHoverAnimator animator) {
this.animator = animator;
}
@Override
public void mouseEntered(MouseEvent e) {
animator.startAnimation(true);
MusicPlayer.loadSound(Sounds.SOUNDS1); // Charge le son
MusicPlayer.playSound(); // Joue le son
}
@Override
public void mouseExited(MouseEvent e) {
animator.startAnimation(false);
}
}

View File

@@ -0,0 +1,115 @@
package fr.monkhanny.dorfromantik.controller;
import fr.monkhanny.dorfromantik.gui.GameModeSelectionPanel;
import fr.monkhanny.dorfromantik.gui.MainMenu;
import fr.monkhanny.dorfromantik.game.Board;
import fr.monkhanny.dorfromantik.utils.Database;
import fr.monkhanny.dorfromantik.Options;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import java.sql.SQLException;
import java.awt.Dimension;
import java.awt.Point;
public class GameModeController implements ActionListener {
private GameModeSelectionPanel gameModeSelectionPanel;
private JFrame gameFrame;
private MainMenu mainMenu;
private Database database;
private JFrame gameModeFrame;
private static Board board;
// Constructeur sans le panneau
public GameModeController(JFrame gameFrame, MainMenu mainMenu, JFrame gameModeFrame) {
this.gameFrame = gameFrame;
this.mainMenu = mainMenu;
this.gameModeFrame = gameModeFrame;
// Connexion à la base de données
try {
this.database = new Database();
} catch (Exception e) {
System.err.println("Erreur lors de la connexion à la base de données: " + e.getMessage());
}
}
// Méthode pour associer le panneau
public void setGameModeSelectionPanel(GameModeSelectionPanel panel) {
this.gameModeSelectionPanel = panel;
}
@Override
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
switch (command) {
case "Mode 1":
startGame("Mode 1", getSeedFromDatabaseByName("Mode 1"));
break;
case "Mode 2":
startGame("Mode 2", getSeedFromDatabaseByName("Mode 2"));
break;
case "Mode 3":
startGame("Mode 3", getSeedFromDatabaseByName("Mode 3"));
break;
case "Mode 4":
startGame("Mode 4", getSeedFromDatabaseByName("Mode 4"));
break;
case "Démarrer":
long seed = gameModeSelectionPanel.getLongSeed();
startGame("Custom Mode", seed);
addCustomSeedToDatabase("Custom Mode", seed);
break;
default:
System.out.println("Commande inconnue: " + command);
}
}
private long getSeedFromDatabaseByName(String modeName) {
try {
Options.SEED = this.database.getSeedByName(modeName);
return Options.SEED;
} catch (SQLException e) {
e.printStackTrace();
return -1; // Retourner une valeur par défaut si une erreur survient
}
}
private void addCustomSeedToDatabase(String name, long seed) {
try {
Options.SEED = seed;
this.database.addCustomSeed(name, seed);
} catch (SQLException e) {
e.printStackTrace();
System.err.println("Erreur lors de l'ajout de la seed custom.");
}
}
private void startGame(String mode, long seed) {
// Supprimer la potentielle ancienne instance de board
GameModeController.board = null;
// Cacher la fenêtre avant de faire des modifications
this.gameFrame.setVisible(false);
if (Options.FULL_SCREEN) {
gameFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); // Set frame to full screen
} else {
Dimension mainMenuSize = this.mainMenu.getSize();
Point mainMenuLocation = this.mainMenu.getLocation();
gameFrame.setSize(mainMenuSize);
gameFrame.setLocation(mainMenuLocation);
}
GameModeController.board = new Board(this.gameFrame,seed);
//this.gameModeFrame.setVisible(false);
this.gameFrame.setVisible(true);
this.gameFrame.add(board);
}
public static Board getGameModeBoard() {
return board;
}
}

View File

@@ -0,0 +1,132 @@
package fr.monkhanny.dorfromantik.controller;
import fr.monkhanny.dorfromantik.gui.MainMenu;
import fr.monkhanny.dorfromantik.gui.ButtonPanel;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Dimension;
import java.awt.Point;
public class MainMenuButtonController implements ActionListener {
private MainMenu mainMenu;
private JFrame settingsFrame;
private JFrame howToPlayFrame;
private JFrame gameModeFrame;
private JFrame gameFrame;
private JFrame rewardsFrame;
public MainMenuButtonController(MainMenu mainMenu, JFrame settingsFrame, JFrame howToPlayFrame, JFrame gameModeFrame, JFrame gameFrame, JFrame rewardsFrame) {
this.mainMenu = mainMenu;
// Ajouter les écouteurs d'événements sur les boutons
ButtonPanel buttonPanel = mainMenu.getButtonPanel();
// Attacher les actions aux boutons du menu principal
buttonPanel.getNewGameButton().addActionListener(this);
buttonPanel.getContinueGameButton().addActionListener(this);
buttonPanel.getHowToPlayButton().addActionListener(this);
buttonPanel.getSettingsButton().addActionListener(this);
buttonPanel.getExitButton().addActionListener(this);
// Paramètrage de la fenêtre des paramètres
this.settingsFrame = settingsFrame;
configureFrame(this.settingsFrame);
// Paramètrage de la fenêtre du tutoriel
this.howToPlayFrame = howToPlayFrame;
configureFrame(this.howToPlayFrame);
// Paramètrage de la fenêtre du jeu
this.gameModeFrame = gameModeFrame;
configureFrame(this.gameModeFrame);
// Paramètrage de la fenêtre du jeu
this.gameFrame = gameFrame;
configureFrame(this.gameFrame);
// Paramètrage de la fenêtre des récompenses
this.rewardsFrame = rewardsFrame;
configureFrame(this.rewardsFrame);
}
private void configureFrame(JFrame frame) {
frame.setLocationRelativeTo(null);
frame.setVisible(false);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
switch (command) {
case "Jouer":
startNewGame();
break;
case "Récompenses":
openRecompense();
break;
case "Comment jouer ?":
showHowToPlay();
break;
case "Paramètres":
openSettings();
break;
case "Quitter":
exitGame();
break;
default:
System.out.println("Commande inconnue: " + command);
break;
}
}
public void startNewGame() {
adjustFrameDisplay(this.gameModeFrame);
this.mainMenu.setVisible(false);
this.gameModeFrame.setVisible(true);
}
private void openRecompense() {
adjustFrameDisplay(this.rewardsFrame);
this.mainMenu.setVisible(false);
this.rewardsFrame.setVisible(true);
}
public void showHowToPlay() {
adjustFrameDisplay(this.howToPlayFrame);
this.mainMenu.setVisible(false);
this.howToPlayFrame.setVisible(true);
}
private void exitGame() {
System.exit(0); // Fermer l'application
}
private void openSettings() {
adjustFrameDisplay(this.settingsFrame);
this.mainMenu.setVisible(false);
this.settingsFrame.setVisible(true);
}
private void adjustFrameDisplay(JFrame frame) {
boolean wasVisible = frame.isVisible(); // Vérifier si la fenêtre était déjà visible
if(!wasVisible){
// Récupérer la taille et la position de la fenêtre du menu principal
Dimension mainMenuSize = this.mainMenu.getSize();
Point mainMenuLocation = this.mainMenu.getLocation();
frame.setSize(mainMenuSize);
frame.setLocation(mainMenuLocation);
}
}
}

View File

@@ -0,0 +1,29 @@
package fr.monkhanny.dorfromantik.controller;
import fr.monkhanny.dorfromantik.gui.ButtonPanel;
import fr.monkhanny.dorfromantik.gui.ButtonHoverAnimator;
import javax.swing.*;
public class MainMenuMouseController {
private final ButtonPanel buttonPanel;
public MainMenuMouseController(ButtonPanel buttonPanel) {
this.buttonPanel = buttonPanel;
initMouseListeners();
}
private void initMouseListeners() {
addButtonHoverListener(buttonPanel.getNewGameButton());
addButtonHoverListener(buttonPanel.getContinueGameButton());
addButtonHoverListener(buttonPanel.getHowToPlayButton());
addButtonHoverListener(buttonPanel.getSettingsButton());
addButtonHoverListener(buttonPanel.getExitButton());
}
private void addButtonHoverListener(JButton button) {
ButtonHoverAnimator animator = new ButtonHoverAnimator(button);
button.addMouseListener(new ButtonHoverListener(animator));
}
}

View File

@@ -0,0 +1,19 @@
package fr.monkhanny.dorfromantik.controller;
import fr.monkhanny.dorfromantik.gui.MainMenu;
public class MainMenuResizeController {
private MainMenu mainMenu;
private MainMenuResizeHandler resizeHandler;
public MainMenuResizeController(MainMenu mainMenu) {
this.mainMenu = mainMenu;
this.resizeHandler = new MainMenuResizeHandler(mainMenu);
addComponentListener();
}
private void addComponentListener() {
mainMenu.addComponentListener(resizeHandler);
}
}

View File

@@ -0,0 +1,30 @@
package fr.monkhanny.dorfromantik.controller;
import fr.monkhanny.dorfromantik.gui.MainMenu;
import fr.monkhanny.dorfromantik.Options;
import fr.monkhanny.dorfromantik.gui.ButtonHoverAnimator;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
public class MainMenuResizeHandler extends ComponentAdapter {
private MainMenu mainMenu;
public MainMenuResizeHandler(MainMenu mainMenu) {
this.mainMenu = mainMenu;
}
@Override
public void componentResized(ComponentEvent e) {
int mainMenuWidth = mainMenu.getWidth();
// Ajuster la taille de la police du titre en fonction de la taille de la fenêtre
float newFontSize = Options.BASE_TITLE_FONT_SIZE * (mainMenuWidth / 900f);
mainMenu.getTitleLabel().updateTitleFont(newFontSize);
// Mettre à jour les polices des boutons
mainMenu.getButtonPanel().updateButtonFonts(mainMenuWidth);
ButtonHoverAnimator.updateOriginalFont(mainMenuWidth / 30f); // On passe la nouvelle taille de police pour chaque bouton
}
}

View File

@@ -0,0 +1,52 @@
package fr.monkhanny.dorfromantik.controller;
import fr.monkhanny.dorfromantik.gui.RewardsPanel;
import fr.monkhanny.dorfromantik.gui.Reward;
import fr.monkhanny.dorfromantik.utils.Database;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
public class RewardsPanelController {
private RewardsPanel rewardsPanel;
public RewardsPanelController(RewardsPanel rewardsPanel) {
this.rewardsPanel = rewardsPanel;
}
public ActionListener getFetchRewardsAction() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String username = rewardsPanel.getUsername();
if (!username.isEmpty()) {
try {
// Récupérer les récompenses pour l'utilisateur
Database db = new Database();
List<Reward> rewards = db.getRewardsByUsername(username);
db.close();
// Mettre à jour le panneau
rewardsPanel.updateRewardsPanel(rewards);
} catch (Exception ex) {
JOptionPane.showMessageDialog(rewardsPanel, "Error fetching rewards: " + ex.getMessage());
}
}
}
};
}
public ActionListener getBackButtonAction() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
rewardsPanel.getMainMenuFrame().setVisible(true);
rewardsPanel.getRewardsFrame().setVisible(false);
}
};
}
}

View File

@@ -0,0 +1,34 @@
package fr.monkhanny.dorfromantik.controller;
import fr.monkhanny.dorfromantik.gui.TutorialPanel;
import fr.monkhanny.dorfromantik.gui.Step;
import fr.monkhanny.dorfromantik.enums.Images;
import fr.monkhanny.dorfromantik.gui.MainMenu;
import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
public class TutorialController {
private TutorialPanel tutorialPanel;
private MainMenu mainMenu;
private JFrame tutorialFrame;
public TutorialController(MainMenu mainMenu, JFrame tutorialFrame) {
this.mainMenu = mainMenu;
this.tutorialFrame = tutorialFrame;
List<Step> steps = new ArrayList<>();
steps.add(new Step("Étape n°1", "Explication de la première étape ici.", Images.TUTORIAL_GIF1.getImagePath()));
steps.add(new Step("Étape n°2", "Explication de la deuxième étape ici.", Images.TUTORIAL_GIF2.getImagePath()));
steps.add(new Step("Étape n°3", "Explication de la troisième étape ici.", Images.TUTORIAL_GIF3.getImagePath()));
steps.add(new Step("Étape n°4", "Explication de la quatrième étape ici.", Images.TUTORIAL_GIF4.getImagePath()));
tutorialPanel = new TutorialPanel(steps, this.mainMenu, this.tutorialFrame);
}
public JPanel getTutorialPanel() {
return tutorialPanel;
}
}