possibilte de placer les tuiles sur le plateau + ajout d'une seed + probleme de variation de tuiles
This commit is contained in:
@@ -1,33 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class Board {
|
|
||||||
private Map<Point, Tile> 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<Point, Tile> getTiles() {
|
|
||||||
return tiles;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,11 +0,0 @@
|
|||||||
public class GameController {
|
|
||||||
private GameView view;
|
|
||||||
|
|
||||||
public GameController(GameView view) {
|
|
||||||
this.view = view;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startGame() {
|
|
||||||
view.showBoard();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
28
TestV1/TestEnAttendantResolutionBug/Makefile
Normal file
28
TestV1/TestEnAttendantResolutionBug/Makefile
Normal file
@@ -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é."
|
@@ -1,3 +0,0 @@
|
|||||||
public enum Terrain {
|
|
||||||
MER, CHAMP, PRE, FORET, MONTAGNE, VIDE
|
|
||||||
}
|
|
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -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)
|
|
@@ -2,20 +2,23 @@ package controller;
|
|||||||
|
|
||||||
import model.Board;
|
import model.Board;
|
||||||
import view.GameView;
|
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 class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// Initialisation du modèle et de la vue
|
SwingUtilities.invokeLater(() -> {
|
||||||
Board board = new Board(); // Créer une instance du modèle (Board)
|
long seed = System.currentTimeMillis();
|
||||||
GameView view = new GameView(board); // Créer une instance de la vue (GameView)
|
Board board = new Board();
|
||||||
|
GameView gameView = new GameView(board, seed);
|
||||||
// Création du contrôleur avec Board et GameView
|
gameView.setVisible(true);
|
||||||
GameController controller = new GameController(board, view);
|
});
|
||||||
|
|
||||||
// Démarrage du jeu
|
|
||||||
controller.startGame();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,33 +1,27 @@
|
|||||||
package model;
|
package model;
|
||||||
|
|
||||||
/**
|
|
||||||
* Classe représentant une tuile du jeu.
|
|
||||||
*/
|
|
||||||
public class Tile {
|
public class Tile {
|
||||||
private final Terrain terrain;
|
private final Terrain terrain1;
|
||||||
|
private final Terrain terrain2;
|
||||||
|
|
||||||
/**
|
// Constructeur pour une tuile avec un ou deux terrains
|
||||||
* Constructeur pour une tuile.
|
public Tile(Terrain terrain1, Terrain terrain2) {
|
||||||
*
|
this.terrain1 = terrain1;
|
||||||
* @param terrain Le type de terrain de la tuile.
|
this.terrain2 = terrain2;
|
||||||
*/
|
|
||||||
public Tile(Terrain terrain) {
|
|
||||||
this.terrain = terrain;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Getter pour terrain1
|
||||||
* Obtient le terrain de la tuile.
|
public Terrain getTerrain1() {
|
||||||
*
|
return terrain1;
|
||||||
* @return Le terrain de la tuile.
|
|
||||||
*/
|
|
||||||
public Terrain getTerrain() {
|
|
||||||
return terrain;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// Getter pour terrain2
|
||||||
public String toString() {
|
public Terrain getTerrain2() {
|
||||||
return "Tile{" +
|
return terrain2;
|
||||||
"terrain=" + terrain +
|
}
|
||||||
'}';
|
|
||||||
|
// Vérifie si la tuile contient un seul terrain
|
||||||
|
public boolean hasSingleTerrain() {
|
||||||
|
return terrain2 == null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,9 +1,11 @@
|
|||||||
|
package utils;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public class Database {
|
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 LOGIN = "foulou";
|
||||||
private static final String PASSWORD = "foulou";
|
private static final String PASSWORD = "foulou";
|
||||||
|
|
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -7,16 +7,19 @@ import java.awt.event.MouseEvent;
|
|||||||
import model.Board;
|
import model.Board;
|
||||||
import model.Tile;
|
import model.Tile;
|
||||||
import model.Terrain;
|
import model.Terrain;
|
||||||
|
import model.TileGenerator;
|
||||||
|
|
||||||
|
|
||||||
public class GameView extends JFrame {
|
public class GameView extends JFrame {
|
||||||
private final Board board;
|
private final Board board;
|
||||||
|
private final TileGenerator tileGenerator;
|
||||||
private final int hexRadius = 60;
|
private final int hexRadius = 60;
|
||||||
private final int hexWidth = (int) (Math.sqrt(3) * hexRadius); // Largeur d'un hexagone
|
private final int hexWidth = (int) (Math.sqrt(3) * hexRadius); // Largeur d'un hexagone
|
||||||
private final int hexHeight = 2 * hexRadius; // Hauteur 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.board = board;
|
||||||
|
this.tileGenerator = new TileGenerator(seed); // Initialisation avec la seed
|
||||||
setTitle("Dorfromantik - Plateau");
|
setTitle("Dorfromantik - Plateau");
|
||||||
setSize(800, 800);
|
setSize(800, 800);
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
@@ -31,12 +34,10 @@ public class GameView extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleMouseClick(Point clickPoint) {
|
private void handleMouseClick(Point clickPoint) {
|
||||||
// Calcul de la position en coordonnées hexagonales
|
|
||||||
Point hexPosition = calculateHexCoordinates(clickPoint);
|
Point hexPosition = calculateHexCoordinates(clickPoint);
|
||||||
|
|
||||||
// Vérifie si la position est libre
|
|
||||||
if (!board.isPositionOccupied(hexPosition)) {
|
if (!board.isPositionOccupied(hexPosition)) {
|
||||||
Tile newTile = new Tile(Terrain.FORET); // Exemple : tuile de forêt
|
Tile newTile = tileGenerator.generateRandomTile();
|
||||||
board.addTile(hexPosition, newTile);
|
board.addTile(hexPosition, newTile);
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
@@ -45,79 +46,104 @@ public class GameView extends JFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void paint(Graphics g) {
|
public void paint(Graphics g) {
|
||||||
super.paint(g);
|
super.paint(g);
|
||||||
Graphics2D g2d = (Graphics2D) g;
|
|
||||||
|
|
||||||
// Dessiner toutes les tuiles placées
|
|
||||||
for (Point position : board.getTiles().keySet()) {
|
for (Point position : board.getTiles().keySet()) {
|
||||||
Tile tile = board.getTile(position);
|
Tile tile = board.getTile(position);
|
||||||
int x = calculateScreenX(position);
|
int x = calculateScreenX(position);
|
||||||
int y = calculateScreenY(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) {
|
public void drawLargeHexagon(Graphics g, int x, int y, Tile tile) {
|
||||||
Polygon hexagon = new Polygon();
|
int r = hexRadius;
|
||||||
Point center = new Point(x, y); // Centre de l'hexagone
|
int h = (int) (Math.sqrt(3) / 2 * r);
|
||||||
|
|
||||||
// Calculer les points des sommets de l'hexagone
|
// Coordonnées des sommets
|
||||||
for (int i = 0; i < 6; i++) {
|
int[] xPoints = {x + r, x + r / 2, x - r / 2, x - r, x - r / 2, x + r / 2};
|
||||||
double angle = Math.toRadians(60 * i);
|
int[] yPoints = {y, y + h, y + h, y, y - h, y - h};
|
||||||
int px = x + (int) (Math.cos(angle) * hexRadius);
|
|
||||||
int py = y + (int) (Math.sin(angle) * hexRadius);
|
if (tile.hasSingleTerrain()) {
|
||||||
hexagon.addPoint(px, py);
|
// 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
|
// Contour de l'hexagone
|
||||||
for (int i = 0; i < 6; i++) {
|
g.setColor(Color.BLACK);
|
||||||
// Trouver les coordonnées des points du côté de l'hexagone
|
g.drawPolygon(xPoints, yPoints, 6);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Color getColorForTerrain(Terrain terrain) {
|
|
||||||
return switch (terrain) {
|
// Dans la classe GameView.java
|
||||||
case MER -> Color.BLUE;
|
private Color getColorForTerrain(Terrain terrain) {
|
||||||
case CHAMP -> Color.YELLOW;
|
if (terrain == null) {
|
||||||
case FORET -> new Color(34, 139, 34);
|
return Color.GRAY; // Retourner une couleur par défaut si le terrain est null
|
||||||
case PRE -> Color.GREEN;
|
|
||||||
case MONTAGNE -> Color.GRAY;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Point calculateHexCoordinates(Point clickPoint) {
|
// Mappage des couleurs pour chaque terrain
|
||||||
int col = (int) Math.round((clickPoint.x - hexWidth / 2.0) / (1.5 * hexRadius));
|
switch (terrain) {
|
||||||
int row = (int) Math.round((clickPoint.y - hexHeight / 2.0 - (col % 2) * hexHeight / 4.0) / hexHeight);
|
case MER:
|
||||||
return new Point(col, row);
|
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) {
|
private int calculateScreenX(Point position) {
|
||||||
int col = position.x;
|
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) {
|
private int calculateScreenY(Point position) {
|
||||||
int col = position.x;
|
int col = position.x;
|
||||||
int row = position.y;
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user