diff --git a/TestV1/Makefile b/TestV1/Makefile index 5395157..2c66da2 100644 --- a/TestV1/Makefile +++ b/TestV1/Makefile @@ -4,7 +4,7 @@ SOURCEDIR = ./src/fr/monkhanny/dorfromantik/ BUILDDIR = ./build/ DOCDIR = ./doc/ JARNAME = dorfromantik.jar -CLASSP = libs/* +CLASSP = ./libs/*:$(BUILDDIR) MANIFESTPATH = Manifest.MF SOURCEDIR = ./src/ @@ -22,7 +22,7 @@ compile: run: @echo "Running..." - @java -jar $(JARNAME) + @java -cp $(CLASSP):$(JARNAME) fr.monkhanny.dorfromantik.Main @echo "Done." clean: diff --git a/TestV1/ressources/images/Tutorial/Gif1.gif b/TestV1/ressources/images/Tutorial/Gif1.gif new file mode 100644 index 0000000..a224ec2 Binary files /dev/null and b/TestV1/ressources/images/Tutorial/Gif1.gif differ diff --git a/TestV1/ressources/images/Tutorial/Gif2.gif b/TestV1/ressources/images/Tutorial/Gif2.gif new file mode 100644 index 0000000..2e0a081 Binary files /dev/null and b/TestV1/ressources/images/Tutorial/Gif2.gif differ diff --git a/TestV1/ressources/images/Tutorial/Gif3.gif b/TestV1/ressources/images/Tutorial/Gif3.gif new file mode 100644 index 0000000..e13adc0 Binary files /dev/null and b/TestV1/ressources/images/Tutorial/Gif3.gif differ diff --git a/TestV1/ressources/images/Tutorial/Gif4.gif b/TestV1/ressources/images/Tutorial/Gif4.gif new file mode 100644 index 0000000..a7a858f Binary files /dev/null and b/TestV1/ressources/images/Tutorial/Gif4.gif differ diff --git a/TestV1/src/fr/monkhanny/dorfromantik/Main.java b/TestV1/src/fr/monkhanny/dorfromantik/Main.java index d121acf..868b203 100644 --- a/TestV1/src/fr/monkhanny/dorfromantik/Main.java +++ b/TestV1/src/fr/monkhanny/dorfromantik/Main.java @@ -7,6 +7,8 @@ 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 fr.monkhanny.dorfromantik.controller.TutorialController; + import javax.swing.JFrame; @@ -26,12 +28,15 @@ public class Main { // Créer la fenêtre des paramètres JFrame settingsFrame = new JFrame("Paramètres"); + // Créer la fenêtre du tutoriel + JFrame howToPlayFrame = new JFrame("Comment jouer ?"); + // 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); + MainMenuButtonController MainMenuButtonController = new MainMenuButtonController(mainMenu,settingsFrame,howToPlayFrame); // Fenêtre des paramètres @@ -41,5 +46,11 @@ public class Main { settingsFrame.add(settingsPanel); settingsFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + // Fenêtre du tutoriel + TutorialController tutorialController = new TutorialController(); + howToPlayFrame.addWindowListener(windowListener); + howToPlayFrame.add(tutorialController.getTutorialPanel()); + howToPlayFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + } } diff --git a/TestV1/src/fr/monkhanny/dorfromantik/controller/MainMenuButtonController.java b/TestV1/src/fr/monkhanny/dorfromantik/controller/MainMenuButtonController.java index 611d3ed..8112540 100644 --- a/TestV1/src/fr/monkhanny/dorfromantik/controller/MainMenuButtonController.java +++ b/TestV1/src/fr/monkhanny/dorfromantik/controller/MainMenuButtonController.java @@ -17,8 +17,9 @@ public class MainMenuButtonController implements ActionListener { private MainMenu mainMenu; private JFrame settingsFrame; + private JFrame howToPlayFrame; - public MainMenuButtonController(MainMenu mainMenu, JFrame settingsFrame) { + public MainMenuButtonController(MainMenu mainMenu, JFrame settingsFrame, JFrame howToPlayFrame) { this.mainMenu = mainMenu; // Ajouter les écouteurs d'événements sur les boutons ButtonPanel buttonPanel = mainMenu.getButtonPanel(); @@ -34,6 +35,11 @@ public class MainMenuButtonController implements ActionListener { this.settingsFrame = settingsFrame; this.settingsFrame.setLocationRelativeTo(null); this.settingsFrame.setVisible(false); + + // Créer la fenêtre du tutoriel + this.howToPlayFrame = howToPlayFrame; + this.howToPlayFrame.setLocationRelativeTo(null); + this.howToPlayFrame.setVisible(false); } @Override @@ -72,11 +78,23 @@ public class MainMenuButtonController implements ActionListener { // Logic to continue the game } - private void showHowToPlay() { - System.out.println("Afficher comment jouer..."); - // Logic to show how to play + public void showHowToPlay() { + // Récupérer la taille et la position de la fenêtre du menu principal + Dimension mainMenuSize = this.mainMenu.getSize(); + Point mainMenuLocation = this.mainMenu.getLocation(); + + // Ajuster la fenêtre des paramètres pour qu'elle ait la même taille et position + this.howToPlayFrame.setSize(mainMenuSize); + this.howToPlayFrame.setLocation(mainMenuLocation); + + // Cacher la fenêtre du menu principal + this.mainMenu.setVisible(false); + + // Afficher la fenêtre des paramètres + this.howToPlayFrame.setVisible(true); } + private void exitGame() { System.exit(0); // Fermer l'application } diff --git a/TestV1/src/fr/monkhanny/dorfromantik/controller/TutorialController.java b/TestV1/src/fr/monkhanny/dorfromantik/controller/TutorialController.java new file mode 100644 index 0000000..5cdfd79 --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/controller/TutorialController.java @@ -0,0 +1,27 @@ +package fr.monkhanny.dorfromantik.controller; + +import fr.monkhanny.dorfromantik.gui.TutorialPanel; +import fr.monkhanny.dorfromantik.gui.Step; +import fr.monkhanny.dorfromantik.enums.Images; + +import javax.swing.*; +import java.util.ArrayList; +import java.util.List; + +public class TutorialController { + private TutorialPanel tutorialPanel; + + public TutorialController() { + List steps = new ArrayList<>(); + steps.add(new Step("Étape n°1", "Explication de la première étape ici.", Images.TUTORIAL_GIF1.getImagePath())); + steps.add(new Step("Étape n°2", "Explication de la deuxième étape ici.", Images.TUTORIAL_GIF2.getImagePath())); + steps.add(new Step("Étape n°3", "Explication de la troisième étape ici.", Images.TUTORIAL_GIF3.getImagePath())); + steps.add(new Step("Étape n°4", "Explication de la quatrième étape ici.", Images.TUTORIAL_GIF4.getImagePath())); + + tutorialPanel = new TutorialPanel(steps); + } + + public JPanel getTutorialPanel() { + return tutorialPanel; + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/enums/Biome.java b/TestV1/src/fr/monkhanny/dorfromantik/enums/Biome.java new file mode 100644 index 0000000..029f052 --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/enums/Biome.java @@ -0,0 +1,24 @@ +package fr.monkhanny.dorfromantik.enums; + +import java.awt.Color; + +public enum Biome { + SEA, FIELD, PRE, FOREST, MOUNTAIN; + + public Color[] getBiomeColors() { + switch (this) { + case SEA: + return new Color[] { new Color(25, 133, 208), new Color(53, 159, 235), new Color(0, 103, 178) }; + case FIELD: + return new Color[] { new Color(232, 214, 28), new Color(247, 228, 28), new Color(210, 195, 0) }; + case PRE: + return new Color[] { new Color(110, 190, 110), new Color(130, 210, 130), new Color(90, 170, 90) }; + case FOREST: + return new Color[] { new Color(15, 110, 65), new Color(35, 130, 85), new Color(0, 90, 45) }; + case MOUNTAIN: + return new Color[] { new Color(110, 110, 110), new Color(130, 130, 130), new Color(90, 90, 90) }; + default: + throw new IllegalArgumentException("Unknown Biome : " + this); + } + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/enums/Images.java b/TestV1/src/fr/monkhanny/dorfromantik/enums/Images.java index 86ecb05..78ed6c5 100644 --- a/TestV1/src/fr/monkhanny/dorfromantik/enums/Images.java +++ b/TestV1/src/fr/monkhanny/dorfromantik/enums/Images.java @@ -2,7 +2,7 @@ package fr.monkhanny.dorfromantik.enums; public enum Images { - SETTINGS_ICON, EXIT_ICON; + SETTINGS_ICON, EXIT_ICON, TUTORIAL_GIF1, TUTORIAL_GIF2, TUTORIAL_GIF3, TUTORIAL_GIF4; public String getImagePath() { switch (this) { @@ -10,6 +10,14 @@ public enum Images { return "./ressources/images/Icone/SettingsIcon.png"; case EXIT_ICON: return "./ressources/images/Icone/ExitIcon.png"; + case TUTORIAL_GIF1: + return "./ressources/images/Tutorial/Gif1.gif"; + case TUTORIAL_GIF2: + return "./ressources/images/Tutorial/Gif2.gif"; + case TUTORIAL_GIF3: + return "./ressources/images/Tutorial/Gif3.gif"; + case TUTORIAL_GIF4: + return "./ressources/images/Tutorial/Gif4.gif"; default: throw new IllegalArgumentException("Unexpected value: " + this); } diff --git a/TestV1/src/fr/monkhanny/dorfromantik/enums/TileOrientation.java b/TestV1/src/fr/monkhanny/dorfromantik/enums/TileOrientation.java new file mode 100644 index 0000000..471ab80 --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/enums/TileOrientation.java @@ -0,0 +1,26 @@ +package fr.monkhanny.dorfromantik.enums; + + +public enum TileOrientation { + NORTH, NORTH_EAST, SOUTH_EAST, SOUTH, SOUTH_WEST, NORTH_WEST; + + + public TileOrientation oppositeOrientation() { + switch (this) { + case NORTH: + return SOUTH; + case NORTH_EAST: + return SOUTH_WEST; + case SOUTH_EAST: + return NORTH_WEST; + case SOUTH: + return NORTH; + case SOUTH_WEST: + return NORTH_EAST; + case NORTH_WEST: + return SOUTH_EAST; + default: + throw new IllegalArgumentException("Unknown TileOrientation: " + this); + } + } +} \ No newline at end of file diff --git a/TestV1/src/fr/monkhanny/dorfromantik/game/Cellule.java b/TestV1/src/fr/monkhanny/dorfromantik/game/Cellule.java new file mode 100644 index 0000000..e69de29 diff --git a/TestV1/src/fr/monkhanny/dorfromantik/gui/Step.java b/TestV1/src/fr/monkhanny/dorfromantik/gui/Step.java new file mode 100644 index 0000000..7ef7c2a --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/gui/Step.java @@ -0,0 +1,25 @@ +package fr.monkhanny.dorfromantik.gui; + +public class Step { + private String title; + private String text; + private String imagePath; + + public Step(String title, String text, String imagePath) { + this.title = title; + this.text = text; + this.imagePath = imagePath; + } + + public String getText() { + return text; + } + + public String getImagePath() { + return imagePath; + } + + public String getTitle() { + return title; + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/gui/TutorialPanel.java b/TestV1/src/fr/monkhanny/dorfromantik/gui/TutorialPanel.java new file mode 100644 index 0000000..c1214e9 --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/gui/TutorialPanel.java @@ -0,0 +1,120 @@ +package fr.monkhanny.dorfromantik.gui; + +import fr.monkhanny.dorfromantik.components.Title; +import fr.monkhanny.dorfromantik.gui.Step; + +import javax.swing.*; +import java.awt.*; +import java.util.List; + +public class TutorialPanel extends JPanel { + + private List steps; + private int currentStepIndex; + + private Title title; + private JLabel stepText; + private JLabel stepImage; + private JButton nextButton; + private JButton prevButton; + + public TutorialPanel(List steps) { + this.steps = steps; + this.currentStepIndex = 0; + + // Utiliser BorderLayout pour la disposition principale + setLayout(new BorderLayout()); + + // Création du titre centré en haut + title = new Title("Comment jouer ?", 70f, Color.WHITE); + title.setHorizontalAlignment(JLabel.CENTER); + title.setOpaque(false); + add(title, BorderLayout.NORTH); + + // Conteneur principal pour les étapes, centré + JPanel centerPanel = new JPanel(); + centerPanel.setLayout(new GridBagLayout()); + centerPanel.setOpaque(false); // Rendre le conteneur transparent + + // Utiliser GridBagConstraints pour centrer le contenu verticalement + GridBagConstraints gbc = new GridBagConstraints(); + gbc.gridx = 0; + gbc.gridy = 0; + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.insets = new Insets(10, 0, 10, 0); + + // Conteneur pour le texte et l'image + JPanel stepContainer = new JPanel(); + stepContainer.setLayout(new BoxLayout(stepContainer, BoxLayout.Y_AXIS)); + stepContainer.setOpaque(false); // Transparent + + stepText = new JLabel(); + stepText.setFont(new Font("Arial", Font.BOLD, 28)); + stepText.setForeground(Color.WHITE); + stepText.setAlignmentX(Component.CENTER_ALIGNMENT); // Centrer le texte horizontalement + + stepImage = new JLabel(); + stepImage.setAlignmentX(Component.CENTER_ALIGNMENT); // Centrer l'image horizontalement + + // Ajouter les composants au conteneur d'étapes + stepContainer.add(stepText); + stepContainer.add(Box.createVerticalStrut(10)); // Espace entre texte et image + stepContainer.add(stepImage); + + // Ajouter le conteneur d'étapes au centre du panel + centerPanel.add(stepContainer, gbc); + add(centerPanel, BorderLayout.CENTER); + + // Panneau pour les boutons de navigation + JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); // Centrer les boutons + buttonPanel.setOpaque(false); // Transparent + + prevButton = new JButton("Précédent"); + nextButton = new JButton("Suivant"); + prevButton.addActionListener(e -> showPreviousStep()); + nextButton.addActionListener(e -> showNextStep()); + buttonPanel.add(prevButton); + buttonPanel.add(nextButton); + + // Ajouter le panneau des boutons en bas + add(buttonPanel, BorderLayout.SOUTH); + + // Affichage initial de l'étape + updateStepDisplay(); + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); // Appel à super pour s'assurer que le panneau est dessiné + + // Dessin de l'image de fond pour couvrir tout le panneau + ImageIcon backgroundImage = new ImageIcon("./ressources/images/MainMenu/backgroundBlured.jpg"); + Image image = backgroundImage.getImage(); + g.drawImage(image, 0, 0, getWidth(), getHeight(), this); // Dessiner l'image pour couvrir tout le panneau + } + + private void updateStepDisplay() { + Step currentStep = steps.get(currentStepIndex); + stepText.setText(currentStep.getText()); + stepImage.setIcon(new ImageIcon(currentStep.getImagePath())); + stepImage.setHorizontalAlignment(JLabel.CENTER); + stepImage.setVerticalAlignment(JLabel.CENTER); + prevButton.setEnabled(currentStepIndex > 0); + nextButton.setEnabled(currentStepIndex < steps.size() - 1); + } + + private void showPreviousStep() { + if (currentStepIndex > 0) { + currentStepIndex--; + updateStepDisplay(); + } + } + + private void showNextStep() { + if (currentStepIndex < steps.size() - 1) { + currentStepIndex++; + updateStepDisplay(); + } + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/utils/Database.java b/TestV1/src/fr/monkhanny/dorfromantik/utils/Database.java new file mode 100644 index 0000000..6ce226b --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/utils/Database.java @@ -0,0 +1,52 @@ +package fr.monkhanny.dorfromantik.utils; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class Database { + // Chargement des variables d'environnement + private static final String URL = Environnement.getEnv("DATABASE_URL_IUT"); + private static final String LOGIN = Environnement.getEnv("DATABASE_LOGIN_IUT"); + private static final String PASSWORD = Environnement.getEnv("DATABASE_PASSWORD_IUT"); + + // Variable de passerelle entre le programme et la base de données + private Connection database; + + /** + * Ouvre la connexion avec la base de données + */ + public Database() throws SQLException { + try { + // Chargement du driver MariaDB + Class.forName("org.mariadb.jdbc.Driver"); + + try { + // Connexion à la base de données + this.database = DriverManager.getConnection(URL, LOGIN, PASSWORD); + }catch (SQLException e) { + // Gestion de l'erreur de connexion + throw new SQLException("Échec de la connexion à la base de données: " + e.getMessage(), e); + } + } catch (ClassNotFoundException e) { + // Si le driver n'est pas trouvé + throw new SQLException("Driver MariaDB introuvable dans le classpath", e); + } + } + + + public Connection getDatabase() { + return this.database; + } + + + public void close() { + try { + if (this.database != null && !this.database.isClosed()) { + this.database.close(); + } + } catch (SQLException e) { + System.err.println("Erreur lors de la fermeture de la base de données : " + e.getMessage()); + } + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/utils/Environnement.java b/TestV1/src/fr/monkhanny/dorfromantik/utils/Environnement.java new file mode 100644 index 0000000..0456bb9 --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/utils/Environnement.java @@ -0,0 +1,32 @@ +package fr.monkhanny.dorfromantik.utils; + +import java.io.*; +import java.util.*; + +public class Environnement { + private static final String ENV_FILE = ".env"; + private static final Properties properties = new Properties(); + + static { + loadEnvironmentVariables(); + } + + private static void loadEnvironmentVariables() { + try (InputStream input = new FileInputStream(ENV_FILE)) { + // Chargement des variables du fichier .env + properties.load(input); + } catch (IOException e) { + System.err.println("Erreur lors du chargement du fichier .env : " + e.getMessage()); + } + } + + // Méthode pour récupérer une variable d'environnement, renvoie null si non trouvé + public static String getEnv(String key) { + return properties.getProperty(key); + } + + // Méthode pour vérifier si une variable d'environnement est présente + public static boolean hasEnv(String key) { + return properties.containsKey(key); + } +} diff --git a/TestV1/src/fr/monkhanny/dorfromantik/utils/Hexagon.java b/TestV1/src/fr/monkhanny/dorfromantik/utils/Hexagon.java new file mode 100644 index 0000000..72b4a0d --- /dev/null +++ b/TestV1/src/fr/monkhanny/dorfromantik/utils/Hexagon.java @@ -0,0 +1,74 @@ +package fr.monkhanny.dorfromantik.utils; + +import java.awt.Point; +import java.awt.Polygon; + + +public class Hexagon extends Polygon { + private static final int ANGLE_BETWEEN_VERTICES = 60; + + /** + * Constructeur d'un hexagone + * + * @param x Position x du centre de l'hexagone + * @param y Position y du centre de l'hexagone + * @param radius Rayon de l'hexagone + * @param startAngle Angle de départ de l'hexagone + */ + public Hexagon(int x, int y, int radius, double startAngle) { + if (radius <= 0) { + throw new IllegalArgumentException("Le rayon doit être supérieur à zéro."); + } + + for (int i = 0; i < 6; i++) { + double angleRad = calculateAngle(i, startAngle); + this.addPoint( + (int) (x + radius * Math.cos(angleRad)), + (int) (y + radius * Math.sin(angleRad)) + ); + } + } + + /** + * Calcule l'angle en radians pour un sommet donné + * + * @param vertexIndex Index du sommet (0 à 5) + * @param startAngle Angle de départ + * @return Angle en radians + */ + private double calculateAngle(int vertexIndex, double startAngle) { + return Math.toRadians(vertexIndex * ANGLE_BETWEEN_VERTICES + startAngle); + } + + /** + * Constructeur d'un hexagone + * + * @param center Centre de l'hexagone + * @param radius Rayon de l'hexagone + * @param startAngle Angle de départ de l'hexagone + */ + public Hexagon(Point center, int radius, double startAngle) { + this(center.x, center.y, radius, startAngle); + } + + /** + * Constructeur d'un hexagone + * + * @param x Position x du centre de l'hexagone + * @param y Position y du centre de l'hexagone + * @param radius Rayon de l'hexagone + */ + public Hexagon(int x, int y, int radius) { + this(x, y, radius, 0); + } + + /** + * Constructeur d'un hexagone + * + * @param center Centre de l'hexagone + * @param radius Rayon de l'hexagone + */ + public Hexagon(Point center, int radius) { + this(center.x, center.y, radius, 0); + } +}