From d3260d67719d20b69b8aa25b513dfe4854fd16a3 Mon Sep 17 00:00:00 2001 From: "foulou.salle224-15" Date: Sun, 17 Nov 2024 20:25:32 +0100 Subject: [PATCH] possibilte de placer les tuiles sur le plateau + ajout d'une seed + probleme de variation de tuiles --- .../TestEnAttendantResolutionBug/Board.java | 33 ----- .../GameController.java | 11 -- .../GameView.java | 135 ----------------- TestV1/TestEnAttendantResolutionBug/Main.java | 15 -- TestV1/TestEnAttendantResolutionBug/Makefile | 28 ++++ .../TestEnAttendantResolutionBug/Terrain.java | 3 - TestV1/TestEnAttendantResolutionBug/Tile.java | 11 -- .../TestEnAttendantResolutionBug/src/Makefile | 18 --- .../src/controller/Main.java | 27 ++-- .../src/model/Tile.java | 40 +++-- .../src/model/TileGenerator.java | 22 +++ .../{ => src}/utils/Database.java | 4 +- .../src/utils/TileRepository.java | 34 +++++ .../src/view/GameView.java | 140 +++++++++++------- 14 files changed, 202 insertions(+), 319 deletions(-) delete mode 100644 TestV1/TestEnAttendantResolutionBug/Board.java delete mode 100644 TestV1/TestEnAttendantResolutionBug/GameController.java delete mode 100644 TestV1/TestEnAttendantResolutionBug/GameView.java delete mode 100644 TestV1/TestEnAttendantResolutionBug/Main.java create mode 100644 TestV1/TestEnAttendantResolutionBug/Makefile delete mode 100644 TestV1/TestEnAttendantResolutionBug/Terrain.java delete mode 100644 TestV1/TestEnAttendantResolutionBug/Tile.java delete mode 100644 TestV1/TestEnAttendantResolutionBug/src/Makefile create mode 100644 TestV1/TestEnAttendantResolutionBug/src/model/TileGenerator.java rename TestV1/TestEnAttendantResolutionBug/{ => src}/utils/Database.java (95%) create mode 100644 TestV1/TestEnAttendantResolutionBug/src/utils/TileRepository.java diff --git a/TestV1/TestEnAttendantResolutionBug/Board.java b/TestV1/TestEnAttendantResolutionBug/Board.java deleted file mode 100644 index 29d0800..0000000 --- a/TestV1/TestEnAttendantResolutionBug/Board.java +++ /dev/null @@ -1,33 +0,0 @@ -import java.awt.*; -import java.util.HashMap; -import java.util.Map; - -public class Board { - private Map tiles; - - public Board() { - tiles = new HashMap<>(); - } - - // Vérifie si la position est déjà occupée - public boolean isPositionOccupied(Point position) { - return tiles.containsKey(position); - } - - // Ajoute une tuile à une position donnée - public void addTile(Point position, Tile tile) { - if (!isPositionOccupied(position)) { - tiles.put(position, tile); - } - } - - // Récupère la tuile à une position donnée - public Tile getTile(Point position) { - return tiles.get(position); - } - - // Récupère toutes les tuiles - public Map getTiles() { - return tiles; - } -} diff --git a/TestV1/TestEnAttendantResolutionBug/GameController.java b/TestV1/TestEnAttendantResolutionBug/GameController.java deleted file mode 100644 index 45709d8..0000000 --- a/TestV1/TestEnAttendantResolutionBug/GameController.java +++ /dev/null @@ -1,11 +0,0 @@ -public class GameController { - private GameView view; - - public GameController(GameView view) { - this.view = view; - } - - public void startGame() { - view.showBoard(); - } -} diff --git a/TestV1/TestEnAttendantResolutionBug/GameView.java b/TestV1/TestEnAttendantResolutionBug/GameView.java deleted file mode 100644 index 3d9f377..0000000 --- a/TestV1/TestEnAttendantResolutionBug/GameView.java +++ /dev/null @@ -1,135 +0,0 @@ -import javax.swing.*; -import java.awt.*; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -public class GameView extends JFrame { - private Board board; - private int hexRadius = 30; // Rayon du grand hexagone - - // Dimensions calculées des hexagones - private int hexWidth = (int) (1.5 * hexRadius); // Largeur de l'hexagone - private int hexHeight = (int) (Math.sqrt(3) * hexRadius); // Hauteur de l'hexagone - - public GameView(Board board) { - this.board = board; - setTitle("Dorfromantik - Plateau"); - setSize(800, 800); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setLocationRelativeTo(null); - - // Gestion des clics de souris pour placer une tuile - addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - handleMouseClick(e.getX(), e.getY()); - } - }); - } - - public void showBoard() { - setVisible(true); - repaint(); - } - - @Override - public void paint(Graphics g) { - super.paint(g); - Graphics2D g2d = (Graphics2D) g; - - // Dessiner toutes les tuiles du plateau - for (Point position : board.getTiles().keySet()) { - Tile tile = board.getTile(position); - drawLargeHexagon(g2d, position.x, position.y, tile); - } - } - - private void drawLargeHexagon(Graphics2D g2d, int centerX, int centerY, Tile tile) { - // Couleurs des triangles - Color color1 = getColorForTerrain(tile.getTerrain()); - Color color2 = color1.darker(); // Variante plus sombre pour contraste - - // Dessiner les 6 triangles pour former l'hexagone - for (int i = 0; i < 6; i++) { - // Dessiner chaque triangle équilatéral avec sa couleur associée - drawTriangle(g2d, centerX, centerY, i, hexRadius, i % 2 == 0 ? color1 : color2); - } - } - - private void drawTriangle(Graphics2D g2d, int centerX, int centerY, int triangleIndex, int radius, Color color) { - // Orientation de chaque triangle (décalage de 60° par rapport à chaque triangle) - double angle = Math.toRadians(60 * triangleIndex); - - // Calcul des points de chaque triangle autour du centre du grand hexagone - int x1 = centerX + (int) (Math.cos(angle) * radius); - int y1 = centerY + (int) (Math.sin(angle) * radius); - - int x2 = centerX + (int) (Math.cos(angle + Math.toRadians(60)) * radius); - int y2 = centerY + (int) (Math.sin(angle + Math.toRadians(60)) * radius); - - int x3 = centerX + (int) (Math.cos(angle + Math.toRadians(120)) * radius); - int y3 = centerY + (int) (Math.sin(angle + Math.toRadians(120)) * radius); - - // Créer un polygone pour dessiner le triangle - Polygon triangle = new Polygon(); - triangle.addPoint(centerX, centerY); // Centre de l'hexagone - triangle.addPoint(x1, y1); // Premier sommet - triangle.addPoint(x2, y2); // Deuxième sommet - triangle.addPoint(x3, y3); // Troisième sommet - - // Remplir le triangle avec la couleur - g2d.setColor(color); - g2d.fillPolygon(triangle); - } - - private Color getColorForTerrain(Terrain terrain) { - switch (terrain) { - case MER: - return Color.BLUE; - case CHAMP: - return Color.YELLOW; - case PRE: - return Color.GREEN; - case FORET: - return new Color(34, 139, 34); // Vert foncé - case MONTAGNE: - return Color.GRAY; - default: - return Color.WHITE; - } - } - - private void handleMouseClick(int mouseX, int mouseY) { - // Calcul des coordonnées de la grille de manière à respecter la structure hexagonale - - // Calcul de la colonne et de la ligne en fonction de la taille des hexagones - int gridX = (int) (mouseX / (hexWidth * 0.75)); // Calcul de la colonne - - // Calcul de la ligne en fonction de la hauteur des hexagones - int gridY = (int) (mouseY / hexHeight); // Calcul de la ligne - - // Détecter si c'est une rangée paire ou impaire et appliquer un décalage - if (gridY % 2 != 0) { // Si la ligne est impaire - gridX += 1; // Décalage horizontal pour les rangées impaires - } - - // Calculer les coordonnées X et Y en pixels - int finalX = (int) (gridX * hexWidth * 0.75); // Calcul des coordonnées X - int finalY = gridY * hexHeight; // Calcul des coordonnées Y - - // Créer un objet Point avec les coordonnées finales - Point position = new Point(finalX, finalY); - - // Vérifier si la position est déjà occupée par une autre tuile - if (!board.isPositionOccupied(position)) { - // Créer une nouvelle tuile (ici, une tuile de forêt) - Tile newTile = new Tile(Terrain.FORET); - - // Ajouter la tuile sur le plateau - board.addTile(position, newTile); - - // Rafraîchir l'affichage - repaint(); - } - } -} \ No newline at end of file diff --git a/TestV1/TestEnAttendantResolutionBug/Main.java b/TestV1/TestEnAttendantResolutionBug/Main.java deleted file mode 100644 index 86fb72a..0000000 --- a/TestV1/TestEnAttendantResolutionBug/Main.java +++ /dev/null @@ -1,15 +0,0 @@ -public class Main { - public static void main(String[] args) { - // Création d'un plateau - Board board = new Board(); - - // Vue avec le plateau - GameView view = new GameView(board); - - // Contrôleur - GameController controller = new GameController(view); - - // Démarrer le jeu - controller.startGame(); - } -} diff --git a/TestV1/TestEnAttendantResolutionBug/Makefile b/TestV1/TestEnAttendantResolutionBug/Makefile new file mode 100644 index 0000000..a0f2673 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/Makefile @@ -0,0 +1,28 @@ +# Variables +SRC_DIR = src +BIN_DIR = bin +JAR_DIR = src/utils +MAIN_CLASS = controller.Main +CP = $(BIN_DIR);$(JAR_DIR)/mariadb-client.jar + +# Règles +.PHONY: all compile run clean + +all: compile run + +compile: + @echo "Compilation des fichiers Java..." + @if not exist $(BIN_DIR) mkdir $(BIN_DIR) + @for /R $(SRC_DIR) %%f in (*.java) do @echo %%f >> sources.txt + @javac -cp $(CP) -d $(BIN_DIR) @sources.txt + @del sources.txt + @echo "Compilation terminée." + +run: + @echo "Exécution du programme..." + @java -cp $(CP) $(MAIN_CLASS) + +clean: + @echo "Nettoyage des fichiers compilés..." + @if exist $(BIN_DIR) rmdir /S /Q $(BIN_DIR) + @echo "Nettoyage terminé." diff --git a/TestV1/TestEnAttendantResolutionBug/Terrain.java b/TestV1/TestEnAttendantResolutionBug/Terrain.java deleted file mode 100644 index 3cbbe46..0000000 --- a/TestV1/TestEnAttendantResolutionBug/Terrain.java +++ /dev/null @@ -1,3 +0,0 @@ -public enum Terrain { - MER, CHAMP, PRE, FORET, MONTAGNE, VIDE -} diff --git a/TestV1/TestEnAttendantResolutionBug/Tile.java b/TestV1/TestEnAttendantResolutionBug/Tile.java deleted file mode 100644 index d476f15..0000000 --- a/TestV1/TestEnAttendantResolutionBug/Tile.java +++ /dev/null @@ -1,11 +0,0 @@ -public class Tile { - private Terrain terrain; // Un seul terrain pour toute la tuile - - public Tile(Terrain terrain) { - this.terrain = terrain; - } - - public Terrain getTerrain() { - return terrain; - } -} diff --git a/TestV1/TestEnAttendantResolutionBug/src/Makefile b/TestV1/TestEnAttendantResolutionBug/src/Makefile deleted file mode 100644 index e7d7954..0000000 --- a/TestV1/TestEnAttendantResolutionBug/src/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -SRC_DIR = src -BUILD_DIR = build -MAIN_CLASS = controller.Main - -SOURCES = $(shell find $(SRC_DIR) -name "*.java") -CLASSES = $(patsubst $(SRC_DIR)/%.java, $(BUILD_DIR)/%.class, $(SOURCES)) - -all: $(CLASSES) - -$(BUILD_DIR)/%.class: $(SRC_DIR)/%.java - mkdir -p $(dir $@) - javac -d $(BUILD_DIR) $< - -run: all - java -cp $(BUILD_DIR) $(MAIN_CLASS) - -clean: - rm -rf $(BUILD_DIR) diff --git a/TestV1/TestEnAttendantResolutionBug/src/controller/Main.java b/TestV1/TestEnAttendantResolutionBug/src/controller/Main.java index 210d9f3..67bc91a 100644 --- a/TestV1/TestEnAttendantResolutionBug/src/controller/Main.java +++ b/TestV1/TestEnAttendantResolutionBug/src/controller/Main.java @@ -2,20 +2,23 @@ package controller; import model.Board; import view.GameView; +import model.Tile; +import utils.Database; +import utils.TileRepository; +import java.sql.SQLException; +import model.TileGenerator; +import javax.swing.SwingUtilities; + + + -/** - * Classe principale pour démarrer l'application. - */ public class Main { public static void main(String[] args) { - // Initialisation du modèle et de la vue - Board board = new Board(); // Créer une instance du modèle (Board) - GameView view = new GameView(board); // Créer une instance de la vue (GameView) - - // Création du contrôleur avec Board et GameView - GameController controller = new GameController(board, view); - - // Démarrage du jeu - controller.startGame(); + SwingUtilities.invokeLater(() -> { + long seed = System.currentTimeMillis(); + Board board = new Board(); + GameView gameView = new GameView(board, seed); + gameView.setVisible(true); + }); } } diff --git a/TestV1/TestEnAttendantResolutionBug/src/model/Tile.java b/TestV1/TestEnAttendantResolutionBug/src/model/Tile.java index 2cec1d5..0b547ac 100644 --- a/TestV1/TestEnAttendantResolutionBug/src/model/Tile.java +++ b/TestV1/TestEnAttendantResolutionBug/src/model/Tile.java @@ -1,33 +1,27 @@ package model; -/** - * Classe représentant une tuile du jeu. - */ public class Tile { - private final Terrain terrain; + private final Terrain terrain1; + private final Terrain terrain2; - /** - * Constructeur pour une tuile. - * - * @param terrain Le type de terrain de la tuile. - */ - public Tile(Terrain terrain) { - this.terrain = terrain; + // Constructeur pour une tuile avec un ou deux terrains + public Tile(Terrain terrain1, Terrain terrain2) { + this.terrain1 = terrain1; + this.terrain2 = terrain2; } - /** - * Obtient le terrain de la tuile. - * - * @return Le terrain de la tuile. - */ - public Terrain getTerrain() { - return terrain; + // Getter pour terrain1 + public Terrain getTerrain1() { + return terrain1; } - @Override - public String toString() { - return "Tile{" + - "terrain=" + terrain + - '}'; + // Getter pour terrain2 + public Terrain getTerrain2() { + return terrain2; + } + + // Vérifie si la tuile contient un seul terrain + public boolean hasSingleTerrain() { + return terrain2 == null; } } diff --git a/TestV1/TestEnAttendantResolutionBug/src/model/TileGenerator.java b/TestV1/TestEnAttendantResolutionBug/src/model/TileGenerator.java new file mode 100644 index 0000000..ecbfb21 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/src/model/TileGenerator.java @@ -0,0 +1,22 @@ +package model; + +import java.util.Random; + +public class TileGenerator { + private final Random random; + + public TileGenerator(long seed) { + this.random = new Random(seed); + } + + // Générer une tuile avec un ou deux terrains + public Tile generateRandomTile() { + // Générer un terrain aléatoire + Terrain terrain1 = Terrain.values()[random.nextInt(Terrain.values().length)]; + + // Décider si la tuile a un seul terrain ou deux + Terrain terrain2 = random.nextBoolean() ? Terrain.values()[random.nextInt(Terrain.values().length)] : null; + + return new Tile(terrain1, terrain2); + } +} diff --git a/TestV1/TestEnAttendantResolutionBug/utils/Database.java b/TestV1/TestEnAttendantResolutionBug/src/utils/Database.java similarity index 95% rename from TestV1/TestEnAttendantResolutionBug/utils/Database.java rename to TestV1/TestEnAttendantResolutionBug/src/utils/Database.java index 2e5aac5..76511a7 100644 --- a/TestV1/TestEnAttendantResolutionBug/utils/Database.java +++ b/TestV1/TestEnAttendantResolutionBug/src/utils/Database.java @@ -1,9 +1,11 @@ +package utils; + import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class Database { - private static final String URL = "jdbc:mariadb://dwarves.iut-fbleau.fr:3306/foulou"; + private static final String URL = "jdbc:mariadb://dwarves.iut-fbleau.fr/foulou"; private static final String LOGIN = "foulou"; private static final String PASSWORD = "foulou"; diff --git a/TestV1/TestEnAttendantResolutionBug/src/utils/TileRepository.java b/TestV1/TestEnAttendantResolutionBug/src/utils/TileRepository.java new file mode 100644 index 0000000..ea618e7 --- /dev/null +++ b/TestV1/TestEnAttendantResolutionBug/src/utils/TileRepository.java @@ -0,0 +1,34 @@ +package utils; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import model.Tile; + + +public class TileRepository { + + private final Database database; + + public TileRepository(Database database) { + this.database = database; + } + + public void saveTile(Tile tile) throws SQLException { + String query = "INSERT INTO tiles (terrain1, terrain2) VALUES (?, ?)"; + + try (Connection connection = database.getDatabase(); + PreparedStatement statement = connection.prepareStatement(query)) { + + statement.setString(1, tile.getTerrain1().toString()); + + if (tile.getTerrain2() != null) { + statement.setString(2, tile.getTerrain2().toString()); + } else { + statement.setNull(2, java.sql.Types.VARCHAR); + } + + statement.executeUpdate(); + } + } +} diff --git a/TestV1/TestEnAttendantResolutionBug/src/view/GameView.java b/TestV1/TestEnAttendantResolutionBug/src/view/GameView.java index 1ce23da..b2ea4bf 100644 --- a/TestV1/TestEnAttendantResolutionBug/src/view/GameView.java +++ b/TestV1/TestEnAttendantResolutionBug/src/view/GameView.java @@ -7,16 +7,19 @@ import java.awt.event.MouseEvent; import model.Board; import model.Tile; import model.Terrain; +import model.TileGenerator; public class GameView extends JFrame { private final Board board; + private final TileGenerator tileGenerator; private final int hexRadius = 60; private final int hexWidth = (int) (Math.sqrt(3) * hexRadius); // Largeur d'un hexagone private final int hexHeight = 2 * hexRadius; // Hauteur d'un hexagone - public GameView(Board board) { + public GameView(Board board, long seed) { this.board = board; + this.tileGenerator = new TileGenerator(seed); // Initialisation avec la seed setTitle("Dorfromantik - Plateau"); setSize(800, 800); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -31,12 +34,10 @@ public class GameView extends JFrame { } private void handleMouseClick(Point clickPoint) { - // Calcul de la position en coordonnées hexagonales Point hexPosition = calculateHexCoordinates(clickPoint); - // Vérifie si la position est libre if (!board.isPositionOccupied(hexPosition)) { - Tile newTile = new Tile(Terrain.FORET); // Exemple : tuile de forêt + Tile newTile = tileGenerator.generateRandomTile(); board.addTile(hexPosition, newTile); repaint(); } @@ -45,79 +46,104 @@ public class GameView extends JFrame { @Override public void paint(Graphics g) { super.paint(g); - Graphics2D g2d = (Graphics2D) g; - - // Dessiner toutes les tuiles placées + for (Point position : board.getTiles().keySet()) { Tile tile = board.getTile(position); int x = calculateScreenX(position); int y = calculateScreenY(position); - drawLargeHexagon(g2d, x, y, tile); + drawLargeHexagon(g, x, y, tile); } } - private void drawLargeHexagon(Graphics2D g2d, int x, int y, Tile tile) { - Polygon hexagon = new Polygon(); - Point center = new Point(x, y); // Centre de l'hexagone - - // Calculer les points des sommets de l'hexagone - for (int i = 0; i < 6; i++) { - double angle = Math.toRadians(60 * i); - int px = x + (int) (Math.cos(angle) * hexRadius); - int py = y + (int) (Math.sin(angle) * hexRadius); - hexagon.addPoint(px, py); + public void drawLargeHexagon(Graphics g, int x, int y, Tile tile) { + int r = hexRadius; + int h = (int) (Math.sqrt(3) / 2 * r); + + // Coordonnées des sommets + int[] xPoints = {x + r, x + r / 2, x - r / 2, x - r, x - r / 2, x + r / 2}; + int[] yPoints = {y, y + h, y + h, y, y - h, y - h}; + + if (tile.hasSingleTerrain()) { + // Une seule couleur : remplir tout l'hexagone + g.setColor(getColorForTerrain(tile.getTerrain1())); + g.fillPolygon(xPoints, yPoints, 6); + } else { + // Deux terrains : Diviser l'hexagone en deux moitiés + Color color1 = getColorForTerrain(tile.getTerrain1()); + Color color2 = getColorForTerrain(tile.getTerrain2()); + + // Premier terrain (moitié supérieure) + g.setColor(color1); + g.fillPolygon( + new int[]{xPoints[0], xPoints[1], xPoints[2], xPoints[3]}, + new int[]{yPoints[0], yPoints[1], yPoints[2], yPoints[3]}, + 4 + ); + + // Deuxième terrain (moitié inférieure) + g.setColor(color2); + g.fillPolygon( + new int[]{xPoints[3], xPoints[4], xPoints[5], xPoints[0]}, + new int[]{yPoints[3], yPoints[4], yPoints[5], yPoints[0]}, + 4 + ); } - // Dessiner l'intérieur de l'hexagone en divisant en triangles - for (int i = 0; i < 6; i++) { - // Trouver les coordonnées des points du côté de l'hexagone - int x1 = hexagon.xpoints[i]; - int y1 = hexagon.ypoints[i]; - int x2 = hexagon.xpoints[(i + 1) % 6]; // Le point suivant (modulo 6) - int y2 = hexagon.ypoints[(i + 1) % 6]; - - // Dessiner un triangle avec le centre de l'hexagone - Polygon triangle = new Polygon(); - triangle.addPoint(center.x, center.y); // Ajouter le centre - triangle.addPoint(x1, y1); // Ajouter le premier sommet - triangle.addPoint(x2, y2); // Ajouter le deuxième sommet - - g2d.setColor(getColorForTerrain(tile.getTerrain())); - g2d.fillPolygon(triangle); // Remplir le triangle - g2d.setColor(Color.BLACK); - g2d.drawPolygon(triangle); // Dessiner les contours du triangle - } - - // Dessiner l'extérieur de l'hexagone - g2d.setColor(Color.BLACK); - g2d.drawPolygon(hexagon); + // Contour de l'hexagone + g.setColor(Color.BLACK); + g.drawPolygon(xPoints, yPoints, 6); } - - private Color getColorForTerrain(Terrain terrain) { - return switch (terrain) { - case MER -> Color.BLUE; - case CHAMP -> Color.YELLOW; - case FORET -> new Color(34, 139, 34); - case PRE -> Color.GREEN; - case MONTAGNE -> Color.GRAY; - }; + + + // Dans la classe GameView.java +private Color getColorForTerrain(Terrain terrain) { + if (terrain == null) { + return Color.GRAY; // Retourner une couleur par défaut si le terrain est null } - private Point calculateHexCoordinates(Point clickPoint) { - int col = (int) Math.round((clickPoint.x - hexWidth / 2.0) / (1.5 * hexRadius)); - int row = (int) Math.round((clickPoint.y - hexHeight / 2.0 - (col % 2) * hexHeight / 4.0) / hexHeight); - return new Point(col, row); + // Mappage des couleurs pour chaque terrain + switch (terrain) { + case MER: + return new Color(0, 0, 255); // Bleu pour MER + case CHAMP: + return new Color(0, 255, 0); // Vert pour CHAMP + case FORET: + return new Color(34, 139, 34); // Vert foncé pour FORET + case PRE: + return new Color(255, 255, 0); // Jaune pour PRE + case MONTAGNE: + return new Color(139, 69, 19); // Marron pour MONTAGNE + default: + return Color.GRAY; // Couleur par défaut pour les cas non gérés } +} + + + +private Point calculateHexCoordinates(Point clickPoint) { + // Rayon et espacement vertical/hexagonal + int r = hexRadius; + double h = Math.sqrt(3) * r / 2; // Hauteur effective entre deux lignes + + // Calcul approximatif de la colonne et de la ligne + int col = (int) Math.round((double) clickPoint.x / (1.5 * r)); + int row = (int) Math.round((double) (clickPoint.y - (col % 2) * h) / (Math.sqrt(3) * r)); + + return new Point(col, row); +} + private int calculateScreenX(Point position) { int col = position.x; - return (int) (col * 1.5 * hexRadius + hexWidth / 2.0); + return col * (int) (1.5 * hexRadius); // Espacement horizontal } - + private int calculateScreenY(Point position) { int col = position.x; int row = position.y; - return (int) (row * hexHeight + (col % 2) * hexHeight / 2.0 + hexHeight / 2.0); + return row * (int) (Math.sqrt(3) * hexRadius) + (col % 2) * (int) (Math.sqrt(3) / 2 * hexRadius); + // Décalage vertical pour les colonnes impaires } + }