Tile par rapport a la base de donnée + fix rotation tuile

This commit is contained in:
Vincent
2024-10-26 22:31:34 +02:00
parent f5c3fa6149
commit 70acc18573
42 changed files with 189 additions and 135 deletions

View File

@@ -1,76 +1,41 @@
package model;
import java.util.Random;
public class Tile {
private int id; // Ajoute l'attribut id
private TerrainType[] terrains; // 2 terrains maximum par tuile
private int segmentsForTerrain1; // Nombre de segments pour le premier terrain
private static final Random random = new Random();
private int segmentsForTerrain1;
private int rotation;
public Tile() {
this.terrains = new TerrainType[2]; // Seulement deux terrains
generateTerrains();
assignSegments();
this.rotation = 0; // Rotation initiale à 0
// Constructeur modifié pour inclure l'ID
public Tile(int id, TerrainType terrain1, TerrainType terrain2, int segmentsForTerrain1) {
this.id = id;
this.terrains = new TerrainType[]{terrain1, terrain2};
this.segmentsForTerrain1 = segmentsForTerrain1;
this.rotation = 0;
}
// Méthode pour tourner la tuile dans le sens des aiguilles d'une montre
public void rotateClockwise() {
rotation = (rotation + 1) % 6; // Modulo 6 pour garder une rotation entre 0 et 5
rotation = (rotation + 1) % 6;
}
// Méthode pour obtenir la rotation actuelle
public void rotateCounterClockwise() {
rotation = (rotation + 5) % 6; // Tourner dans le sens inverse, équivalent à -1 dans un modulo 6
}
public int getRotation() {
return rotation;
}
// Génère deux terrains aléatoires pour la tuile
private void generateTerrains() {
terrains[0] = generateRandomTerrain();
terrains[1] = generateRandomTerrain();
// Assure que les deux terrains sont différents
while (terrains[0] == terrains[1]) {
terrains[1] = generateRandomTerrain();
}
}
// Assigner le nombre de segments pour chaque terrain avec plus de diversité
private void assignSegments() {
// Terrain 1 occupe entre 1 et 5 segments, le reste pour le terrain 2
this.segmentsForTerrain1 = random.nextInt(5) + 1;
}
// Génère un terrain aléatoire avec plus de variété dans les probabilités
private TerrainType generateRandomTerrain() {
int rand = random.nextInt(100);
if (rand < 15) {
return TerrainType.MER; // 15% MER
} else if (rand < 30) {
return TerrainType.CHAMP; // 15% CHAMP
} else if (rand < 50) {
return TerrainType.PRE; // 20% PRE
} else if (rand < 75) {
return TerrainType.FORET; // 25% FORET
} else {
return TerrainType.MONTAGNE; // 25% MONTAGNE
}
public int getId() {
return id;
}
public TerrainType getTerrain(int index) {
if (index >= 0 && index < 2) {
return terrains[index];
}
return null;
return index >= 0 && index < 2 ? terrains[index] : null;
}
public int getSegmentsForTerrain(int index) {
if (index == 0) {
return segmentsForTerrain1; // Nombre de segments pour le premier terrain
} else {
return 6 - segmentsForTerrain1; // Le reste pour le second terrain
}
return index == 0 ? segmentsForTerrain1 : 6 - segmentsForTerrain1;
}
}