Un peu de ménage dans le git
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 stiti
|
||||
Copyright (c) 2024 stiti, foulou, chenouna
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
42
Makefile
Normal file
@@ -0,0 +1,42 @@
|
||||
PACKAGE = fr.monkhanny.dorfromantik
|
||||
ENTRY = Main
|
||||
SOURCEDIR = ./src/fr/monkhanny/dorfromantik/
|
||||
BUILDDIR = ./build/
|
||||
DOCDIR = ./doc/
|
||||
JARNAME = dorfromantik.jar
|
||||
CLASSP = ./libs/*:$(BUILDDIR)
|
||||
MANIFESTPATH = Manifest.MF
|
||||
SOURCEDIR = ./src/
|
||||
|
||||
SOURCES := $(shell find $(SOURCEDIR) -name '*.java')
|
||||
|
||||
all:
|
||||
@make clean
|
||||
@make compile
|
||||
@make jar
|
||||
@make run
|
||||
|
||||
compile:
|
||||
@echo "Compiling..."
|
||||
@javac -cp $(CLASSP) -d $(BUILDDIR) $(SOURCES) -Xlint:unchecked -Xlint:deprecation
|
||||
@echo "Done."
|
||||
|
||||
run:
|
||||
@echo "Running..."
|
||||
@java -cp $(CLASSP):$(JARNAME) fr.monkhanny.dorfromantik.Main
|
||||
@echo "Done."
|
||||
|
||||
clean:
|
||||
@echo "Cleaning up..."
|
||||
@rm -rf $(BUILDDIR)* $(DOCDIR)*
|
||||
@echo "Done."
|
||||
|
||||
javadoc:
|
||||
@echo "Generating javadoc..."
|
||||
@javadoc -d $(DOCDIR) -sourcepath src -subpackages $(PACKAGE)
|
||||
@echo "Done."
|
||||
|
||||
jar:
|
||||
@echo "Creating jar..."
|
||||
@jar cfm $(JARNAME) $(MANIFESTPATH) -C $(BUILDDIR) fr/monkhanny/dorfromantik ressources
|
||||
@echo "Done."
|
3
Manifest.MF
Normal file
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: fr.monkhanny.dorfromantik.Main
|
||||
Class-Path: libs/mariadb-client.jar
|
45370
SQL_DATABASE.sql
BIN
ressources/fonts/Contage-Black-Italic-BF63fc29ba63509.ttf
Normal file
BIN
ressources/fonts/Contage-Black.ttf
Normal file
BIN
ressources/fonts/Contage-Bold-Italic-BF63fc29ba7e1fc.ttf
Normal file
BIN
ressources/fonts/Contage-Bold.ttf
Normal file
BIN
ressources/fonts/Contage-Light-BF63fc29bb66d25.ttf
Normal file
BIN
ressources/fonts/Contage-Light-Italic-BF63fc29ba81b18.ttf
Normal file
BIN
ressources/fonts/Contage-Medium-BF63fc29bae1bb5.ttf
Normal file
BIN
ressources/fonts/Contage-Medium-Italic-BF63fc29b9cd284.ttf
Normal file
BIN
ressources/fonts/Contage-Regular-Italic-BF63fc29b846c83.ttf
Normal file
BIN
ressources/fonts/Contage-Regular.ttf
Normal file
BIN
ressources/fonts/Contage-Semi-Light-BF63fc29ba776e9.ttf
Normal file
BIN
ressources/fonts/Contage-Semi-Light-Italic-BF63fc29b8477f8.ttf
Normal file
BIN
ressources/images/Application/Application_Icon.jpg
Normal file
After Width: | Height: | Size: 7.7 KiB |
BIN
ressources/images/Icone/ExitIcon.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
ressources/images/Icone/ExitIcon2.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
ressources/images/MainMenu/Leaderboard/1.png
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
ressources/images/MainMenu/Leaderboard/2.png
Normal file
After Width: | Height: | Size: 27 KiB |
BIN
ressources/images/MainMenu/Leaderboard/3.png
Normal file
After Width: | Height: | Size: 27 KiB |
BIN
ressources/images/MainMenu/background.jpg
Normal file
After Width: | Height: | Size: 444 KiB |
BIN
ressources/images/MainMenu/backgroundBlured.jpg
Normal file
After Width: | Height: | Size: 231 KiB |
BIN
ressources/images/Recompense/1.png
Normal file
After Width: | Height: | Size: 74 KiB |
BIN
ressources/images/Recompense/2.png
Normal file
After Width: | Height: | Size: 58 KiB |
BIN
ressources/images/Recompense/3.png
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
ressources/images/Recompense/4.png
Normal file
After Width: | Height: | Size: 95 KiB |
BIN
ressources/images/Recompense/5.png
Normal file
After Width: | Height: | Size: 98 KiB |
BIN
ressources/images/Recompense/6.png
Normal file
After Width: | Height: | Size: 105 KiB |
BIN
ressources/images/Recompense/7.png
Normal file
After Width: | Height: | Size: 114 KiB |
BIN
ressources/images/Recompense/8.png
Normal file
After Width: | Height: | Size: 121 KiB |
BIN
ressources/images/Recompense/9.png
Normal file
After Width: | Height: | Size: 103 KiB |
BIN
ressources/images/Settings/speaker-high-volume.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
ressources/images/Settings/speaker-mute-volume.png
Normal file
After Width: | Height: | Size: 8.2 KiB |
BIN
ressources/images/Tutorial/Gif1.gif
Normal file
After Width: | Height: | Size: 1.9 MiB |
BIN
ressources/images/Tutorial/Gif2.gif
Normal file
After Width: | Height: | Size: 2.1 MiB |
BIN
ressources/images/Tutorial/Gif3.gif
Normal file
After Width: | Height: | Size: 888 KiB |
BIN
ressources/images/Tutorial/Gif4.gif
Normal file
After Width: | Height: | Size: 1.9 MiB |
BIN
ressources/sounds/Music/mainMenuMusic.wav
Normal file
BIN
ressources/sounds/SFX/1.wav
Normal file
110
src/fr/monkhanny/dorfromantik/Main.java
Normal file
@@ -0,0 +1,110 @@
|
||||
package fr.monkhanny.dorfromantik;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
import fr.monkhanny.dorfromantik.gui.RewardsPanel;
|
||||
import fr.monkhanny.dorfromantik.controller.MainMenuResizeController;
|
||||
import fr.monkhanny.dorfromantik.controller.MainMenuButtonController;
|
||||
import fr.monkhanny.dorfromantik.utils.MusicPlayer;
|
||||
import fr.monkhanny.dorfromantik.enums.Musics;
|
||||
import fr.monkhanny.dorfromantik.listeners.CloseWindowListener;
|
||||
import fr.monkhanny.dorfromantik.gui.SettingsPanel;
|
||||
import fr.monkhanny.dorfromantik.controller.TutorialController;
|
||||
import fr.monkhanny.dorfromantik.controller.GameModeController;
|
||||
import fr.monkhanny.dorfromantik.gui.GameModeSelectionPanel;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
/**
|
||||
* Classe principale du jeu
|
||||
* @version 1.0
|
||||
* @author Moncef STITI
|
||||
* @see MainMenu
|
||||
* @see MainMenuResizeController
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
private static JFrame gameModeFrame;
|
||||
private static JFrame gameFrame;
|
||||
private static JFrame settingsFrame;
|
||||
private static JFrame howToPlayFrame;
|
||||
private static JFrame rewardsFrame;
|
||||
|
||||
// Variable statique pour savoir si la musique a été jouée
|
||||
private static boolean isMusicPlayed = false;
|
||||
|
||||
// Fonction pour réinitialiser tout le jeu
|
||||
public static void resetGame() {
|
||||
// 1. Fermer toutes les fenêtres ouvertes
|
||||
if (gameModeFrame != null) {
|
||||
gameModeFrame.dispose(); // Ferme la fenêtre du choix des modes de jeu
|
||||
}
|
||||
if (gameFrame != null) {
|
||||
gameFrame.dispose(); // Ferme la fenêtre de jeu
|
||||
}
|
||||
if (settingsFrame != null) {
|
||||
settingsFrame.dispose(); // Ferme la fenêtre des paramètres
|
||||
}
|
||||
if (howToPlayFrame != null) {
|
||||
howToPlayFrame.dispose(); // Ferme la fenêtre du tutoriel
|
||||
}
|
||||
if (rewardsFrame != null) {
|
||||
rewardsFrame.dispose(); // Ferme la fenêtre des récompenses
|
||||
}
|
||||
|
||||
// 2. Réinitialiser les variables globales ou statiques si nécessaire
|
||||
Options.mainMenu = new MainMenu(); // Réinitialiser le menu principal
|
||||
|
||||
// 3. Lancer la musique uniquement si ce n'est pas déjà fait
|
||||
if (!isMusicPlayed) {
|
||||
MusicPlayer.loadMusic(Musics.MAIN_MENU_MUSIC); // Recharger la musique du menu principal
|
||||
MusicPlayer.playMusic(); // Reprendre la musique
|
||||
isMusicPlayed = true; // Marquer la musique comme jouée
|
||||
}
|
||||
|
||||
// 4. Créer les fenêtres à nouveau comme au début
|
||||
gameModeFrame = new JFrame("Choix des modes de jeu - Dorfromantik");
|
||||
gameFrame = new JFrame("Jeu - Dorfromantik");
|
||||
settingsFrame = new JFrame("Paramètres - Dorfromantik");
|
||||
howToPlayFrame = new JFrame("Comment jouer ? - Dorfromantik");
|
||||
rewardsFrame = new JFrame("Récompenses - Dorfromantik");
|
||||
|
||||
// Re-créer et réinitialiser les panels et les contrôleurs
|
||||
MainMenuResizeController mainMenuResizeController = new MainMenuResizeController(Options.mainMenu);
|
||||
MainMenuButtonController mainMenuButtonController = new MainMenuButtonController(Options.mainMenu, settingsFrame, howToPlayFrame, gameModeFrame, gameFrame, rewardsFrame);
|
||||
|
||||
// Fenêtre des paramètres
|
||||
CloseWindowListener settingsWindowListener = new CloseWindowListener(Options.mainMenu, settingsFrame);
|
||||
SettingsPanel settingsPanel = new SettingsPanel(Options.mainMenu, settingsFrame);
|
||||
settingsFrame.addWindowListener(settingsWindowListener);
|
||||
settingsFrame.add(settingsPanel);
|
||||
|
||||
// Fenêtre du tutoriel
|
||||
CloseWindowListener howToPlayWindowListener = new CloseWindowListener(Options.mainMenu, howToPlayFrame);
|
||||
TutorialController tutorialController = new TutorialController(Options.mainMenu, howToPlayFrame);
|
||||
howToPlayFrame.addWindowListener(howToPlayWindowListener);
|
||||
howToPlayFrame.add(tutorialController.getTutorialPanel());
|
||||
|
||||
// Fenêtre du choix des modes de jeu
|
||||
CloseWindowListener gameModeWindowListener = new CloseWindowListener(Options.mainMenu, gameModeFrame);
|
||||
GameModeController gameModeController = new GameModeController(gameFrame, Options.mainMenu, gameModeFrame);
|
||||
GameModeSelectionPanel gameModeSelectionPanel = new GameModeSelectionPanel(gameModeController,gameModeFrame, Options.mainMenu);
|
||||
gameModeFrame.addWindowListener(gameModeWindowListener);
|
||||
gameModeController.setGameModeSelectionPanel(gameModeSelectionPanel);
|
||||
gameModeFrame.add(gameModeSelectionPanel);
|
||||
|
||||
// Fenêtre des récompenses
|
||||
CloseWindowListener rewardsWindowListener = new CloseWindowListener(Options.mainMenu, rewardsFrame);
|
||||
rewardsFrame.addWindowListener(rewardsWindowListener);
|
||||
RewardsPanel rewardsPanel = new RewardsPanel(Options.mainMenu,rewardsFrame);
|
||||
rewardsFrame.setContentPane(rewardsPanel);
|
||||
rewardsFrame.pack();
|
||||
|
||||
// Afficher à nouveau le menu principal
|
||||
Options.mainMenu.setVisible(true);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Appel initial pour créer les fenêtres et démarrer le jeu
|
||||
resetGame(); // Appel à la fonction de réinitialisation
|
||||
}
|
||||
}
|
69
src/fr/monkhanny/dorfromantik/Options.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package fr.monkhanny.dorfromantik;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
|
||||
public class Options {
|
||||
|
||||
/**
|
||||
* Taille de police de base pour les titres du menu principal
|
||||
*/
|
||||
public static final float BASE_TITLE_FONT_SIZE = 80f;
|
||||
|
||||
/**
|
||||
* Taille de police de base pour les boutons du menu principal
|
||||
*/
|
||||
public static final float BASE_BUTTON_FONT_SIZE = 45f;
|
||||
|
||||
/**
|
||||
* Niveau de volume par défaut
|
||||
*/
|
||||
public static final int DEFAULT_VOLUME = 60;
|
||||
|
||||
/**
|
||||
* Musique en sourdine ou non
|
||||
*/
|
||||
public static boolean MUSIC_MUTED = false;
|
||||
|
||||
/**
|
||||
* Sons en sourdine ou non
|
||||
*/
|
||||
public static boolean SOUNDS_MUTED = false;
|
||||
|
||||
/**
|
||||
* Couleur de subrillance des boutons
|
||||
*/
|
||||
public static final Color BUTTON_HOVER_COLOR = new Color(0, 130, 180);
|
||||
|
||||
|
||||
public static final float HOVER_FONT_SCALE = 1.1f;
|
||||
public static final int ANIMATION_STEPS = 10;
|
||||
public static final int ANIMATION_DELAY = 15;
|
||||
|
||||
/**
|
||||
* Volume de la musique
|
||||
*/
|
||||
public static int MUSIC_VOLUME = 60;
|
||||
|
||||
/**
|
||||
* Volume des bruitages
|
||||
*/
|
||||
public static int SOUNDS_VOLUME = 60;
|
||||
|
||||
public static final Dimension MINIMUM_FRAME_SIZE = new Dimension(700, 700);
|
||||
|
||||
public static boolean AUTO_FOCUS = false;
|
||||
|
||||
public static final int MAX_TILE_NUMBER = 50;
|
||||
|
||||
public static boolean FULL_SCREEN = false;
|
||||
|
||||
public static final float SCORE_SIZE = 30f;
|
||||
|
||||
public static long SEED = 0;
|
||||
|
||||
public static MainMenu mainMenu;
|
||||
|
||||
public static boolean isPlaying = false;
|
||||
}
|
48
src/fr/monkhanny/dorfromantik/components/Button.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package fr.monkhanny.dorfromantik.components;
|
||||
|
||||
import fr.monkhanny.dorfromantik.utils.FontManager;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Button {
|
||||
|
||||
public static JButton createCustomTextButton(String text, float fontSize) {
|
||||
JButton button = new JButton(text);
|
||||
button.setFocusPainted(false); // Retirer le focus
|
||||
button.setBackground(new Color(102, 178, 255)); // Couleur de fond
|
||||
button.setForeground(Color.WHITE); // Couleur du texte
|
||||
button.setFont(FontManager.getButtonFont(fontSize)); // Appliquer la police du bouton
|
||||
button.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20)); // Espacement autour du texte du bouton
|
||||
return button;
|
||||
}
|
||||
|
||||
public static JButton createCustomIconButton(String iconPath) {
|
||||
// Créer le bouton
|
||||
JButton button = new JButton();
|
||||
button.setFocusPainted(false); // Retirer le focus
|
||||
|
||||
// Charger l'icône depuis le chemin spécifié
|
||||
ImageIcon icon = new ImageIcon(iconPath);
|
||||
|
||||
// Calculer automatiquement la taille de l'icône pour l'adapter à la taille du bouton
|
||||
int buttonWidth = 100; // Taille du bouton (largeur)
|
||||
int buttonHeight = 100; // Taille du bouton (hauteur)
|
||||
|
||||
// Vous pouvez ajuster ces valeurs ou les calculer dynamiquement en fonction de la taille du bouton
|
||||
Image img = icon.getImage();
|
||||
Image resizedImage = img.getScaledInstance(buttonWidth, buttonHeight, Image.SCALE_SMOOTH);
|
||||
button.setIcon(new ImageIcon(resizedImage));
|
||||
|
||||
// Optionnel : changer la couleur de fond ou de bordure si nécessaire
|
||||
button.setBackground(new Color(102, 178, 255)); // Couleur de fond (facultatif)
|
||||
|
||||
// Retirer la bordure du bouton (facultatif)
|
||||
button.setBorder(BorderFactory.createEmptyBorder());
|
||||
|
||||
// Redimensionner le bouton pour s'adapter à l'icône si nécessaire
|
||||
button.setPreferredSize(new Dimension(buttonWidth, buttonHeight));
|
||||
|
||||
return button;
|
||||
}
|
||||
}
|
27
src/fr/monkhanny/dorfromantik/components/Title.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package fr.monkhanny.dorfromantik.components;
|
||||
|
||||
import fr.monkhanny.dorfromantik.utils.FontManager;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Title extends JLabel {
|
||||
|
||||
public Title(String text, float fontSize) {
|
||||
super(text, SwingConstants.CENTER);
|
||||
setFont(FontManager.getTitleFont(fontSize));
|
||||
setForeground(Color.WHITE);
|
||||
setBorder(BorderFactory.createEmptyBorder(20, 0, 20, 0));
|
||||
}
|
||||
|
||||
public Title(String text, float fontSize, Color textColor) {
|
||||
super(text, SwingConstants.CENTER);
|
||||
setFont(FontManager.getTitleFont(fontSize));
|
||||
setForeground(textColor);
|
||||
setBorder(BorderFactory.createEmptyBorder(20, 0, 20, 0));
|
||||
}
|
||||
|
||||
public void updateTitleFont(float fontSize) {
|
||||
setFont(FontManager.getTitleFont(fontSize));
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class ButtonHoverAnimationListener implements ActionListener {
|
||||
|
||||
private int step = 0;
|
||||
private final float scaleIncrement;
|
||||
private final boolean entering;
|
||||
private final JButton button;
|
||||
private final Color originalColor;
|
||||
private final Font originalFont;
|
||||
private float currentScale = 1.0f;
|
||||
|
||||
public ButtonHoverAnimationListener(boolean entering, JButton button, Color originalColor, Font originalFont) {
|
||||
this.entering = entering;
|
||||
this.button = button;
|
||||
this.originalColor = originalColor;
|
||||
this.originalFont = originalFont;
|
||||
this.scaleIncrement = (Options.HOVER_FONT_SCALE - 1.0f) / Options.ANIMATION_STEPS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
currentScale = entering ? (1.0f + step * scaleIncrement) : (Options.HOVER_FONT_SCALE - step * scaleIncrement);
|
||||
|
||||
button.setForeground(entering ? Options.BUTTON_HOVER_COLOR : originalColor);
|
||||
button.setFont(originalFont.deriveFont(originalFont.getSize2D() * currentScale));
|
||||
|
||||
step++;
|
||||
if (step >= Options.ANIMATION_STEPS) {
|
||||
((Timer) e.getSource()).stop();
|
||||
if (!entering) {
|
||||
button.setFont(originalFont); // Restore the original font
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.ButtonHoverAnimator;
|
||||
import fr.monkhanny.dorfromantik.utils.MusicPlayer;
|
||||
import fr.monkhanny.dorfromantik.enums.Sounds;
|
||||
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class ButtonHoverListener extends MouseAdapter {
|
||||
|
||||
private final ButtonHoverAnimator animator;
|
||||
|
||||
public ButtonHoverListener(ButtonHoverAnimator animator) {
|
||||
this.animator = animator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
animator.startAnimation(true);
|
||||
MusicPlayer.loadSound(Sounds.SOUNDS1); // Charge le son
|
||||
MusicPlayer.playSound(); // Joue le son
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
animator.startAnimation(false);
|
||||
}
|
||||
}
|
115
src/fr/monkhanny/dorfromantik/controller/GameModeController.java
Normal file
@@ -0,0 +1,115 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.GameModeSelectionPanel;
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
import fr.monkhanny.dorfromantik.game.Board;
|
||||
import fr.monkhanny.dorfromantik.utils.Database;
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.JFrame;
|
||||
import java.sql.SQLException;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Point;
|
||||
|
||||
public class GameModeController implements ActionListener {
|
||||
|
||||
private GameModeSelectionPanel gameModeSelectionPanel;
|
||||
private JFrame gameFrame;
|
||||
private MainMenu mainMenu;
|
||||
private Database database;
|
||||
private JFrame gameModeFrame;
|
||||
private static Board board;
|
||||
|
||||
// Constructeur sans le panneau
|
||||
public GameModeController(JFrame gameFrame, MainMenu mainMenu, JFrame gameModeFrame) {
|
||||
this.gameFrame = gameFrame;
|
||||
this.mainMenu = mainMenu;
|
||||
this.gameModeFrame = gameModeFrame;
|
||||
|
||||
// Connexion à la base de données
|
||||
try {
|
||||
this.database = new Database();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Erreur lors de la connexion à la base de données: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Méthode pour associer le panneau
|
||||
public void setGameModeSelectionPanel(GameModeSelectionPanel panel) {
|
||||
this.gameModeSelectionPanel = panel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String command = e.getActionCommand();
|
||||
|
||||
switch (command) {
|
||||
case "Mode 1":
|
||||
startGame("Mode 1", getSeedFromDatabaseByName("Mode 1"));
|
||||
break;
|
||||
case "Mode 2":
|
||||
startGame("Mode 2", getSeedFromDatabaseByName("Mode 2"));
|
||||
break;
|
||||
case "Mode 3":
|
||||
startGame("Mode 3", getSeedFromDatabaseByName("Mode 3"));
|
||||
break;
|
||||
case "Mode 4":
|
||||
startGame("Mode 4", getSeedFromDatabaseByName("Mode 4"));
|
||||
break;
|
||||
case "Démarrer":
|
||||
long seed = gameModeSelectionPanel.getLongSeed();
|
||||
startGame("Custom Mode", seed);
|
||||
addCustomSeedToDatabase("Custom Mode", seed);
|
||||
break;
|
||||
default:
|
||||
System.out.println("Commande inconnue: " + command);
|
||||
}
|
||||
}
|
||||
|
||||
private long getSeedFromDatabaseByName(String modeName) {
|
||||
try {
|
||||
Options.SEED = this.database.getSeedByName(modeName);
|
||||
return Options.SEED;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return -1; // Retourner une valeur par défaut si une erreur survient
|
||||
}
|
||||
}
|
||||
|
||||
private void addCustomSeedToDatabase(String name, long seed) {
|
||||
try {
|
||||
Options.SEED = seed;
|
||||
this.database.addCustomSeed(name, seed);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
System.err.println("Erreur lors de l'ajout de la seed custom.");
|
||||
}
|
||||
}
|
||||
|
||||
private void startGame(String mode, long seed) {
|
||||
// Supprimer la potentielle ancienne instance de board
|
||||
GameModeController.board = null;
|
||||
|
||||
// Cacher la fenêtre avant de faire des modifications
|
||||
this.gameFrame.setVisible(false);
|
||||
|
||||
if (Options.FULL_SCREEN) {
|
||||
gameFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); // Set frame to full screen
|
||||
} else {
|
||||
Dimension mainMenuSize = this.mainMenu.getSize();
|
||||
Point mainMenuLocation = this.mainMenu.getLocation();
|
||||
gameFrame.setSize(mainMenuSize);
|
||||
gameFrame.setLocation(mainMenuLocation);
|
||||
}
|
||||
GameModeController.board = new Board(this.gameFrame,seed);
|
||||
//this.gameModeFrame.setVisible(false);
|
||||
this.gameFrame.setVisible(true);
|
||||
this.gameFrame.add(board);
|
||||
}
|
||||
|
||||
public static Board getGameModeBoard() {
|
||||
return board;
|
||||
}
|
||||
}
|
@@ -0,0 +1,132 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||
import fr.monkhanny.dorfromantik.gui.ButtonPanel;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Point;
|
||||
|
||||
|
||||
|
||||
public class MainMenuButtonController implements ActionListener {
|
||||
|
||||
private MainMenu mainMenu;
|
||||
|
||||
private JFrame settingsFrame;
|
||||
private JFrame howToPlayFrame;
|
||||
private JFrame gameModeFrame;
|
||||
private JFrame gameFrame;
|
||||
private JFrame rewardsFrame;
|
||||
|
||||
public MainMenuButtonController(MainMenu mainMenu, JFrame settingsFrame, JFrame howToPlayFrame, JFrame gameModeFrame, JFrame gameFrame, JFrame rewardsFrame) {
|
||||
this.mainMenu = mainMenu;
|
||||
// Ajouter les écouteurs d'événements sur les boutons
|
||||
ButtonPanel buttonPanel = mainMenu.getButtonPanel();
|
||||
|
||||
// Attacher les actions aux boutons du menu principal
|
||||
buttonPanel.getNewGameButton().addActionListener(this);
|
||||
buttonPanel.getContinueGameButton().addActionListener(this);
|
||||
buttonPanel.getHowToPlayButton().addActionListener(this);
|
||||
buttonPanel.getSettingsButton().addActionListener(this);
|
||||
buttonPanel.getExitButton().addActionListener(this);
|
||||
|
||||
// Paramètrage de la fenêtre des paramètres
|
||||
this.settingsFrame = settingsFrame;
|
||||
configureFrame(this.settingsFrame);
|
||||
|
||||
// Paramètrage de la fenêtre du tutoriel
|
||||
this.howToPlayFrame = howToPlayFrame;
|
||||
configureFrame(this.howToPlayFrame);
|
||||
|
||||
// Paramètrage de la fenêtre du jeu
|
||||
this.gameModeFrame = gameModeFrame;
|
||||
configureFrame(this.gameModeFrame);
|
||||
|
||||
// Paramètrage de la fenêtre du jeu
|
||||
this.gameFrame = gameFrame;
|
||||
configureFrame(this.gameFrame);
|
||||
|
||||
// Paramètrage de la fenêtre des récompenses
|
||||
this.rewardsFrame = rewardsFrame;
|
||||
configureFrame(this.rewardsFrame);
|
||||
}
|
||||
|
||||
private void configureFrame(JFrame frame) {
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setVisible(false);
|
||||
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String command = e.getActionCommand();
|
||||
|
||||
switch (command) {
|
||||
case "Jouer":
|
||||
startNewGame();
|
||||
break;
|
||||
case "Récompenses":
|
||||
openRecompense();
|
||||
break;
|
||||
case "Comment jouer ?":
|
||||
showHowToPlay();
|
||||
break;
|
||||
case "Paramètres":
|
||||
openSettings();
|
||||
break;
|
||||
case "Quitter":
|
||||
exitGame();
|
||||
break;
|
||||
default:
|
||||
System.out.println("Commande inconnue: " + command);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void startNewGame() {
|
||||
adjustFrameDisplay(this.gameModeFrame);
|
||||
this.mainMenu.setVisible(false);
|
||||
this.gameModeFrame.setVisible(true);
|
||||
}
|
||||
|
||||
private void openRecompense() {
|
||||
adjustFrameDisplay(this.rewardsFrame);
|
||||
this.mainMenu.setVisible(false);
|
||||
this.rewardsFrame.setVisible(true);
|
||||
}
|
||||
|
||||
public void showHowToPlay() {
|
||||
adjustFrameDisplay(this.howToPlayFrame);
|
||||
this.mainMenu.setVisible(false);
|
||||
this.howToPlayFrame.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
private void exitGame() {
|
||||
System.exit(0); // Fermer l'application
|
||||
}
|
||||
|
||||
private void openSettings() {
|
||||
adjustFrameDisplay(this.settingsFrame);
|
||||
this.mainMenu.setVisible(false);
|
||||
this.settingsFrame.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
private void adjustFrameDisplay(JFrame frame) {
|
||||
boolean wasVisible = frame.isVisible(); // Vérifier si la fenêtre était déjà visible
|
||||
|
||||
if(!wasVisible){
|
||||
// Récupérer la taille et la position de la fenêtre du menu principal
|
||||
Dimension mainMenuSize = this.mainMenu.getSize();
|
||||
Point mainMenuLocation = this.mainMenu.getLocation();
|
||||
frame.setSize(mainMenuSize);
|
||||
frame.setLocation(mainMenuLocation);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package fr.monkhanny.dorfromantik.controller;
|
||||
|
||||
import fr.monkhanny.dorfromantik.gui.ButtonPanel;
|
||||
import fr.monkhanny.dorfromantik.gui.ButtonHoverAnimator;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class MainMenuMouseController {
|
||||
|
||||
private final ButtonPanel buttonPanel;
|
||||
|
||||
public MainMenuMouseController(ButtonPanel buttonPanel) {
|
||||
this.buttonPanel = buttonPanel;
|
||||
initMouseListeners();
|
||||
}
|
||||
|
||||
private void initMouseListeners() {
|
||||
addButtonHoverListener(buttonPanel.getNewGameButton());
|
||||
addButtonHoverListener(buttonPanel.getContinueGameButton());
|
||||
addButtonHoverListener(buttonPanel.getHowToPlayButton());
|
||||
addButtonHoverListener(buttonPanel.getSettingsButton());
|
||||
addButtonHoverListener(buttonPanel.getExitButton());
|
||||
}
|
||||
|
||||
private void addButtonHoverListener(JButton button) {
|
||||
ButtonHoverAnimator animator = new ButtonHoverAnimator(button);
|
||||
button.addMouseListener(new ButtonHoverListener(animator));
|
||||
}
|
||||
}
|