Réparation du score grâce à Luc (the goat)
This commit is contained in:
@@ -1,29 +0,0 @@
|
|||||||
package fr.monkhanny.dorfromantik.game;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class BiomeGroup {
|
|
||||||
private List<Pocket> pockets;
|
|
||||||
|
|
||||||
public BiomeGroup() {
|
|
||||||
pockets = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addPocket(Pocket pocket) {
|
|
||||||
pockets.add(pocket);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Pocket> getPockets() {
|
|
||||||
return pockets;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int calculateTotalScore() {
|
|
||||||
int totalScore = 0;
|
|
||||||
for (Pocket pocket : pockets) {
|
|
||||||
totalScore += pocket.calculateScore();
|
|
||||||
}
|
|
||||||
return totalScore;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@@ -6,9 +6,7 @@ import fr.monkhanny.dorfromantik.listeners.GameSpaceKeyListener;
|
|||||||
import fr.monkhanny.dorfromantik.listeners.GameMouseClickListener;
|
import fr.monkhanny.dorfromantik.listeners.GameMouseClickListener;
|
||||||
import fr.monkhanny.dorfromantik.listeners.GameMouseWheelListener;
|
import fr.monkhanny.dorfromantik.listeners.GameMouseWheelListener;
|
||||||
import fr.monkhanny.dorfromantik.Options;
|
import fr.monkhanny.dorfromantik.Options;
|
||||||
import fr.monkhanny.dorfromantik.enums.Biome;
|
|
||||||
import fr.monkhanny.dorfromantik.enums.Fonts;
|
import fr.monkhanny.dorfromantik.enums.Fonts;
|
||||||
import fr.monkhanny.dorfromantik.enums.TileOrientation;
|
|
||||||
import fr.monkhanny.dorfromantik.gui.GameControlsMenu;
|
import fr.monkhanny.dorfromantik.gui.GameControlsMenu;
|
||||||
import fr.monkhanny.dorfromantik.gui.GameOver;
|
import fr.monkhanny.dorfromantik.gui.GameOver;
|
||||||
import fr.monkhanny.dorfromantik.utils.Database;
|
import fr.monkhanny.dorfromantik.utils.Database;
|
||||||
@@ -34,33 +32,26 @@ public class Board extends JPanel{
|
|||||||
private int offsetX = 0; // Décalage horizontal du plateau
|
private int offsetX = 0; // Décalage horizontal du plateau
|
||||||
private int offsetY = 0; // Décalage vertical du plateau
|
private int offsetY = 0; // Décalage vertical du plateau
|
||||||
private Tile nextTile;
|
private Tile nextTile;
|
||||||
private Map<Biome, BiomeGroup> biomeGroups;
|
|
||||||
private Point mousePosition;
|
private Point mousePosition;
|
||||||
private ScoreManager scoreManager;
|
|
||||||
private int currentScore;
|
private int currentScore;
|
||||||
private Database database;
|
private Database database;
|
||||||
private RemainingTilesIndicator remainingTilesIndicator;
|
private RemainingTilesIndicator remainingTilesIndicator;
|
||||||
private ScoreDisplay scoreDisplay;
|
|
||||||
private GameControlsMenu controlsMenu;
|
private GameControlsMenu controlsMenu;
|
||||||
|
private ScoreManager scoreManager;
|
||||||
|
private ScoreDisplay scoreDisplay;
|
||||||
|
|
||||||
// Constructeur avec seed
|
// Constructeur avec seed
|
||||||
public Board(JFrame gameFrame, long seed) {
|
public Board(JFrame gameFrame, long seed) {
|
||||||
this.gameFrame = gameFrame;
|
this.gameFrame = gameFrame;
|
||||||
this.tiles = new ArrayList<>();
|
this.tiles = new ArrayList<>();
|
||||||
this.biomeGroups = new HashMap<>();
|
|
||||||
this.availablePositions = new ArrayList<>();
|
this.availablePositions = new ArrayList<>();
|
||||||
this.random = new Random(seed);
|
this.random = new Random(seed);
|
||||||
this.game = new Game(seed);
|
this.game = new Game(seed);
|
||||||
|
scoreManager = new ScoreManager();
|
||||||
|
|
||||||
this.scoreManager = new ScoreManager(biomeGroups);
|
|
||||||
Font scoreFont = Fonts.SCORE.getFont(30f); // Remplacez par votre logique de chargement de police
|
Font scoreFont = Fonts.SCORE.getFont(30f); // Remplacez par votre logique de chargement de police
|
||||||
scoreDisplay = new ScoreDisplay(scoreFont, 0, 40); // Position fixe
|
scoreDisplay = new ScoreDisplay(scoreFont, 0, 40); // Position fixe
|
||||||
|
|
||||||
for (Biome biome : Biome.values()) {
|
|
||||||
biomeGroups.put(biome, new BiomeGroup());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Placer une tuile centrale au démarrage
|
// Placer une tuile centrale au démarrage
|
||||||
initializeCentralTile();
|
initializeCentralTile();
|
||||||
|
|
||||||
@@ -189,25 +180,28 @@ public class Board extends JPanel{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Récupérer les coordonnées du clic
|
|
||||||
Point clickedPoint = e.getPoint();
|
Point clickedPoint = e.getPoint();
|
||||||
|
|
||||||
// Ajuster les coordonnées du clic en tenant compte du zoom et des déplacements
|
|
||||||
// Annuler l'effet du zoom et du déplacement
|
|
||||||
int adjustedX = (int)((clickedPoint.x - offsetX) / zoomFactor);
|
int adjustedX = (int)((clickedPoint.x - offsetX) / zoomFactor);
|
||||||
int adjustedY = (int)((clickedPoint.y - offsetY) / zoomFactor);
|
int adjustedY = (int)((clickedPoint.y - offsetY) / zoomFactor);
|
||||||
|
|
||||||
// Vérifiez si la position ajustée est dans la liste des positions disponibles et si la distance est suffisante
|
Point nearestPosition = null;
|
||||||
|
double minDistance = Double.MAX_VALUE;
|
||||||
|
|
||||||
for (Point position : availablePositions) {
|
for (Point position : availablePositions) {
|
||||||
// Vérifiez la distance entre le clic ajusté et la position
|
double distance = new Point(adjustedX, adjustedY).distance(position);
|
||||||
if (new Point(adjustedX, adjustedY).distance(position) < 20) {
|
if (distance < minDistance) {
|
||||||
placeTileAtPosition(position); // Place une tuile à cette position
|
minDistance = distance;
|
||||||
break; // Si une tuile est ajoutée, on peut sortir de la boucle
|
nearestPosition = position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nearestPosition != null && minDistance < 20) {
|
||||||
|
placeTileAtPosition(nearestPosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void initializeCentralTile() {
|
private void initializeCentralTile() {
|
||||||
int centerX = gameFrame.getWidth() / 2;
|
int centerX = gameFrame.getWidth() / 2;
|
||||||
int centerY = gameFrame.getHeight() / 2;
|
int centerY = gameFrame.getHeight() / 2;
|
||||||
@@ -215,6 +209,7 @@ public class Board extends JPanel{
|
|||||||
this.centralTile = new Tile(this, centerX, centerY, 50);
|
this.centralTile = new Tile(this, centerX, centerY, 50);
|
||||||
addTile(centralTile);
|
addTile(centralTile);
|
||||||
|
|
||||||
|
|
||||||
// Calculer les positions disponibles autour de la tuile centrale
|
// Calculer les positions disponibles autour de la tuile centrale
|
||||||
calculateAvailablePositions(centralTile);
|
calculateAvailablePositions(centralTile);
|
||||||
initializeNextTile();
|
initializeNextTile();
|
||||||
@@ -222,67 +217,19 @@ public class Board extends JPanel{
|
|||||||
|
|
||||||
public void addTile(Tile tile) {
|
public void addTile(Tile tile) {
|
||||||
tiles.add(tile);
|
tiles.add(tile);
|
||||||
updatePockets(tile);
|
scoreManager.addTile(tile);
|
||||||
calculateCurrentScore();
|
currentScore = scoreManager.getCurrentScore();
|
||||||
|
scoreDisplay.setScore(currentScore);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePockets(Tile newTile) {
|
|
||||||
for (TileOrientation orientation : TileOrientation.values()) {
|
|
||||||
Biome biome = newTile.getBiome(orientation);
|
|
||||||
BiomeGroup biomeGroup = biomeGroups.get(biome);
|
|
||||||
|
|
||||||
// Vérifier si la nouvelle tuile peut être connectée à une poche existante
|
public Tile getTileAt(int x, int y) {
|
||||||
Pocket connectedPocket = null;
|
for (Tile tile : tiles) {
|
||||||
for (Pocket pocket : biomeGroup.getPockets()) {
|
if (Math.abs(tile.getXCoord() - x) < 5 && Math.abs(tile.getYCoord() - y) < 5) {
|
||||||
if (isConnectedToPocket(newTile, pocket)) {
|
return tile;
|
||||||
connectedPocket = pocket;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connectedPocket != null) {
|
|
||||||
// Connecte la tuile à une poche existante
|
|
||||||
connectedPocket.addTile(newTile);
|
|
||||||
} else {
|
|
||||||
// Crée une nouvelle poche pour ce biome
|
|
||||||
Pocket newPocket = new Pocket(biome);
|
|
||||||
newPocket.addTile(newTile);
|
|
||||||
biomeGroup.addPocket(newPocket);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return null;
|
||||||
|
|
||||||
// Méthode pour vérifier si une tuile est connectée à une poche existante
|
|
||||||
private boolean isConnectedToPocket(Tile tile, Pocket pocket) {
|
|
||||||
for (Tile connectedTile : pocket.getTiles()) {
|
|
||||||
if (areTilesConnected(tile, connectedTile)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Vérifie si deux tuiles sont connectées par un même biome
|
|
||||||
private boolean areTilesConnected(Tile tile1, Tile tile2) {
|
|
||||||
for (TileOrientation orientation : TileOrientation.values()) {
|
|
||||||
if (tile1.getBiome(orientation).equals(tile2.getBiome(orientation.oppositeOrientation()))) {
|
|
||||||
// Vérifier si les tuiles sont adjacentes (logique à adapter selon vos besoins)
|
|
||||||
// Exemple : si elles partagent un côté commun
|
|
||||||
return tile1.isAdjacentTo(tile2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void calculateCurrentScore() {
|
|
||||||
scoreManager.updateScore(); // Met à jour le score
|
|
||||||
currentScore = scoreManager.getCurrentScore(); // Récupère le score actuel
|
|
||||||
scoreDisplay.setScore(currentScore); // Met à jour l'affichage du score
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCurrentScore() {
|
|
||||||
return currentScore;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Random getRandom() { return random; }
|
public Random getRandom() { return random; }
|
||||||
@@ -435,6 +382,7 @@ public class Board extends JPanel{
|
|||||||
|
|
||||||
scoreDisplay.draw(g);
|
scoreDisplay.draw(g);
|
||||||
|
|
||||||
|
|
||||||
// Appliquer l'échelle de zoom et le déplacement
|
// Appliquer l'échelle de zoom et le déplacement
|
||||||
g2d.scale(zoomFactor, zoomFactor); // Appliquer le zoom
|
g2d.scale(zoomFactor, zoomFactor); // Appliquer le zoom
|
||||||
g2d.translate(offsetX / zoomFactor, offsetY / zoomFactor); // Appliquer le déplacement (en tenant compte du zoom)
|
g2d.translate(offsetX / zoomFactor, offsetY / zoomFactor); // Appliquer le déplacement (en tenant compte du zoom)
|
||||||
|
@@ -1,15 +1,16 @@
|
|||||||
package fr.monkhanny.dorfromantik.game;
|
package fr.monkhanny.dorfromantik.game;
|
||||||
|
|
||||||
import fr.monkhanny.dorfromantik.enums.Biome;
|
import fr.monkhanny.dorfromantik.enums.Biome;
|
||||||
|
import fr.monkhanny.dorfromantik.enums.TileOrientation;
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
/**
|
||||||
import java.util.HashSet;
|
* Represents a connected pocket of tiles with the same biome.
|
||||||
import java.util.List;
|
*/
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class Pocket {
|
public class Pocket {
|
||||||
private Biome biome;
|
private Biome biome;
|
||||||
private Set<Tile> tiles; // Ensemble des tuiles de la poche
|
private Set<Tile> tiles;
|
||||||
|
|
||||||
public Pocket(Biome biome) {
|
public Pocket(Biome biome) {
|
||||||
this.biome = biome;
|
this.biome = biome;
|
||||||
@@ -20,24 +21,15 @@ public class Pocket {
|
|||||||
tiles.add(tile);
|
tiles.add(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsTile(Tile tile) {
|
public int getSize() {
|
||||||
return tiles.contains(tile);
|
return tiles.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Biome getBiome() {
|
public Biome getBiome() {
|
||||||
return biome;
|
return biome;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSize() {
|
public Set<Tile> getTiles() {
|
||||||
return tiles.size();
|
return tiles;
|
||||||
}
|
|
||||||
|
|
||||||
public int calculateScore() {
|
|
||||||
// Calcul du score basé sur la taille de la poche
|
|
||||||
return getSize() * getSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Tile> getTiles() {
|
|
||||||
return new ArrayList<>(tiles);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -7,7 +7,7 @@ import java.awt.Graphics;
|
|||||||
public class ScoreDisplay {
|
public class ScoreDisplay {
|
||||||
private int score;
|
private int score;
|
||||||
private Font font;
|
private Font font;
|
||||||
private int x, y; // Position du score
|
private int x, y; // Position du texte
|
||||||
|
|
||||||
public ScoreDisplay(Font font, int x, int y) {
|
public ScoreDisplay(Font font, int x, int y) {
|
||||||
this.font = font;
|
this.font = font;
|
||||||
|
@@ -1,44 +1,139 @@
|
|||||||
package fr.monkhanny.dorfromantik.game;
|
package fr.monkhanny.dorfromantik.game;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import fr.monkhanny.dorfromantik.enums.Biome;
|
import fr.monkhanny.dorfromantik.enums.Biome;
|
||||||
|
import fr.monkhanny.dorfromantik.enums.TileOrientation;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Classe responsable du calcul et de la gestion du score.
|
* Manages the score of the game, keeping track of biome pockets.
|
||||||
*/
|
*/
|
||||||
public class ScoreManager {
|
public class ScoreManager {
|
||||||
private int currentScore = 0;
|
private List<Pocket> pockets;
|
||||||
private Map<Biome, BiomeGroup> biomeGroups;
|
private int currentScore;
|
||||||
|
|
||||||
// Constructeur avec la référence aux groupes de biomes
|
public ScoreManager() {
|
||||||
public ScoreManager(Map<Biome, BiomeGroup> biomeGroups) {
|
pockets = new ArrayList<>();
|
||||||
this.biomeGroups = biomeGroups;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Méthode pour calculer le score en fonction des groupes de biomes
|
|
||||||
public void calculateScore() {
|
|
||||||
int totalScore = 0;
|
|
||||||
|
|
||||||
for (BiomeGroup group : biomeGroups.values()) {
|
|
||||||
totalScore += group.calculateTotalScore();
|
|
||||||
}
|
|
||||||
|
|
||||||
currentScore = totalScore;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Récupérer le score actuel
|
|
||||||
public int getCurrentScore() {
|
|
||||||
return currentScore;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mettre à jour le score (si nécessaire)
|
|
||||||
public void updateScore() {
|
|
||||||
calculateScore();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Réinitialiser le score
|
|
||||||
public void resetScore() {
|
|
||||||
currentScore = 0;
|
currentScore = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a tile to the appropriate pocket or creates a new one if necessary.
|
||||||
|
*
|
||||||
|
* @param tile The tile to add.
|
||||||
|
*/
|
||||||
|
public void addTile(Tile tile) {
|
||||||
|
Map<Biome, Pocket> biomeToPocketMap = new HashMap<>();
|
||||||
|
|
||||||
|
// Trouver les poches existantes auxquelles cette tuile peut être connectée, en vérifiant les voisins directs
|
||||||
|
for (TileOrientation orientation : TileOrientation.values()) {
|
||||||
|
Biome biome = tile.getBiome(orientation);
|
||||||
|
if (biome != null) {
|
||||||
|
// Trouver la tuile voisine dans la direction donnée
|
||||||
|
Tile neighborTile = tile.getNeighbor(orientation);
|
||||||
|
if (neighborTile != null && neighborTile.getBiome(orientation.oppositeOrientation()) == biome) {
|
||||||
|
Pocket connectedPocket = findPocketForTile(neighborTile, biome);
|
||||||
|
if (connectedPocket != null && !biomeToPocketMap.containsKey(biome)) {
|
||||||
|
biomeToPocketMap.put(biome, connectedPocket);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ajouter la tuile aux poches existantes ou créer une nouvelle poche si aucune n'est trouvée
|
||||||
|
for (TileOrientation orientation : TileOrientation.values()) {
|
||||||
|
Biome biome = tile.getBiome(orientation);
|
||||||
|
if (biome != null) {
|
||||||
|
if (biomeToPocketMap.containsKey(biome)) {
|
||||||
|
// Ajouter la tuile à la poche existante pour ce biome
|
||||||
|
biomeToPocketMap.get(biome).addTile(tile);
|
||||||
|
} else {
|
||||||
|
// Créer une nouvelle poche pour ce biome
|
||||||
|
Pocket newPocket = new Pocket(biome);
|
||||||
|
newPocket.addTile(tile);
|
||||||
|
pockets.add(newPocket);
|
||||||
|
biomeToPocketMap.put(biome, newPocket);
|
||||||
|
System.out.println("New pocket created with biome: " + biome);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recalculer le score après avoir ajouté la tuile
|
||||||
|
recalculateScore();
|
||||||
|
System.out.println("Current Score: " + currentScore);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the pocket associated with the given tile and biome.
|
||||||
|
*
|
||||||
|
* @param tile The tile to check.
|
||||||
|
* @param biome The biome to match.
|
||||||
|
* @return The connected pocket, or null if none found.
|
||||||
|
*/
|
||||||
|
private Pocket findPocketForTile(Tile tile, Biome biome) {
|
||||||
|
for (Pocket pocket : pockets) {
|
||||||
|
if (pocket.getBiome() == biome && pocket.getTiles().contains(tile)) {
|
||||||
|
return pocket;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds a pocket connected to the given tile with the specified biome.
|
||||||
|
*
|
||||||
|
* @param tile The tile to check connections for.
|
||||||
|
* @param biome The biome to match.
|
||||||
|
* @return The connected pocket, or null if none found.
|
||||||
|
*/
|
||||||
|
private Pocket findConnectedPocket(Tile tile, Biome biome) {
|
||||||
|
for (Pocket pocket : pockets) {
|
||||||
|
if (pocket.getBiome() == biome) {
|
||||||
|
for (Tile pocketTile : pocket.getTiles()) {
|
||||||
|
if (pocketTile.isAdjacentTo(tile) && sharesBiome(tile, pocketTile, biome)) {
|
||||||
|
return pocket;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if two tiles share a biome on any of their sides.
|
||||||
|
*
|
||||||
|
* @param tile1 The first tile.
|
||||||
|
* @param tile2 The second tile.
|
||||||
|
* @param biome The biome to match.
|
||||||
|
* @return True if the tiles share the given biome on a connecting side.
|
||||||
|
*/
|
||||||
|
private boolean sharesBiome(Tile tile1, Tile tile2, Biome biome) {
|
||||||
|
for (TileOrientation orientation : TileOrientation.values()) {
|
||||||
|
if (tile1.getBiome(orientation) == biome && tile2.getBiome(orientation.oppositeOrientation()) == biome) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recalculates the score based on the current pockets.
|
||||||
|
*/
|
||||||
|
private void recalculateScore() {
|
||||||
|
currentScore = 0;
|
||||||
|
for (Pocket pocket : pockets) {
|
||||||
|
currentScore += Math.pow(pocket.getSize(), 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCurrentScore() {
|
||||||
|
return currentScore;
|
||||||
|
}
|
||||||
}
|
}
|
@@ -139,21 +139,67 @@ public class Tile extends Cell {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isAdjacentTo(Tile otherTile) {
|
public boolean isAdjacentTo(Tile otherTile) {
|
||||||
// Obtenir le rayon de la tuile
|
|
||||||
int tileRadius = this.getRadius();
|
|
||||||
|
|
||||||
// Compute the distance between the center of this tile and the other tile
|
int radius = this.getRadius(); // Utilisation du rayon pour la distance correcte
|
||||||
int deltaX = this.getX() - otherTile.getX();
|
|
||||||
int deltaY = this.getY() - otherTile.getY();
|
|
||||||
|
|
||||||
// Calculate the Euclidean distance between the two tiles
|
// Calculer les différences de position
|
||||||
double distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
int deltaX = otherTile.getXCoord() - this.getXCoord();
|
||||||
|
int deltaY = otherTile.getYCoord() - this.getYCoord();
|
||||||
|
|
||||||
// In a hexagonal grid, two tiles are adjacent if their distance is equal to the diameter (2 * radius)
|
// Calculer la distance euclidienne entre les deux tuiles
|
||||||
return distance <= (2 * tileRadius);
|
double distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||||
|
|
||||||
|
// Distance attendue pour des tuiles adjacentes dans une grille hexagonale
|
||||||
|
double expectedDistance = (int) (1.5 * radius); // ou une autre valeur calculée correctement
|
||||||
|
|
||||||
|
// Définir une tolérance pour la précision
|
||||||
|
double epsilon = 15.0;
|
||||||
|
|
||||||
|
// Vérifier si la différence de distance est dans la tolérance
|
||||||
|
if (Math.abs(distance - expectedDistance) < epsilon) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Tile getNeighbor(TileOrientation orientation) {
|
||||||
|
int radius = this.getRadius();
|
||||||
|
int neighborX = this.getXCoord();
|
||||||
|
int neighborY = this.getYCoord();
|
||||||
|
|
||||||
|
switch (orientation) {
|
||||||
|
case NORTH:
|
||||||
|
neighborY -= (int) (Math.sqrt(3) * radius);
|
||||||
|
break;
|
||||||
|
case NORTH_EAST:
|
||||||
|
neighborX += (int) (1.5 * radius);
|
||||||
|
neighborY -= (int) (Math.sqrt(3) / 2 * radius);
|
||||||
|
break;
|
||||||
|
case SOUTH_EAST:
|
||||||
|
neighborX += (int) (1.5 * radius);
|
||||||
|
neighborY += (int) (Math.sqrt(3) / 2 * radius);
|
||||||
|
break;
|
||||||
|
case SOUTH:
|
||||||
|
neighborY += (int) (Math.sqrt(3) * radius);
|
||||||
|
break;
|
||||||
|
case SOUTH_WEST:
|
||||||
|
neighborX -= (int) (1.5 * radius);
|
||||||
|
neighborY += (int) (Math.sqrt(3) / 2 * radius);
|
||||||
|
break;
|
||||||
|
case NORTH_WEST:
|
||||||
|
neighborX -= (int) (1.5 * radius);
|
||||||
|
neighborY -= (int) (Math.sqrt(3) / 2 * radius);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rechercher la tuile à la position calculée
|
||||||
|
return this.getBoard().getTileAt(neighborX, neighborY);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private TileOrientation determineSide(int x, int y) {
|
private TileOrientation determineSide(int x, int y) {
|
||||||
int radius = this.getRadius();
|
int radius = this.getRadius();
|
||||||
TileOrientation[] sides = TileOrientation.values();
|
TileOrientation[] sides = TileOrientation.values();
|
||||||
|
Reference in New Issue
Block a user