diff --git a/README.md b/README.md index 5f05832..df0bd2e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# 🌄 Dorfromantik 🌄 +# Dorfromantik 🌄 -À VENIR ! \ No newline at end of file +À VENIR ! diff --git a/TestV2/Makefile b/TestV2/Makefile new file mode 100644 index 0000000..5395157 --- /dev/null +++ b/TestV2/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/TestV2/Manifest.MF b/TestV2/Manifest.MF new file mode 100644 index 0000000..bb6606d --- /dev/null +++ b/TestV2/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/TestV2/ressources/fonts/Contage-Black-Italic-BF63fc29ba63509.ttf b/TestV2/ressources/fonts/Contage-Black-Italic-BF63fc29ba63509.ttf new file mode 100644 index 0000000..4f23744 Binary files /dev/null and b/TestV2/ressources/fonts/Contage-Black-Italic-BF63fc29ba63509.ttf differ diff --git a/TestV2/ressources/fonts/Contage-Black.ttf b/TestV2/ressources/fonts/Contage-Black.ttf new file mode 100644 index 0000000..47495ef Binary files /dev/null and b/TestV2/ressources/fonts/Contage-Black.ttf differ diff --git a/TestV2/ressources/fonts/Contage-Bold-BF63fc29ba8dac9.ttf b/TestV2/ressources/fonts/Contage-Bold-BF63fc29ba8dac9.ttf new file mode 100644 index 0000000..ce95431 Binary files /dev/null and b/TestV2/ressources/fonts/Contage-Bold-BF63fc29ba8dac9.ttf differ diff --git a/TestV2/ressources/fonts/Contage-Bold-Italic-BF63fc29ba7e1fc.ttf b/TestV2/ressources/fonts/Contage-Bold-Italic-BF63fc29ba7e1fc.ttf new file mode 100644 index 0000000..12d8c24 Binary files /dev/null and b/TestV2/ressources/fonts/Contage-Bold-Italic-BF63fc29ba7e1fc.ttf differ diff --git a/TestV2/ressources/fonts/Contage-Light-BF63fc29bb66d25.ttf b/TestV2/ressources/fonts/Contage-Light-BF63fc29bb66d25.ttf new file mode 100644 index 0000000..3da4da9 Binary files /dev/null and b/TestV2/ressources/fonts/Contage-Light-BF63fc29bb66d25.ttf differ diff --git a/TestV2/ressources/fonts/Contage-Light-Italic-BF63fc29ba81b18.ttf b/TestV2/ressources/fonts/Contage-Light-Italic-BF63fc29ba81b18.ttf new file mode 100644 index 0000000..b6171a2 Binary files /dev/null and b/TestV2/ressources/fonts/Contage-Light-Italic-BF63fc29ba81b18.ttf differ diff --git a/TestV2/ressources/fonts/Contage-Medium-BF63fc29bae1bb5.ttf b/TestV2/ressources/fonts/Contage-Medium-BF63fc29bae1bb5.ttf new file mode 100644 index 0000000..387468c Binary files /dev/null and b/TestV2/ressources/fonts/Contage-Medium-BF63fc29bae1bb5.ttf differ diff --git a/TestV2/ressources/fonts/Contage-Medium-Italic-BF63fc29b9cd284.ttf b/TestV2/ressources/fonts/Contage-Medium-Italic-BF63fc29b9cd284.ttf new file mode 100644 index 0000000..e6b5198 Binary files /dev/null and b/TestV2/ressources/fonts/Contage-Medium-Italic-BF63fc29b9cd284.ttf differ diff --git a/TestV2/ressources/fonts/Contage-Regular-Italic-BF63fc29b846c83.ttf b/TestV2/ressources/fonts/Contage-Regular-Italic-BF63fc29b846c83.ttf new file mode 100644 index 0000000..513d0f4 Binary files /dev/null and b/TestV2/ressources/fonts/Contage-Regular-Italic-BF63fc29b846c83.ttf differ diff --git a/TestV2/ressources/fonts/Contage-Regular.ttf b/TestV2/ressources/fonts/Contage-Regular.ttf new file mode 100644 index 0000000..aca216b Binary files /dev/null and b/TestV2/ressources/fonts/Contage-Regular.ttf differ diff --git a/TestV2/ressources/fonts/Contage-Semi-Light-BF63fc29ba776e9.ttf b/TestV2/ressources/fonts/Contage-Semi-Light-BF63fc29ba776e9.ttf new file mode 100644 index 0000000..1404aed Binary files /dev/null and b/TestV2/ressources/fonts/Contage-Semi-Light-BF63fc29ba776e9.ttf differ diff --git a/TestV2/ressources/fonts/Contage-Semi-Light-Italic-BF63fc29b8477f8.ttf b/TestV2/ressources/fonts/Contage-Semi-Light-Italic-BF63fc29b8477f8.ttf new file mode 100644 index 0000000..7754d50 Binary files /dev/null and b/TestV2/ressources/fonts/Contage-Semi-Light-Italic-BF63fc29b8477f8.ttf differ diff --git a/TestV2/ressources/images/Application/Application_Icon.jpg b/TestV2/ressources/images/Application/Application_Icon.jpg new file mode 100644 index 0000000..45a1621 Binary files /dev/null and b/TestV2/ressources/images/Application/Application_Icon.jpg differ diff --git a/TestV2/ressources/images/MainMenu/background.jpg b/TestV2/ressources/images/MainMenu/background.jpg new file mode 100644 index 0000000..e788cf5 Binary files /dev/null and b/TestV2/ressources/images/MainMenu/background.jpg differ diff --git a/TestV2/src/fr/monkhanny/dorfromantik/Main.java b/TestV2/src/fr/monkhanny/dorfromantik/Main.java new file mode 100644 index 0000000..6d6813d --- /dev/null +++ b/TestV2/src/fr/monkhanny/dorfromantik/Main.java @@ -0,0 +1,22 @@ +package fr.monkhanny.dorfromantik; + +import fr.monkhanny.dorfromantik.gui.MainMenu; +import fr.monkhanny.dorfromantik.controller.MainMenuController; + +/** + * Classe principale du jeu + * @version 1.0 + * @author Moncef STITI + * @see MainMenu + * @see MainMenuController + */ +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) { + MainMenu mainMenu = new MainMenu(); + MainMenuController mainMenuController = new MainMenuController(mainMenu); + } +} diff --git a/TestV2/src/fr/monkhanny/dorfromantik/Options.java b/TestV2/src/fr/monkhanny/dorfromantik/Options.java new file mode 100644 index 0000000..e79488b --- /dev/null +++ b/TestV2/src/fr/monkhanny/dorfromantik/Options.java @@ -0,0 +1,7 @@ +package fr.monkhanny.dorfromantik; + +public class Options { + public static final float BASE_TITLE_FONT_SIZE = 70f; + + public static final float BASE_BUTTON_FONT_SIZE = 50f; +} diff --git a/TestV2/src/fr/monkhanny/dorfromantik/components/Button.java b/TestV2/src/fr/monkhanny/dorfromantik/components/Button.java new file mode 100644 index 0000000..48b2028 --- /dev/null +++ b/TestV2/src/fr/monkhanny/dorfromantik/components/Button.java @@ -0,0 +1,19 @@ +package fr.monkhanny.dorfromantik.components; + +import fr.monkhanny.dorfromantik.utils.FontManager; + +import javax.swing.*; +import java.awt.*; + +public class Button { + + public static JButton createStyledButton(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; + } +} diff --git a/TestV2/src/fr/monkhanny/dorfromantik/components/Title.java b/TestV2/src/fr/monkhanny/dorfromantik/components/Title.java new file mode 100644 index 0000000..86908ef --- /dev/null +++ b/TestV2/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/TestV2/src/fr/monkhanny/dorfromantik/controller/MainMenuController.java b/TestV2/src/fr/monkhanny/dorfromantik/controller/MainMenuController.java new file mode 100644 index 0000000..da80f4b --- /dev/null +++ b/TestV2/src/fr/monkhanny/dorfromantik/controller/MainMenuController.java @@ -0,0 +1,31 @@ +package fr.monkhanny.dorfromantik.controller; + +import fr.monkhanny.dorfromantik.gui.MainMenu; +import fr.monkhanny.dorfromantik.Options; + +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; + +public class MainMenuController { + + private MainMenu mainMenu; + + public MainMenuController(MainMenu mainMenu) { + this.mainMenu = mainMenu; + addComponentListener(); + } + + private void addComponentListener() { + mainMenu.addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + // Ajuster la taille de la police du titre en fonction de la taille de la fenêtre + float newFontSize = Options.BASE_TITLE_FONT_SIZE * (mainMenu.getWidth() / 900f); + mainMenu.getTitleLabel().updateTitleFont(newFontSize); + + // Mettre à jour les polices des boutons + mainMenu.getButtonPanel().updateButtonFonts(mainMenu.getWidth()); + } + }); + } +} diff --git a/TestV2/src/fr/monkhanny/dorfromantik/enums/Fonts.java b/TestV2/src/fr/monkhanny/dorfromantik/enums/Fonts.java new file mode 100644 index 0000000..1e3cc36 --- /dev/null +++ b/TestV2/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/TestV2/src/fr/monkhanny/dorfromantik/gui/ButtonPanel.java b/TestV2/src/fr/monkhanny/dorfromantik/gui/ButtonPanel.java new file mode 100644 index 0000000..1611b72 --- /dev/null +++ b/TestV2/src/fr/monkhanny/dorfromantik/gui/ButtonPanel.java @@ -0,0 +1,59 @@ +package fr.monkhanny.dorfromantik.gui; + +import fr.monkhanny.dorfromantik.utils.FontManager; +import fr.monkhanny.dorfromantik.components.Button; + +import javax.swing.*; +import java.awt.*; + +public class ButtonPanel extends JPanel { + + private JButton newGameButton; + private JButton continueGameButton; + private JButton howToPlayButton; + + 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.createStyledButton("Nouvelle partie", fontSize); + continueGameButton = Button.createStyledButton("Continuer une partie", fontSize); + howToPlayButton = Button.createStyledButton("Comment jouer ?", fontSize); + + // Ajouter les boutons au panneau + this.add(newGameButton); + this.add(Box.createVerticalStrut(20)); // Espace entre les boutons + this.add(continueGameButton); + this.add(Box.createVerticalStrut(20)); + this.add(howToPlayButton); + + // Espacement extensible pour maintenir les icônes en bas + this.add(Box.createVerticalGlue()); + } + + public JButton getNewGameButton() { + return newGameButton; + } + + public JButton getContinueGameButton() { + return continueGameButton; + } + + public JButton getHowToPlayButton() { + return howToPlayButton; + } + + 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)); + } +} diff --git a/TestV2/src/fr/monkhanny/dorfromantik/gui/MainMenu.java b/TestV2/src/fr/monkhanny/dorfromantik/gui/MainMenu.java new file mode 100644 index 0000000..9952219 --- /dev/null +++ b/TestV2/src/fr/monkhanny/dorfromantik/gui/MainMenu.java @@ -0,0 +1,55 @@ +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.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/TestV2/src/fr/monkhanny/dorfromantik/utils/FontLoader.java b/TestV2/src/fr/monkhanny/dorfromantik/utils/FontLoader.java new file mode 100644 index 0000000..0bd31ab --- /dev/null +++ b/TestV2/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/TestV2/src/fr/monkhanny/dorfromantik/utils/FontManager.java b/TestV2/src/fr/monkhanny/dorfromantik/utils/FontManager.java new file mode 100644 index 0000000..44301ea --- /dev/null +++ b/TestV2/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/TestV2/src/fr/monkhanny/dorfromantik/utils/ImageLoader.java b/TestV2/src/fr/monkhanny/dorfromantik/utils/ImageLoader.java new file mode 100644 index 0000000..1e9ff02 --- /dev/null +++ b/TestV2/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; + } + } +}