diff --git a/TestV1/Makefile b/TestV1/Makefile new file mode 100644 index 0000000..5395157 --- /dev/null +++ b/TestV1/Makefile @@ -0,0 +1,41 @@ +PACKAGE = fr.monkhanny.dorfromantik +ENTRY = Main +SOURCEDIR = ./src/fr/monkhanny/dorfromantik/ +BUILDDIR = ./build/ +DOCDIR = ./doc/ +JARNAME = dorfromantik.jar +CLASSP = libs/* +MANIFESTPATH = Manifest.MF +SOURCEDIR = ./src/ + +SOURCES := $(shell find $(SOURCEDIR) -name '*.java') + +all: + @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 -jar $(JARNAME) + @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." diff --git a/TestV1/Manifest.MF b/TestV1/Manifest.MF new file mode 100644 index 0000000..bb6606d --- /dev/null +++ b/TestV1/Manifest.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: fr.monkhanny.dorfromantik.Main +Class-Path: libs/mariadb-client.jar \ No newline at end of file diff --git a/TestV1/TestEnAttendantResolutionBug/Main.java b/TestV1/TestEnAttendantResolutionBug/Main.java new file mode 100644 index 0000000..baeb594 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/Main.java @@ -0,0 +1,20 @@ +import model.Game; +import view.GameView; +import controller.GameController; + +import javax.swing.*; + +public class Main { + public static void main(String[] args) { + SwingUtilities.invokeLater(() -> { + Game game = new Game(); + GameView gameView = new GameView(game); // Crée la vue sans contrôleur pour le moment + GameController controller = new GameController(game, gameView); // Initialise le contrôleur avec game et gameView + + // Passe ensuite le contrôleur à la vue une fois que tout est initialisé + gameView.setController(controller); + + gameView.setVisible(true); // Affiche la fenêtre + }); + } +} diff --git a/TestV1/TestEnAttendantResolutionBug/View/BoardView.java b/TestV1/TestEnAttendantResolutionBug/View/BoardView.java new file mode 100644 index 0000000..8757694 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/View/BoardView.java @@ -0,0 +1,61 @@ +package view; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import model.Board; +import model.Tile; +import controller.GameController; + +public class BoardView extends JPanel { + private GameController controller; + private int rows = 5; + private int cols = 5; + + public BoardView(Board board, GameController controller) { + this.controller = controller; + setLayout(new GridLayout(rows, cols, 5, 5)); + initializeBoard(); + } + + // Méthode pour assigner le contrôleur après création de l'instance + public void setController(GameController controller) { + this.controller = controller; + } + + private void initializeBoard() { + for (int i = 0; i < rows * cols; i++) { + JPanel tilePanel = new JPanel(); + tilePanel.setBackground(Color.LIGHT_GRAY); + tilePanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); + + tilePanel.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + handleTilePlacement(tilePanel); + } + }); + + add(tilePanel); + } + } + + private void handleTilePlacement(JPanel tilePanel) { + if (controller != null) { // Assure que le contrôleur est bien assigné + Tile tile = controller.getNextTile(); + if (tile != null) { + tilePanel.setBackground(Color.GREEN); + tilePanel.add(new JLabel(tile.getType())); + revalidate(); + repaint(); + controller.placeTile(tile); + } + } + } + + public void refreshBoard() { + revalidate(); + repaint(); + } +} diff --git a/TestV1/TestEnAttendantResolutionBug/View/GameController.java b/TestV1/TestEnAttendantResolutionBug/View/GameController.java new file mode 100644 index 0000000..0b3fe7c --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/View/GameController.java @@ -0,0 +1,31 @@ +package controller; + +import model.Game; +import model.Tile; +import view.GameView; + +public class GameController { + private Game game; + private GameView gameView; + private Tile currentTile; + + public GameController(Game game, GameView gameView) { + this.game = game; + this.gameView = gameView; + this.currentTile = null; // Initialise sans tuile au début + } + + public void selectNextTile(Tile tile) { + this.currentTile = tile; + } + + public Tile getNextTile() { + return currentTile; // Retourne la tuile actuellement sélectionnée + } + + public void placeTile(Tile tile) { + game.placeTile(tile); + gameView.update(game); + currentTile = null; // Réinitialise après placement + } +} diff --git a/TestV1/TestEnAttendantResolutionBug/View/GameView.java b/TestV1/TestEnAttendantResolutionBug/View/GameView.java new file mode 100644 index 0000000..99c91e4 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/View/GameView.java @@ -0,0 +1,52 @@ +package view; + +import model.Game; +import model.Tile; +import controller.GameController; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class GameView extends JFrame { + private JLabel scoreLabel; + private BoardView boardView; + private GameController controller; // Ajoute le contrôleur ici + + public GameView(Game game) { // Constructeur sans le contrôleur en paramètre + setTitle("Dorfromantik en Java"); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setSize(500, 500); + setLayout(new BorderLayout()); + + scoreLabel = new JLabel("Score : " + game.getScore()); + boardView = new BoardView(game.getBoard(), null); // Initialise BoardView sans contrôleur + + JButton nextTileButton = new JButton("Sélectionner une tuile"); + nextTileButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (controller != null) { // Vérifie que le contrôleur est bien assigné + Tile tile = new Tile("forêt", new String[]{"terre", "terre", "eau", "terre", "eau", "terre"}); + controller.selectNextTile(tile); + } + } + }); + + add(scoreLabel, BorderLayout.NORTH); + add(boardView, BorderLayout.CENTER); + add(nextTileButton, BorderLayout.SOUTH); + } + + // Nouvelle méthode setController pour permettre d'assigner le contrôleur après création + public void setController(GameController controller) { + this.controller = controller; + boardView.setController(controller); // Passe le contrôleur à BoardView + } + + public void update(Game game) { + scoreLabel.setText("Score : " + game.getScore()); + boardView.refreshBoard(); + } +} diff --git a/TestV1/TestEnAttendantResolutionBug/controller/GameController.java b/TestV1/TestEnAttendantResolutionBug/controller/GameController.java new file mode 100644 index 0000000..4b08d39 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/controller/GameController.java @@ -0,0 +1,20 @@ +package controller; + +import model.Game; +import model.Tile; +import view.GameView; + +public class GameController { + private Game game; + private GameView gameView; + + public GameController(Game game, GameView gameView) { + this.game = game; + this.gameView = gameView; + } + + public void placeTile(Tile tile) { + game.placeTile(tile); + gameView.update(game); + } +} diff --git a/TestV1/TestEnAttendantResolutionBug/model/Board.java b/TestV1/TestEnAttendantResolutionBug/model/Board.java new file mode 100644 index 0000000..b5e26f2 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/model/Board.java @@ -0,0 +1,26 @@ +package model; + +import java.util.ArrayList; +import java.util.List; + +public class Board { + private List tiles; + + public Board() { + tiles = new ArrayList<>(); + } + + public void addTile(Tile tile) { + tiles.add(tile); + } + + public List getTiles() { + return tiles; + } + + public boolean isPlacementValid(Tile tile) { + // Logique simplifiée pour vérifier si la tuile peut être placée + // Ici, tu pourrais vérifier les bords de la tuile et du plateau + return true; // Retourne true pour simplifier + } +} diff --git a/TestV1/TestEnAttendantResolutionBug/model/Game.java b/TestV1/TestEnAttendantResolutionBug/model/Game.java new file mode 100644 index 0000000..5cf832a --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/model/Game.java @@ -0,0 +1,26 @@ +package model; + +public class Game { + private Board board; + private int score; + + public Game() { + board = new Board(); + score = 0; + } + + public Board getBoard() { + return board; + } + + public int getScore() { + return score; + } + + public void placeTile(Tile tile) { + if (board.isPlacementValid(tile)) { + board.addTile(tile); + score += 10; // Par exemple, chaque tuile ajoute 10 points + } + } +} diff --git a/TestV1/TestEnAttendantResolutionBug/model/Tile.java b/TestV1/TestEnAttendantResolutionBug/model/Tile.java new file mode 100644 index 0000000..f175519 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/model/Tile.java @@ -0,0 +1,19 @@ +package model; + +public class Tile { + private String type; // Par exemple : "forêt", "rivière", "champ", etc. + private String[] edges; // Les types des bords de la tuile (ex: "eau", "terre") + + public Tile(String type, String[] edges) { + this.type = type; + this.edges = edges; + } + + public String getType() { + return type; + } + + public String getEdge(int index) { + return edges[index]; + } +} diff --git a/TestV1/TestEnAttendantResolutionBug/view/BoardView.java b/TestV1/TestEnAttendantResolutionBug/view/BoardView.java new file mode 100644 index 0000000..e81065b --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/view/BoardView.java @@ -0,0 +1,24 @@ +package view; + +import javax.swing.*; +import model.Board; +import model.Tile; +import java.awt.*; + +public class BoardView extends JPanel { + private Board board; + + public BoardView(Board board) { + this.board = board; + setLayout(new GridLayout(5, 5, 5, 5)); // Exemple de grille 5x5 pour le plateau + } + + public void refreshBoard() { + removeAll(); + for (Tile tile : board.getTiles()) { + add(new TileView(tile.getType())); + } + revalidate(); + repaint(); + } +} diff --git a/TestV1/TestEnAttendantResolutionBug/view/GameView.java b/TestV1/TestEnAttendantResolutionBug/view/GameView.java new file mode 100644 index 0000000..4028ecb --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/view/GameView.java @@ -0,0 +1,28 @@ +package view; + +import model.Game; +import javax.swing.*; +import java.awt.*; + +public class GameView extends JFrame { + private JLabel scoreLabel; + private BoardView boardView; + + public GameView(Game game) { + setTitle("Dorfromantik en Java"); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setSize(400, 400); + setLayout(new BorderLayout()); + + scoreLabel = new JLabel("Score : " + game.getScore()); + boardView = new BoardView(game.getBoard()); + + add(scoreLabel, BorderLayout.NORTH); + add(boardView, BorderLayout.CENTER); + } + + public void update(Game game) { + scoreLabel.setText("Score : " + game.getScore()); + boardView.refreshBoard(); + } +} diff --git a/TestV1/TestEnAttendantResolutionBug/view/TileView.java b/TestV1/TestEnAttendantResolutionBug/view/TileView.java new file mode 100644 index 0000000..b5bf724 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/view/TileView.java @@ -0,0 +1,21 @@ +package view; + +import javax.swing.*; +import java.awt.*; + +public class TileView extends JPanel { + private String type; + + public TileView(String type) { + this.type = type; + setPreferredSize(new Dimension(50, 50)); // Taille de la tuile + setBackground(Color.LIGHT_GRAY); + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + g.setColor(Color.BLACK); + g.drawString(type, 10, 25); // Affiche le type de la tuile au centre + } +} diff --git a/TestV1/res/fond-ecran.jpg!d b/TestV1/res/fond-ecran.jpg!d deleted file mode 100644 index bf76a95..0000000 Binary files a/TestV1/res/fond-ecran.jpg!d and /dev/null differ diff --git a/TestV1/ressources/fonts/Contage-Black-Italic-BF63fc29ba63509.ttf b/TestV1/ressources/fonts/Contage-Black-Italic-BF63fc29ba63509.ttf new file mode 100644 index 0000000..4f23744 Binary files /dev/null and b/TestV1/ressources/fonts/Contage-Black-Italic-BF63fc29ba63509.ttf differ diff --git a/TestV1/ressources/fonts/Contage-Black.ttf b/TestV1/ressources/fonts/Contage-Black.ttf new file mode 100644 index 0000000..47495ef Binary files /dev/null and b/TestV1/ressources/fonts/Contage-Black.ttf differ diff --git a/TestV1/ressources/fonts/Contage-Bold-BF63fc29ba8dac9.ttf b/TestV1/ressources/fonts/Contage-Bold-BF63fc29ba8dac9.ttf new file mode 100644 index 0000000..ce95431 Binary files /dev/null and b/TestV1/ressources/fonts/Contage-Bold-BF63fc29ba8dac9.ttf differ diff --git a/TestV1/ressources/fonts/Contage-Bold-Italic-BF63fc29ba7e1fc.ttf b/TestV1/ressources/fonts/Contage-Bold-Italic-BF63fc29ba7e1fc.ttf new file mode 100644 index 0000000..12d8c24 Binary files /dev/null and b/TestV1/ressources/fonts/Contage-Bold-Italic-BF63fc29ba7e1fc.ttf differ diff --git a/TestV1/ressources/fonts/Contage-Light-BF63fc29bb66d25.ttf b/TestV1/ressources/fonts/Contage-Light-BF63fc29bb66d25.ttf new file mode 100644 index 0000000..3da4da9 Binary files /dev/null and b/TestV1/ressources/fonts/Contage-Light-BF63fc29bb66d25.ttf differ diff --git a/TestV1/ressources/fonts/Contage-Light-Italic-BF63fc29ba81b18.ttf b/TestV1/ressources/fonts/Contage-Light-Italic-BF63fc29ba81b18.ttf new file mode 100644 index 0000000..b6171a2 Binary files /dev/null and b/TestV1/ressources/fonts/Contage-Light-Italic-BF63fc29ba81b18.ttf differ diff --git a/TestV1/ressources/fonts/Contage-Medium-BF63fc29bae1bb5.ttf b/TestV1/ressources/fonts/Contage-Medium-BF63fc29bae1bb5.ttf new file mode 100644 index 0000000..387468c Binary files /dev/null and b/TestV1/ressources/fonts/Contage-Medium-BF63fc29bae1bb5.ttf differ diff --git a/TestV1/ressources/fonts/Contage-Medium-Italic-BF63fc29b9cd284.ttf b/TestV1/ressources/fonts/Contage-Medium-Italic-BF63fc29b9cd284.ttf new file mode 100644 index 0000000..e6b5198 Binary files /dev/null and b/TestV1/ressources/fonts/Contage-Medium-Italic-BF63fc29b9cd284.ttf differ diff --git a/TestV1/ressources/fonts/Contage-Regular-Italic-BF63fc29b846c83.ttf b/TestV1/ressources/fonts/Contage-Regular-Italic-BF63fc29b846c83.ttf new file mode 100644 index 0000000..513d0f4 Binary files /dev/null and b/TestV1/ressources/fonts/Contage-Regular-Italic-BF63fc29b846c83.ttf differ diff --git a/TestV1/ressources/fonts/Contage-Regular.ttf b/TestV1/ressources/fonts/Contage-Regular.ttf new file mode 100644 index 0000000..aca216b Binary files /dev/null and b/TestV1/ressources/fonts/Contage-Regular.ttf differ diff --git a/TestV1/ressources/fonts/Contage-Semi-Light-BF63fc29ba776e9.ttf b/TestV1/ressources/fonts/Contage-Semi-Light-BF63fc29ba776e9.ttf new file mode 100644 index 0000000..1404aed Binary files /dev/null and b/TestV1/ressources/fonts/Contage-Semi-Light-BF63fc29ba776e9.ttf differ diff --git a/TestV1/ressources/fonts/Contage-Semi-Light-Italic-BF63fc29b8477f8.ttf b/TestV1/ressources/fonts/Contage-Semi-Light-Italic-BF63fc29b8477f8.ttf new file mode 100644 index 0000000..7754d50 Binary files /dev/null and b/TestV1/ressources/fonts/Contage-Semi-Light-Italic-BF63fc29b8477f8.ttf differ diff --git a/TestV1/ressources/images/Application/Application_Icon.jpg b/TestV1/ressources/images/Application/Application_Icon.jpg new file mode 100644 index 0000000..45a1621 Binary files /dev/null and b/TestV1/ressources/images/Application/Application_Icon.jpg differ diff --git a/TestV1/ressources/images/MainMenu/background.jpg b/TestV1/ressources/images/MainMenu/background.jpg new file mode 100644 index 0000000..e788cf5 Binary files /dev/null and b/TestV1/ressources/images/MainMenu/background.jpg differ diff --git a/TestV1/ressources/images/MainMenu/backgroundBlured.jpg b/TestV1/ressources/images/MainMenu/backgroundBlured.jpg new file mode 100644 index 0000000..fa9808e Binary files /dev/null and b/TestV1/ressources/images/MainMenu/backgroundBlured.jpg differ diff --git a/TestV1/ressources/images/Settings/speaker-high-volume.png b/TestV1/ressources/images/Settings/speaker-high-volume.png new file mode 100644 index 0000000..34f36e9 Binary files /dev/null and b/TestV1/ressources/images/Settings/speaker-high-volume.png differ diff --git a/TestV1/ressources/images/Settings/speaker-mute-volume.png b/TestV1/ressources/images/Settings/speaker-mute-volume.png new file mode 100644 index 0000000..5ebcb07 Binary files /dev/null and b/TestV1/ressources/images/Settings/speaker-mute-volume.png differ diff --git a/TestV1/ressources/sounds/Music/mainMenuMusic.wav b/TestV1/ressources/sounds/Music/mainMenuMusic.wav new file mode 100644 index 0000000..f00f883 Binary files /dev/null and b/TestV1/ressources/sounds/Music/mainMenuMusic.wav differ diff --git a/TestV1/ressources/sounds/SFX/1.wav b/TestV1/ressources/sounds/SFX/1.wav new file mode 100644 index 0000000..b27c353 Binary files /dev/null and b/TestV1/ressources/sounds/SFX/1.wav differ diff --git a/TestV1/src/Controller/MenuController.java b/TestV1/src/Controller/MenuController.java deleted file mode 100644 index eeb1df2..0000000 --- a/TestV1/src/Controller/MenuController.java +++ /dev/null @@ -1,36 +0,0 @@ -package Controller; // Spécifie que cette classe fait partie du package Controller - -import Model.MenuModel; // Importer la classe MenuModel -import View.MenuView; - -import javax.swing.*; - -public class MenuController { - private MenuModel model; - private MenuView view; - - public MenuController(MenuModel model, MenuView view) { - this.model = model; - this.view = view; - } - - public void run() { - view.setVisible(true); - } - - public static void main(String[] args) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - // Initialiser le modèle avec le chemin de l'image - MenuModel model = new MenuModel("../res/fond-ecran.jpg"); - - // Créer la vue en lui passant l'image de fond - MenuView view = new MenuView(model); - - // Démarrer le contrôleur - new MenuController(model, view).run(); - } - }); - } -} diff --git a/TestV1/src/Makefile b/TestV1/src/Makefile deleted file mode 100644 index 2528e43..0000000 --- a/TestV1/src/Makefile +++ /dev/null @@ -1,62 +0,0 @@ -### VARIABLES ### - -JC = javac -JCFLAGS = -encoding UTF-8 -implicit:none - -JVM = java -JVMFLAGS = - -# Chemins des dossiers -SRC_CONTROLLER = Controller -SRC_MODEL = Model -SRC_VIEW = View - -# Cibles pour chaque fichier .class avec leurs chemins respectifs -CONTROLLER_CLASS = $(SRC_CONTROLLER)/MenuController.class -MODEL_CLASS = $(SRC_MODEL)/MenuModel.class -VIEW_CLASS = $(SRC_VIEW)/MenuView.class -PANEL_CLASS = $(SRC_VIEW)/PanneauImage.class -TITRE_CLASS = $(SRC_VIEW)/TitreView.class -BOUTON_CLASS = $(SRC_VIEW)/BoutonView.class -### REGLES ESSENTIELLES ### - -# Règle pour compiler MenuController -$(CONTROLLER_CLASS): $(SRC_CONTROLLER)/MenuController.java $(MODEL_CLASS) $(VIEW_CLASS) $(PANEL_CLASS) $(TITRE_CLASS) $(BOUTON_CLASS) - ${JC} ${JCFLAGS} -d . $(SRC_CONTROLLER)/MenuController.java - -# Règle pour compiler MenuModel -$(MODEL_CLASS): $(SRC_MODEL)/MenuModel.java - ${JC} ${JCFLAGS} -d . $(SRC_MODEL)/MenuModel.java - -# Règle pour compiler MenuView -$(VIEW_CLASS): $(SRC_VIEW)/MenuView.java $(PANEL_CLASS) $(TITRE_CLASS) $(BOUTON_CLASS) - ${JC} ${JCFLAGS} -d . $(SRC_VIEW)/MenuView.java - -# Règle pour compiler PanneauImage -$(PANEL_CLASS): $(SRC_VIEW)/PanneauImage.java - ${JC} ${JCFLAGS} -d . $(SRC_VIEW)/PanneauImage.java - -# Règle pour compiler TitreView -$(TITRE_CLASS): $(SRC_VIEW)/TitreView.java # Règle pour compiler TitreView - ${JC} ${JCFLAGS} -d . $(SRC_VIEW)/TitreView.java - -# Règle pour compiler BoutonView -$(TITRE_CLASS): $(SRC_VIEW)/BoutonView.java # Règle pour compiler TitreView - ${JC} ${JCFLAGS} -d . $(SRC_VIEW)/BoutonView.java - -### REGLES OPTIONNELLES ### - -# Règle pour exécuter l'application -run: $(CONTROLLER_CLASS) - ${JVM} ${JVMFLAGS} Controller.MenuController - -# Règle pour nettoyer les fichiers .class -clean: - -rm -f $(SRC_CONTROLLER)/*.class $(SRC_MODEL)/*.class $(SRC_VIEW)/*.class - -# Règle pour tout nettoyer et recompiler -mrproper: clean $(CONTROLLER_CLASS) - -### BUTS FACTICES ### - -.PHONY: run clean mrproper diff --git a/TestV1/src/Menu.java b/TestV1/src/Menu.java deleted file mode 100644 index 53b4cfa..0000000 --- a/TestV1/src/Menu.java +++ /dev/null @@ -1,50 +0,0 @@ -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; -import java.io.IOException; -import javax.imageio.ImageIO; - -public class Menu extends JFrame { - - private Image imageDeFond; - - public Menu() { - // Charge l'image de fond - try { - imageDeFond = ImageIO.read(new File("../res/fond-ecran.jpg!d")); - } catch (IOException e) { - e.printStackTrace(); - } - - // Configuration de la fenêtre - setTitle(" Dorfromantik"); - setSize(800, 600); // Taille de la fenêtre - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setLocationRelativeTo(null); - - // Ajouter le panneau avec image de fond - setContentPane(new PanneauImage()); - } - - // Classe interne pour le panneau personnalisé qui dessine l'image en fond - class PanneauImage extends JPanel { - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - if (imageDeFond != null) { - g.drawImage(imageDeFond, 0, 0, getWidth(), getHeight(), this); - } - } - } - - public static void main(String[] args) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - new Menu().setVisible(true); - } - }); - } -} diff --git a/TestV1/src/Model/MenuModel.java b/TestV1/src/Model/MenuModel.java deleted file mode 100644 index b2ab41d..0000000 --- a/TestV1/src/Model/MenuModel.java +++ /dev/null @@ -1,23 +0,0 @@ -package Model; - -import java.awt.Image; -import java.io.File; -import java.io.IOException; -import javax.imageio.ImageIO; - -public class MenuModel { - private Image imageDeFond; - - public MenuModel(String imagePath) { - // Charger l'image de fond - try { - imageDeFond = ImageIO.read(new File("../res/fond-ecran.jpg!d")); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public Image getImageDeFond() { - return imageDeFond; - } -} diff --git a/TestV1/src/View/BoutonView.java b/TestV1/src/View/BoutonView.java deleted file mode 100644 index 8645a09..0000000 --- a/TestV1/src/View/BoutonView.java +++ /dev/null @@ -1,19 +0,0 @@ -package View; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionListener; - -public class BoutonView extends JButton { - public BoutonView(String texte) { - super(texte); - - setFont(new Font("Arial", Font.BOLD, 40)); - setForeground(Color.WHITE); // Couleur du texte blanc - setFocusPainted(false); // Enlever le focus sur le bouton - setBorderPainted(false); // Enlever la bordure par défaut - setContentAreaFilled(false); // Fond transparent - setOpaque(false); // Ne dessine pas le fond par défaut - - } -} diff --git a/TestV1/src/View/MenuView.java b/TestV1/src/View/MenuView.java deleted file mode 100644 index 34a2d46..0000000 --- a/TestV1/src/View/MenuView.java +++ /dev/null @@ -1,51 +0,0 @@ -package View; - -import javax.swing.*; -import java.awt.*; -import Model.MenuModel; - -public class MenuView extends JFrame { - private PanneauImage panneauImage; - private TitreView titreView; - private BoutonView boutonJouer; - private BoutonView boutonCommentJouer; - private BoutonView boutonQuitter; - - public MenuView(MenuModel model) { - - setTitle("Dorfromantik"); - setSize(800, 600); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setLocationRelativeTo(null); - - panneauImage = new PanneauImage(model.getImageDeFond()); - setContentPane(panneauImage); - titreView = new TitreView(); - - JPanel panelTitre = new JPanel(new FlowLayout(FlowLayout.CENTER)); - panelTitre.setOpaque(false); - panelTitre.add(titreView.getTitre()); - - setLayout(new BorderLayout()); - add(panelTitre, BorderLayout.NORTH); - - JPanel panelBouton = new JPanel(); - panelBouton.setOpaque(false); // Panneau transparent pour ne pas couvrir l'image de fond - panelBouton.setLayout(new BoxLayout(panelBouton, BoxLayout.Y_AXIS)); // Disposition verticale - - // Initialisation des boutons - boutonJouer = new BoutonView("Jouer"); - boutonCommentJouer = new BoutonView("Comment Jouer ?"); - boutonQuitter = new BoutonView("Quitter"); - - panelBouton.add(boutonJouer); - panelBouton.add(Box.createVerticalStrut(10)); // Espace entre les boutons - panelBouton.add(boutonCommentJouer); - panelBouton.add(Box.createVerticalStrut(10)); // Espace entre les boutons - panelBouton.add(boutonQuitter); - - add(panelBouton, BorderLayout.SOUTH); - - setVisible(true); - } -} diff --git a/TestV1/src/View/PanneauImage.java b/TestV1/src/View/PanneauImage.java deleted file mode 100644 index 610c7d2..0000000 --- a/TestV1/src/View/PanneauImage.java +++ /dev/null @@ -1,20 +0,0 @@ -package View; - -import javax.swing.*; -import java.awt.*; - -public class PanneauImage extends JPanel { - private Image imageDeFond; - - public PanneauImage(Image image) { - this.imageDeFond = image; - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - if (imageDeFond != null) { - g.drawImage(imageDeFond, 0, 0, getWidth(), getHeight(), this); - } - } -} diff --git a/TestV1/src/View/TitreView.java b/TestV1/src/View/TitreView.java deleted file mode 100644 index 134a749..0000000 --- a/TestV1/src/View/TitreView.java +++ /dev/null @@ -1,68 +0,0 @@ -package View; - -import javax.swing.*; -import java.awt.*; - -public class TitreView { - private ContourLabel titre; - - public TitreView() { - // Créer une instance de ContourLabel avec le texte souhaité - titre = new ContourLabel("Dorfromantik"); - - // Définir la police et les couleurs - titre.setFont(new Font("Algerian", Font.BOLD, 70)); - titre.setForeground(Color.WHITE); // Couleur du texte principal - titre.setContourColor(Color.BLACK); // Couleur du contour - titre.setContourThickness(4); // Épaisseur du contour - } - - public JLabel getTitre() { - return titre; - } - - // Classe interne pour gérer le contour autour du texte - private static class ContourLabel extends JLabel { - private Color contourColor = Color.BLACK; - private int contourThickness = 2; - - public ContourLabel(String text) { - super(text); - } - - public void setContourColor(Color contourColor) { - this.contourColor = contourColor; - } - - public void setContourThickness(int contourThickness) { - this.contourThickness = contourThickness; - } - - @Override - protected void paintComponent(Graphics g) { - Graphics2D g2d = (Graphics2D) g.create(); - - // Activer l'anti-aliasing - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - - // Dessiner le contour - g2d.setFont(getFont()); - g2d.setColor(contourColor); - g2d.setStroke(new BasicStroke(contourThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); - FontMetrics fm = g2d.getFontMetrics(); - int x = 0; - int y = fm.getAscent(); - g2d.draw(getTextShape(g2d, getText(), x, y)); - - // Dessiner le texte principal - g2d.setColor(getForeground()); - g2d.fill(getTextShape(g2d, getText(), x, y)); - - g2d.dispose(); - } - - private Shape getTextShape(Graphics2D g2d, String text, int x, int y) { - return getFont().createGlyphVector(g2d.getFontRenderContext(), text).getOutline(x, y); - } - } -} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/Main.java b/TestV1/src/fr/monkhanny/dorfromantik/Main.java new file mode 100644 index 0000000..d121acf --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/Main.java @@ -0,0 +1,45 @@ +package fr.monkhanny.dorfromantik; + +import fr.monkhanny.dorfromantik.gui.MainMenu; +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.gui.SettingsPanel; + +import javax.swing.JFrame; + +/** + * Classe principale du jeu + * @version 1.0 + * @author Moncef STITI + * @see MainMenu + * @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"); + + // 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); + + + // 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); + + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/Options.java b/TestV1/src/fr/monkhanny/dorfromantik/Options.java new file mode 100644 index 0000000..e07f263 --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/Options.java @@ -0,0 +1,54 @@ +package fr.monkhanny.dorfromantik; + +import java.awt.Color; +import java.awt.Dimension; + +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(70, 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); +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/components/Button.java b/TestV1/src/fr/monkhanny/dorfromantik/components/Button.java new file mode 100644 index 0000000..75affe7 --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/components/Button.java @@ -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; + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/components/Title.java b/TestV1/src/fr/monkhanny/dorfromantik/components/Title.java new file mode 100644 index 0000000..86908ef --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/components/Title.java @@ -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)); + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/controller/ButtonHoverAnimationListener.java b/TestV1/src/fr/monkhanny/dorfromantik/controller/ButtonHoverAnimationListener.java new file mode 100644 index 0000000..59a4a18 --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/controller/ButtonHoverAnimationListener.java @@ -0,0 +1,43 @@ +package fr.monkhanny.dorfromantik.gui; + +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 + } + } + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/controller/ButtonHoverListener.java b/TestV1/src/fr/monkhanny/dorfromantik/controller/ButtonHoverListener.java new file mode 100644 index 0000000..fdce4fe --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/controller/ButtonHoverListener.java @@ -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); + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/controller/MainMenuButtonController.java b/TestV1/src/fr/monkhanny/dorfromantik/controller/MainMenuButtonController.java new file mode 100644 index 0000000..611d3ed --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/controller/MainMenuButtonController.java @@ -0,0 +1,99 @@ +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; +import java.awt.event.ActionListener; +import java.awt.Dimension; +import java.awt.Point; + +public class MainMenuButtonController implements ActionListener { + + private MainMenu mainMenu; + + private JFrame settingsFrame; + + public MainMenuButtonController(MainMenu mainMenu, JFrame settingsFrame) { + this.mainMenu = mainMenu; + // Ajouter les écouteurs d'événements sur les boutons + ButtonPanel buttonPanel = mainMenu.getButtonPanel(); + + // Attacher les actions aux boutons + 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 + this.settingsFrame = settingsFrame; + this.settingsFrame.setLocationRelativeTo(null); + this.settingsFrame.setVisible(false); + } + + @Override + public void actionPerformed(ActionEvent e) { + String command = e.getActionCommand(); + + switch (command) { + case "Nouvelle partie": + startNewGame(); + break; + case "Continuer une partie": + continueGame(); + break; + case "Comment jouer ?": + showHowToPlay(); + break; + case "Paramètres": + openSettings(); + break; + case "Quitter": + exitGame(); + break; + default: + System.out.println("Commande inconnue: " + command); + break; + } + } + + private void startNewGame() { + System.out.println("Démarrer une nouvelle partie..."); + // Logic to start a new game + } + + private void continueGame() { + System.out.println("Continuer une partie..."); + // Logic to continue the game + } + + private void showHowToPlay() { + System.out.println("Afficher comment jouer..."); + // Logic to show how to play + } + + private void exitGame() { + System.exit(0); // Fermer l'application + } + + 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 + this.mainMenu.setVisible(false); + + // Afficher la fenêtre des paramètres + this.settingsFrame.setVisible(true); + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/controller/MainMenuMouseController.java b/TestV1/src/fr/monkhanny/dorfromantik/controller/MainMenuMouseController.java new file mode 100644 index 0000000..1046af9 --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/controller/MainMenuMouseController.java @@ -0,0 +1,31 @@ +package fr.monkhanny.dorfromantik.controller; + +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 { + + 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)); + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/controller/MainMenuResizeController.java b/TestV1/src/fr/monkhanny/dorfromantik/controller/MainMenuResizeController.java new file mode 100644 index 0000000..f9219ce --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/controller/MainMenuResizeController.java @@ -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); + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/controller/MainMenuResizeHandler.java b/TestV1/src/fr/monkhanny/dorfromantik/controller/MainMenuResizeHandler.java new file mode 100644 index 0000000..742c16a --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/controller/MainMenuResizeHandler.java @@ -0,0 +1,31 @@ +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; +import javax.swing.JButton; + +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 + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/enums/Fonts.java b/TestV1/src/fr/monkhanny/dorfromantik/enums/Fonts.java new file mode 100644 index 0000000..1e3cc36 --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/enums/Fonts.java @@ -0,0 +1,18 @@ +package fr.monkhanny.dorfromantik.enums; + +import java.awt.Color; + +public enum Fonts { + TITLE, BUTTON; + + public String getFontPath() { + switch (this) { + case TITLE: + return "./ressources/fonts/Contage-Black.ttf"; + case BUTTON: + return "./ressources/fonts/Contage-Regular.ttf"; + default: + throw new IllegalArgumentException("Unexpected value: " + this); + } + } +} \ No newline at end of file diff --git a/TestV1/src/fr/monkhanny/dorfromantik/enums/Images.java b/TestV1/src/fr/monkhanny/dorfromantik/enums/Images.java new file mode 100644 index 0000000..86ecb05 --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/enums/Images.java @@ -0,0 +1,17 @@ +package fr.monkhanny.dorfromantik.enums; + + +public enum Images { + SETTINGS_ICON, EXIT_ICON; + + public String getImagePath() { + switch (this) { + case SETTINGS_ICON: + return "./ressources/images/Icone/SettingsIcon.png"; + case EXIT_ICON: + return "./ressources/images/Icone/ExitIcon.png"; + default: + throw new IllegalArgumentException("Unexpected value: " + this); + } + } +} \ No newline at end of file diff --git a/TestV1/src/fr/monkhanny/dorfromantik/enums/Musics.java b/TestV1/src/fr/monkhanny/dorfromantik/enums/Musics.java new file mode 100644 index 0000000..219f064 --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/enums/Musics.java @@ -0,0 +1,14 @@ +package fr.monkhanny.dorfromantik.enums; + +public enum Musics { + MAIN_MENU_MUSIC; + + public String getSoundsPath() { + switch (this) { + case MAIN_MENU_MUSIC: + return "./ressources/sounds/Music/mainMenuMusic.wav"; + default: + throw new IllegalArgumentException("Unexpected value: " + this); + } + } +} \ No newline at end of file diff --git a/TestV1/src/fr/monkhanny/dorfromantik/enums/Sounds.java b/TestV1/src/fr/monkhanny/dorfromantik/enums/Sounds.java new file mode 100644 index 0000000..772dac4 --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/enums/Sounds.java @@ -0,0 +1,16 @@ +package fr.monkhanny.dorfromantik.enums; + +public enum Sounds { + SOUNDS1, SOUNDS2; + + public String getSoundsPath() { + switch (this) { + case SOUNDS1: + return "./ressources/sounds/SFX/1.wav"; + case SOUNDS2: + return "./ressources/sounds/SFX/2.wav"; + default: + throw new IllegalArgumentException("Unexpected value: " + this); + } + } +} \ No newline at end of file diff --git a/TestV1/src/fr/monkhanny/dorfromantik/gui/ButtonHoverAnimator.java b/TestV1/src/fr/monkhanny/dorfromantik/gui/ButtonHoverAnimator.java new file mode 100644 index 0000000..9ee623f --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/gui/ButtonHoverAnimator.java @@ -0,0 +1,38 @@ +package fr.monkhanny.dorfromantik.gui; + +import fr.monkhanny.dorfromantik.Options; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class ButtonHoverAnimator { + + private final JButton button; + 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(); + } + + 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); + } + +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/gui/ButtonPanel.java b/TestV1/src/fr/monkhanny/dorfromantik/gui/ButtonPanel.java new file mode 100644 index 0000000..70f1dcc --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/gui/ButtonPanel.java @@ -0,0 +1,87 @@ +package fr.monkhanny.dorfromantik.gui; + +import fr.monkhanny.dorfromantik.utils.FontManager; +import fr.monkhanny.dorfromantik.components.Button; +import fr.monkhanny.dorfromantik.controller.MainMenuMouseController; + +import javax.swing.*; +import java.awt.*; +import java.util.List; +import java.util.Arrays; + + +public class ButtonPanel extends JPanel { + + private JButton newGameButton; + private JButton continueGameButton; + private JButton howToPlayButton; + private JButton settingsButton; + private JButton exitButton; + + public ButtonPanel(float fontSize) { + // Paramétrage de l'apparence du panneau + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + this.setOpaque(false); // Rendre le panneau transparent + this.setBorder(BorderFactory.createEmptyBorder(50, 30, 30, 30)); // Marge à gauche et en bas + + // Espacement vertical extensible pour centrer les boutons principaux verticalement + this.add(Box.createVerticalGlue()); + + // Créer les boutons avec un style personnalisé + newGameButton = Button.createCustomTextButton("Nouvelle partie", fontSize); + continueGameButton = Button.createCustomTextButton("Continuer une partie", fontSize); + howToPlayButton = Button.createCustomTextButton("Comment jouer ?", fontSize); + settingsButton = Button.createCustomTextButton("Paramètres", fontSize); + exitButton = Button.createCustomTextButton("Quitter", fontSize); + + // Ajouter les boutons au panneau + this.add(newGameButton); + this.add(Box.createVerticalStrut(10)); // Espace entre les boutons + this.add(continueGameButton); + this.add(Box.createVerticalStrut(10)); + this.add(howToPlayButton); + this.add(Box.createVerticalStrut(10)); + this.add(settingsButton); + this.add(Box.createVerticalStrut(10)); + this.add(exitButton); + + // Espacement extensible pour maintenir les icônes en bas + this.add(Box.createVerticalGlue()); + + MainMenuMouseController gestionSouris = new MainMenuMouseController(this); + } + + public JButton getNewGameButton() { + return newGameButton; + } + + public JButton getContinueGameButton() { + return continueGameButton; + } + + public JButton getHowToPlayButton() { + return howToPlayButton; + } + + public JButton getSettingsButton() { + return settingsButton; + } + + public JButton getExitButton() { + return exitButton; + } + + public List getButtons() { + return Arrays.asList(newGameButton, continueGameButton, howToPlayButton, settingsButton, exitButton); + } + + public void updateButtonFonts(int windowWidth) { + // Mettre à jour la police des boutons avec la taille ajustée + float newFontSize = windowWidth / 30f; + newGameButton.setFont(FontManager.getTitleFont(newFontSize)); + continueGameButton.setFont(FontManager.getTitleFont(newFontSize)); + howToPlayButton.setFont(FontManager.getTitleFont(newFontSize)); + settingsButton.setFont(FontManager.getTitleFont(newFontSize)); + exitButton.setFont(FontManager.getTitleFont(newFontSize)); + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/gui/MainMenu.java b/TestV1/src/fr/monkhanny/dorfromantik/gui/MainMenu.java new file mode 100644 index 0000000..ec2624b --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/gui/MainMenu.java @@ -0,0 +1,56 @@ +package fr.monkhanny.dorfromantik.gui; + +import fr.monkhanny.dorfromantik.utils.FontManager; +import fr.monkhanny.dorfromantik.utils.ImageLoader; +import fr.monkhanny.dorfromantik.enums.Fonts; +import fr.monkhanny.dorfromantik.components.Title; +import fr.monkhanny.dorfromantik.Options; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; + +public class MainMenu extends JFrame { + + private Title titleLabel; + private ButtonPanel buttonPanel; + + public MainMenu() { + // Charger les polices pour le titre et les boutons + FontManager.loadCustomFont(Fonts.TITLE); // Charge la police pour le titre + FontManager.loadCustomFont(Fonts.BUTTON); // Charge la police pour les boutons + + // Paramétrage de la fenêtre principale + this.setTitle("Dorfromantik - Menu Principal"); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + super.setIconImage(ImageLoader.APPLICATION_ICON); + this.setMinimumSize(Options.MINIMUM_FRAME_SIZE); + this.setSize(1200, 800); + this.setLocationRelativeTo(null); // Centrer la fenêtre + this.setLayout(new BorderLayout()); + + // Arrière plan du menu principal + JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/background.jpg")); + background.setLayout(new BorderLayout()); + this.setContentPane(background); + + // Ajouter le titre en haut au centre + this.titleLabel = new Title("Dorfromantik", Options.BASE_TITLE_FONT_SIZE); + background.add(titleLabel, BorderLayout.NORTH); + + // Panneau des boutons avec style personnalisé + this.buttonPanel = new ButtonPanel(Options.BASE_BUTTON_FONT_SIZE); + background.add(buttonPanel, BorderLayout.WEST); + + setVisible(true); + } + + public Title getTitleLabel() { + return titleLabel; + } + + public ButtonPanel getButtonPanel() { + return buttonPanel; + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/gui/SettingsPanel.java b/TestV1/src/fr/monkhanny/dorfromantik/gui/SettingsPanel.java new file mode 100644 index 0000000..3b78b06 --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/gui/SettingsPanel.java @@ -0,0 +1,142 @@ +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 javax.swing.*; +import java.awt.*; +import javax.swing.event.ChangeListener; + +public class SettingsPanel extends JPanel { + + private MainMenu mainMenu; + private JFrame settingsFrame; + + public SettingsPanel(MainMenu mainMenu, JFrame settingsFrame) { + this.mainMenu = mainMenu; + this.settingsFrame = settingsFrame; + + initializeSettingsFrame(); + setupBackground(); + setupMainPanel(); + } + + private void initializeSettingsFrame() { + settingsFrame.setMinimumSize(Options.MINIMUM_FRAME_SIZE); + } + + private void setupBackground() { + JLabel background = new JLabel(new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg")); + background.setLayout(new GridBagLayout()); + this.setLayout(new BorderLayout()); + this.add(background); + } + + 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; + } + + 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 createSoundPanel(String labelText, JSlider volumeSlider, ChangeListener sliderChangeListener, MuteCheckBoxListener muteCheckBoxListener) { + JPanel panel = new JPanel(new GridBagLayout()); + panel.setOpaque(false); + + GridBagConstraints gbc = new GridBagConstraints(); + gbc.insets = new Insets(10, 10, 10, 10); + gbc.gridx = 0; + + JCheckBox muteCheckBox = new JCheckBox(); + 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); + + 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); + + gbc.gridx++; + panel.add(createSliderPanel(volumeSlider), gbc); + + return panel; + } + + private JPanel createSliderPanel(JSlider volumeSlider) { + JPanel sliderPanel = new JPanel(new BorderLayout()); + sliderPanel.setOpaque(false); + + JLabel lowLabel = new JLabel("Low"); + lowLabel.setFont(new Font("Roboto", Font.PLAIN, 18)); + sliderPanel.add(lowLabel, BorderLayout.WEST); + + sliderPanel.add(volumeSlider, BorderLayout.CENTER); + + JLabel highLabel = new JLabel("High"); + highLabel.setFont(new Font("Roboto", Font.PLAIN, 18)); + sliderPanel.add(highLabel, BorderLayout.EAST); + + 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; + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/listeners/CloseButtonListener.java b/TestV1/src/fr/monkhanny/dorfromantik/listeners/CloseButtonListener.java new file mode 100644 index 0000000..70d2012 --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/listeners/CloseButtonListener.java @@ -0,0 +1,24 @@ +package fr.monkhanny.dorfromantik.listeners; + +import fr.monkhanny.dorfromantik.gui.MainMenu; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class CloseButtonListener implements ActionListener { + private MainMenu mainMenu; + private JFrame settingsFrame; + + public CloseButtonListener(MainMenu mainMenu, JFrame settingsFrame) { + this.mainMenu = mainMenu; + this.settingsFrame = settingsFrame; + } + + @Override + public void actionPerformed(ActionEvent e) { + // Réafficher la fenêtre du menu principal + mainMenu.setVisible(true); + settingsFrame.setVisible(false); // Fermer la fenêtre des paramètres + } +} \ No newline at end of file diff --git a/TestV1/src/fr/monkhanny/dorfromantik/listeners/MusicVolumeChangeListener.java b/TestV1/src/fr/monkhanny/dorfromantik/listeners/MusicVolumeChangeListener.java new file mode 100644 index 0000000..7998eaa --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/listeners/MusicVolumeChangeListener.java @@ -0,0 +1,23 @@ +package fr.monkhanny.dorfromantik.listeners; + +import fr.monkhanny.dorfromantik.Options; +import fr.monkhanny.dorfromantik.utils.MusicPlayer; + +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.JSlider; + +public class MusicVolumeChangeListener implements ChangeListener { + private JSlider slider; + + public MusicVolumeChangeListener(JSlider slider) { + this.slider = slider; + } + + @Override + public void stateChanged(ChangeEvent e) { + // Récupérer la valeur du slider spécifique + Options.MUSIC_VOLUME = slider.getValue(); + MusicPlayer.setVolume(MusicPlayer.getMusicClip(), Options.MUSIC_VOLUME); + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/listeners/MuteCheckBoxListener.java b/TestV1/src/fr/monkhanny/dorfromantik/listeners/MuteCheckBoxListener.java new file mode 100644 index 0000000..13bc5ca --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/listeners/MuteCheckBoxListener.java @@ -0,0 +1,32 @@ +package fr.monkhanny.dorfromantik.listeners; + +import fr.monkhanny.dorfromantik.Options; +import fr.monkhanny.dorfromantik.utils.MusicPlayer; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class MuteCheckBoxListener implements ActionListener { + private String label; + + public MuteCheckBoxListener(String label) { + this.label = label; + } + + @Override + public void actionPerformed(ActionEvent e) { + JCheckBox checkBox = (JCheckBox) e.getSource(); + + if ("Musique".equals(label)) { + Options.MUSIC_MUTED = !checkBox.isSelected(); + if (Options.MUSIC_MUTED) { + MusicPlayer.pauseMusic(); + } else { + MusicPlayer.playMusic(); + } + } else if ("SFX".equals(label)) { + Options.SOUNDS_MUTED = !checkBox.isSelected(); + } + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/listeners/SettingsWindowListener.java b/TestV1/src/fr/monkhanny/dorfromantik/listeners/SettingsWindowListener.java new file mode 100644 index 0000000..93f1c46 --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/listeners/SettingsWindowListener.java @@ -0,0 +1,25 @@ +package fr.monkhanny.dorfromantik.listeners; + +import fr.monkhanny.dorfromantik.gui.MainMenu; + +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import javax.swing.*; + +public class SettingsWindowListener extends WindowAdapter { + + private MainMenu mainMenu; + private JFrame settingsFrame; + + public SettingsWindowListener(MainMenu mainMenu, JFrame settingsFrame) { + this.mainMenu = mainMenu; + this.settingsFrame = settingsFrame; + } + + @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 + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/listeners/SoundsVolumeChangeListener.java b/TestV1/src/fr/monkhanny/dorfromantik/listeners/SoundsVolumeChangeListener.java new file mode 100644 index 0000000..952d3b6 --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/listeners/SoundsVolumeChangeListener.java @@ -0,0 +1,23 @@ +package fr.monkhanny.dorfromantik.listeners; + +import fr.monkhanny.dorfromantik.Options; +import fr.monkhanny.dorfromantik.utils.MusicPlayer; + +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.JSlider; + +public class SoundsVolumeChangeListener implements ChangeListener { + private JSlider slider; + + public SoundsVolumeChangeListener(JSlider slider) { + this.slider = slider; + } + + @Override + public void stateChanged(ChangeEvent e) { + // Récupérer la valeur du slider spécifique + Options.SOUNDS_VOLUME = slider.getValue(); + MusicPlayer.setVolume(MusicPlayer.getSoundClip(), Options.SOUNDS_VOLUME); + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/utils/FontLoader.java b/TestV1/src/fr/monkhanny/dorfromantik/utils/FontLoader.java new file mode 100644 index 0000000..0bd31ab --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/utils/FontLoader.java @@ -0,0 +1,33 @@ +package fr.monkhanny.dorfromantik.utils; + +import fr.monkhanny.dorfromantik.enums.Fonts; + +import java.awt.*; +import java.io.File; +import java.io.IOException; + +/** + * Classe utilitaire pour charger des polices à partir de fichiers. + * @version 1.0 + * @author Moncef STITI + * @see Fonts + * @see Font + */ +public class FontLoader { + + /** + * Charge une police à partir du fichier spécifié. + * @param fontEnumName Enumération de la police à charger. + * @return La police chargée. + * @throws IOException Si une erreur se produit lors de la lecture du fichier. + * @throws FontFormatException Si une erreur se produit lors de la création de la police. + */ + public static Font loadFont(Fonts fontEnumName) throws IOException, FontFormatException { + String fontFilePath = fontEnumName.getFontPath(); + File fontFile = new File(fontFilePath); + Font customFont = Font.createFont(Font.TRUETYPE_FONT, fontFile); + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + ge.registerFont(customFont); + return customFont; + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/utils/FontManager.java b/TestV1/src/fr/monkhanny/dorfromantik/utils/FontManager.java new file mode 100644 index 0000000..44301ea --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/utils/FontManager.java @@ -0,0 +1,70 @@ +package fr.monkhanny.dorfromantik.utils; + +import fr.monkhanny.dorfromantik.enums.Fonts; + +import java.awt.*; +import java.io.IOException; + +public class FontManager { + + private static Font titleFont; + private static Font buttonFont; + + // Charge et applique la police spécifique en fonction de Fonts + public static void loadCustomFont(Fonts fontEnum) { + try { + Font loadedFont = FontLoader.loadFont(fontEnum); + if (fontEnum == Fonts.TITLE) { + titleFont = loadedFont; + } else if (fontEnum == Fonts.BUTTON) { + buttonFont = loadedFont; + } + } catch (IOException | FontFormatException e) { + throw new RuntimeException("Failed to load font: " + fontEnum, e); + } + } + + // Obtient la police du titre avec une taille spécifique + public static Font getTitleFont(float size) { + if (titleFont == null) { + throw new IllegalStateException("Title font not loaded. Please load the font first."); + } + return titleFont.deriveFont(size); + } + + // Obtient la police du bouton avec une taille spécifique + public static Font getButtonFont(float size) { + if (buttonFont == null) { + throw new IllegalStateException("Button font not loaded. Please load the font first."); + } + return buttonFont.deriveFont(size); + } + + // Ajuste la taille de la police du titre selon la taille du composant sans la modifier directement + public static Font getAdjustedTitleFont(Component component, float minSize, float maxSize) { + if (titleFont == null) { + throw new IllegalStateException("Title font not loaded. Please load the font first."); + } + float newSize = Math.max(minSize, Math.min(maxSize, component.getWidth() / 12f)); + return titleFont.deriveFont(newSize); + } + + // Ajuste la taille de la police du bouton selon la taille du composant sans la modifier directement + public static Font getAdjustedButtonFont(Component component, float minSize, float maxSize) { + if (buttonFont == null) { + throw new IllegalStateException("Button font not loaded. Please load the font first."); + } + float newSize = Math.max(minSize, Math.min(maxSize, component.getHeight() / 20f)); + return buttonFont.deriveFont(newSize); + } + + // Définir manuellement une police de titre personnalisée + public static void setTitleFont(Font font) { + titleFont = font; + } + + // Définir manuellement une police de bouton personnalisée + public static void setButtonFont(Font font) { + buttonFont = font; + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/utils/ImageLoader.java b/TestV1/src/fr/monkhanny/dorfromantik/utils/ImageLoader.java new file mode 100644 index 0000000..1e9ff02 --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/utils/ImageLoader.java @@ -0,0 +1,35 @@ +package fr.monkhanny.dorfromantik.utils; + +import java.awt.Image; +import java.io.File; +import java.io.IOException; +import javax.imageio.ImageIO; + +/** + * Classe utilitaire pour charger des images à partir de fichiers. + * + * @version 1.0 + * @author Moncef STITI + */ +public class ImageLoader { + /** + * Icône de l'application. + */ + public static final Image APPLICATION_ICON = ImageLoader.loadImage("./ressources/images/Application/Application_Icon.jpg"); + + /** + * Charge une image à partir du fichier spécifié. + * + * @param filePath Chemin du fichier image à charger. + * @return L'image chargée, ou null si une erreur se produit. + */ + public static Image loadImage(String filePath) { + try { + File imageFile = new File(filePath); + return ImageIO.read(imageFile); + } catch (IOException e) { + System.err.println("Erreur lors du chargement de l'image : " + e.getMessage()); + return null; + } + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/utils/MusicPlayer.java b/TestV1/src/fr/monkhanny/dorfromantik/utils/MusicPlayer.java new file mode 100644 index 0000000..3271746 --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/utils/MusicPlayer.java @@ -0,0 +1,94 @@ +package fr.monkhanny.dorfromantik.utils; + +import fr.monkhanny.dorfromantik.enums.Musics; +import fr.monkhanny.dorfromantik.enums.Sounds; +import fr.monkhanny.dorfromantik.Options; + +import javax.sound.sampled.Clip; +import javax.sound.sampled.LineEvent; +import javax.sound.sampled.FloatControl; + +public class MusicPlayer { + private static Clip musicClip; + private static Clip soundClip; // Clip séparé pour les bruitages + private static boolean isPlayingMusic = false; + private static boolean isPlayingSound = false; + + public static void loadMusic(Musics music) { + if (music == Musics.MAIN_MENU_MUSIC) { + musicClip = SoundLoader.loadMusic(Musics.MAIN_MENU_MUSIC.getSoundsPath()); + if (musicClip != null) { + setVolume(musicClip, Options.MUSIC_VOLUME); + } + } + } + + public static void loadSound(Sounds sound) { + if (sound == Sounds.SOUNDS1) { + soundClip = SoundLoader.loadMusic(Sounds.SOUNDS1.getSoundsPath()); // Utilise soundClip pour les bruitages + if (soundClip != null) { + setVolume(soundClip, Options.SOUNDS_VOLUME); + } + } + } + + public static void playMusic() { + if (musicClip != null && !isPlayingMusic && !Options.MUSIC_MUTED) { + musicClip.start(); + isPlayingMusic = true; + } + } + + public static void playSound() { + if (soundClip != null && !isPlayingSound && !Options.SOUNDS_MUTED) { + soundClip.start(); + isPlayingSound = true; + soundClip.addLineListener(event -> { // Réinitialiser isPlayingSound à la fin du son + if (event.getType() == LineEvent.Type.STOP) { + soundClip.setFramePosition(0); // Retour au début du son pour rejouer si nécessaire + isPlayingSound = false; + } + }); + } + } + + public static void pauseMusic() { + if (musicClip != null && isPlayingMusic) { + musicClip.stop(); + isPlayingMusic = false; + } + } + + public static void stopMusic() { + if (musicClip != null) { + musicClip.stop(); + musicClip.setFramePosition(0); + isPlayingMusic = false; + } + } + + public static void setVolume(Clip clip, int volume) { + if (clip != null) { + FloatControl volumeControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); + float range = volumeControl.getMaximum() - volumeControl.getMinimum(); + float gain = (range * volume / 100f) + volumeControl.getMinimum(); + volumeControl.setValue(gain); + } + } + + public static boolean isPlayingMusic() { + return isPlayingMusic; + } + + public static boolean isPlayingSound() { + return isPlayingSound; + } + + public static Clip getMusicClip() { + return musicClip; + } + + public static Clip getSoundClip() { + return soundClip; + } +} \ No newline at end of file diff --git a/TestV1/src/fr/monkhanny/dorfromantik/utils/SoundLoader.java b/TestV1/src/fr/monkhanny/dorfromantik/utils/SoundLoader.java new file mode 100644 index 0000000..a28d30b --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/utils/SoundLoader.java @@ -0,0 +1,23 @@ +package fr.monkhanny.dorfromantik.utils; + +import javax.sound.sampled.*; +import java.io.File; +import java.io.IOException; + +public class SoundLoader { + + public static Clip loadMusic(String filePath) { + try { + File soundFile = new File(filePath); + AudioInputStream audioStream = AudioSystem.getAudioInputStream(soundFile); + Clip clip = AudioSystem.getClip(); + clip.open(audioStream); + return clip; + } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) { + e.printStackTrace(); + System.err.println("Failed to load sound at path: " + filePath); + return null; + } + } + +} \ No newline at end of file