import javax.swing.*; import java.awt.*; public class GameView extends JFrame { private Tile tile; // Constructeur public GameView(Tile tile) { this.tile = tile; setTitle("Dorfromantik - Affichage de tuile"); setSize(600, 600); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); } public void showTile() { setVisible(true); repaint(); } @Override public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; int hexRadius = 50; // Rayon des hexagones int hexHeight = (int) (Math.sqrt(3) * hexRadius); // Hauteur de l'hexagone int xOffset = 150, yOffset = 150; // Décalage initial pour centrer Terrain[][] matrix = tile.getHexMatrix(); // Dessiner les hexagones en fonction de la matrice for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++) { if (matrix[i][j] != Terrain.VIDE) { // Calcul des coordonnées int x = xOffset + j * (3 * hexRadius / 2); // Décalage horizontal int y = yOffset + i * hexHeight + (j % 2) * (hexHeight / 2); // Décalage vertical drawHexagon(g2d, x, y, hexRadius, getColorForTerrain(matrix[i][j])); } } } } private void drawHexagon(Graphics2D g2d, int x, int y, int radius, Color color) { int[] xPoints = new int[6]; int[] yPoints = new int[6]; for (int i = 0; i < 6; i++) { xPoints[i] = x + (int) (radius * Math.cos(i * Math.PI / 3)); yPoints[i] = y + (int) (radius * Math.sin(i * Math.PI / 3)); } g2d.setColor(color); g2d.fillPolygon(xPoints, yPoints, 6); g2d.setColor(Color.BLACK); // Contour noir g2d.drawPolygon(xPoints, yPoints, 6); } 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; } } }