Files
SAE31_2024/src/main/java/model/Tile.java

50 lines
1.6 KiB
Java
Raw Normal View History

2024-10-21 13:21:22 +02:00
package model;
public class Tile {
2024-10-27 16:58:15 +01:00
private int id; // ID de la tuile
private TerrainType[] terrains; // Tableau contenant deux types de terrains (ex. MER, FORET)
private int segmentsForTerrain1; // Nombre de segments pour le premier terrain
private int rotation; // Rotation de la tuile (en multiple de 60 degrés)
2024-10-21 13:21:22 +02:00
public Tile(int id, TerrainType terrain1, TerrainType terrain2, int segmentsForTerrain1) {
this.id = id;
this.terrains = new TerrainType[]{terrain1, terrain2};
this.segmentsForTerrain1 = segmentsForTerrain1;
2024-10-27 16:58:15 +01:00
this.rotation = 0; // Initialisation de la rotation à 0
}
// Renvoie le terrain pour l'index donné (0 ou 1)
public TerrainType getTerrain(int index) {
if (index >= 0 && index < terrains.length) {
return terrains[index];
}
return null; // Retourne null si l'index est invalide
}
// Méthode pour obtenir le terrain associé à un segment spécifique (prend en compte la rotation)
public TerrainType getTerrainForSegment(int segmentIndex) {
int adjustedIndex = (segmentIndex - rotation + 6) % 6;
if (adjustedIndex < segmentsForTerrain1) {
return terrains[0];
} else {
return terrains[1];
}
}
public void rotateClockwise() {
rotation = (rotation + 1) % 6;
}
public void rotateCounterClockwise() {
2024-10-27 16:58:15 +01:00
rotation = (rotation + 5) % 6; // Tourner dans le sens inverse
2024-10-21 13:21:22 +02:00
}
public int getRotation() {
return rotation;
2024-10-25 00:59:58 +02:00
}
public int getId() {
return id;
2024-10-21 13:21:22 +02:00
}
}