resolution problème de tuiles
This commit is contained in:
@@ -3,24 +3,30 @@ package model;
|
|||||||
public class Tile {
|
public class Tile {
|
||||||
private final Terrain terrain1;
|
private final Terrain terrain1;
|
||||||
private final Terrain terrain2;
|
private final Terrain terrain2;
|
||||||
|
private final int terrain1Sides; // Nombre de côtés attribués à terrain1 (1, 2 ou 3)
|
||||||
|
|
||||||
// Constructeur pour une tuile avec un ou deux terrains
|
public Tile(Terrain terrain1, Terrain terrain2, int terrain1Sides) {
|
||||||
public Tile(Terrain terrain1, Terrain terrain2) {
|
|
||||||
this.terrain1 = terrain1;
|
this.terrain1 = terrain1;
|
||||||
this.terrain2 = terrain2;
|
this.terrain2 = terrain2;
|
||||||
|
this.terrain1Sides = terrain1Sides;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getter pour terrain1
|
|
||||||
public Terrain getTerrain1() {
|
public Terrain getTerrain1() {
|
||||||
return terrain1;
|
return terrain1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getter pour terrain2
|
|
||||||
public Terrain getTerrain2() {
|
public Terrain getTerrain2() {
|
||||||
return terrain2;
|
return terrain2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vérifie si la tuile contient un seul terrain
|
public int getTerrain1Sides() {
|
||||||
|
return terrain1Sides;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTerrain2Sides() {
|
||||||
|
return 6 - terrain1Sides; // Le reste des côtés
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasSingleTerrain() {
|
public boolean hasSingleTerrain() {
|
||||||
return terrain2 == null;
|
return terrain2 == null;
|
||||||
}
|
}
|
||||||
|
@@ -9,14 +9,23 @@ public class TileGenerator {
|
|||||||
this.random = new Random(seed);
|
this.random = new Random(seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Générer une tuile avec un ou deux terrains
|
|
||||||
public Tile generateRandomTile() {
|
public Tile generateRandomTile() {
|
||||||
// Générer un terrain aléatoire
|
|
||||||
Terrain terrain1 = Terrain.values()[random.nextInt(Terrain.values().length)];
|
Terrain terrain1 = Terrain.values()[random.nextInt(Terrain.values().length)];
|
||||||
|
if (random.nextBoolean()) { // 50% chance d'avoir un seul terrain
|
||||||
// Décider si la tuile a un seul terrain ou deux
|
return new Tile(terrain1, null, 6); // Toutes les faces au même terrain
|
||||||
Terrain terrain2 = random.nextBoolean() ? Terrain.values()[random.nextInt(Terrain.values().length)] : null;
|
}
|
||||||
|
|
||||||
return new Tile(terrain1, terrain2);
|
Terrain terrain2;
|
||||||
|
do {
|
||||||
|
terrain2 = Terrain.values()[random.nextInt(Terrain.values().length)];
|
||||||
|
} while (terrain2 == terrain1); // Assurer deux terrains différents
|
||||||
|
|
||||||
|
int terrain1Sides = switch (random.nextInt(3)) { // 0, 1 ou 2 -> 1+5, 2+4, 3+3
|
||||||
|
case 0 -> 1;
|
||||||
|
case 1 -> 2;
|
||||||
|
default -> 3;
|
||||||
|
};
|
||||||
|
|
||||||
|
return new Tile(terrain1, terrain2, terrain1Sides);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@ public class GameView extends JFrame {
|
|||||||
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, long seed) {
|
public GameView(Board board, long seed) {
|
||||||
this.board = board;
|
this.board = board;
|
||||||
this.tileGenerator = new TileGenerator(seed); // Initialisation avec la seed
|
this.tileGenerator = new TileGenerator(seed); // Initialisation avec la seed
|
||||||
@@ -55,45 +56,42 @@ public class GameView extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawLargeHexagon(Graphics g, int x, int y, Tile tile) {
|
public void drawLargeHexagon(Graphics g, int x, int y, Tile tile) {
|
||||||
int r = hexRadius;
|
int r = hexRadius;
|
||||||
int h = (int) (Math.sqrt(3) / 2 * r);
|
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[] 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};
|
||||||
int[] yPoints = {y, y + h, y + h, y, y - h, y - h};
|
|
||||||
|
if (tile.hasSingleTerrain()) {
|
||||||
if (tile.hasSingleTerrain()) {
|
g.setColor(getColorForTerrain(tile.getTerrain1()));
|
||||||
// Une seule couleur : remplir tout l'hexagone
|
g.fillPolygon(xPoints, yPoints, 6);
|
||||||
g.setColor(getColorForTerrain(tile.getTerrain1()));
|
} else {
|
||||||
g.fillPolygon(xPoints, yPoints, 6);
|
// Deux terrains : appliquer la répartition spécifique
|
||||||
} else {
|
int terrain1Sides = tile.getTerrain1Sides();
|
||||||
// Deux terrains : Diviser l'hexagone en deux moitiés
|
Color color1 = getColorForTerrain(tile.getTerrain1());
|
||||||
Color color1 = getColorForTerrain(tile.getTerrain1());
|
Color color2 = getColorForTerrain(tile.getTerrain2());
|
||||||
Color color2 = getColorForTerrain(tile.getTerrain2());
|
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
// Premier terrain (moitié supérieure)
|
int next = (i + 1) % 6; // Prochain point
|
||||||
g.setColor(color1);
|
|
||||||
|
if (i < terrain1Sides) {
|
||||||
|
g.setColor(color1);
|
||||||
|
} else {
|
||||||
|
g.setColor(color2);
|
||||||
|
}
|
||||||
|
|
||||||
g.fillPolygon(
|
g.fillPolygon(
|
||||||
new int[]{xPoints[0], xPoints[1], xPoints[2], xPoints[3]},
|
new int[]{x, xPoints[i], xPoints[next]},
|
||||||
new int[]{yPoints[0], yPoints[1], yPoints[2], yPoints[3]},
|
new int[]{y, yPoints[i], yPoints[next]},
|
||||||
4
|
3
|
||||||
);
|
|
||||||
|
|
||||||
// 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
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Contour de l'hexagone
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
g.drawPolygon(xPoints, yPoints, 6);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawPolygon(xPoints, yPoints, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Dans la classe GameView.java
|
// Dans la classe GameView.java
|
||||||
|
Binary file not shown.
Reference in New Issue
Block a user