diff --git a/TestV2/Makefile b/TestV2/Makefile index 5395157..2c66da2 100644 --- a/TestV2/Makefile +++ b/TestV2/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/TestV2/src/fr/monkhanny/dorfromantik/Main.java b/TestV2/src/fr/monkhanny/dorfromantik/Main.java index b46c168..868b203 100644 --- a/TestV2/src/fr/monkhanny/dorfromantik/Main.java +++ b/TestV2/src/fr/monkhanny/dorfromantik/Main.java @@ -9,6 +9,7 @@ import fr.monkhanny.dorfromantik.listeners.SettingsWindowListener; import fr.monkhanny.dorfromantik.gui.SettingsPanel; import fr.monkhanny.dorfromantik.controller.TutorialController; + import javax.swing.JFrame; /** diff --git a/TestV2/src/fr/monkhanny/dorfromantik/enums/Biome.java b/TestV2/src/fr/monkhanny/dorfromantik/enums/Biome.java new file mode 100644 index 0000000..029f052 --- /dev/null +++ b/TestV2/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/TestV2/src/fr/monkhanny/dorfromantik/enums/TileOrientation.java b/TestV2/src/fr/monkhanny/dorfromantik/enums/TileOrientation.java new file mode 100644 index 0000000..471ab80 --- /dev/null +++ b/TestV2/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/TestV2/src/fr/monkhanny/dorfromantik/game/Cellule.java b/TestV2/src/fr/monkhanny/dorfromantik/game/Cellule.java new file mode 100644 index 0000000..e69de29 diff --git a/TestV2/src/fr/monkhanny/dorfromantik/utils/Database.java b/TestV2/src/fr/monkhanny/dorfromantik/utils/Database.java new file mode 100644 index 0000000..6ce226b --- /dev/null +++ b/TestV2/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/TestV2/src/fr/monkhanny/dorfromantik/utils/Environnement.java b/TestV2/src/fr/monkhanny/dorfromantik/utils/Environnement.java new file mode 100644 index 0000000..0456bb9 --- /dev/null +++ b/TestV2/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/TestV2/src/fr/monkhanny/dorfromantik/utils/Hexagon.java b/TestV2/src/fr/monkhanny/dorfromantik/utils/Hexagon.java new file mode 100644 index 0000000..72b4a0d --- /dev/null +++ b/TestV2/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); + } +}