Correction de bug d'affichage
This commit is contained in:
@@ -53,4 +53,6 @@ public class Options {
|
||||
public static final Dimension MINIMUM_FRAME_SIZE = new Dimension(700, 700);
|
||||
|
||||
public static boolean AUTO_FOCUS = true;
|
||||
|
||||
public static final int MAX_TILE_NUMBER = 5;
|
||||
}
|
||||
|
@@ -230,16 +230,21 @@ public class Board extends JPanel{
|
||||
public void placeTileAtPosition(Point position) {
|
||||
// Vérifie si la position est disponible et que la tuile n'est pas déjà placée à cet endroit
|
||||
if (availablePositions.contains(position) && !isTileAtPosition(position)) {
|
||||
Tile newTile = new Tile(this, position.x, position.y, 50);
|
||||
if (tiles.size() < Options.MAX_TILE_NUMBER) {
|
||||
Tile newTile = new Tile(this, position.x, position.y, 50);
|
||||
|
||||
// Vérifier que la tuile ne se chevauche pas avec l'ancienne tuile
|
||||
if (!isTileAtPosition(new Point(newTile.getXCoord(), newTile.getYCoord()))) {
|
||||
addTile(newTile);
|
||||
calculateAvailablePositions(newTile); // Calculer de nouvelles positions disponibles
|
||||
repaint(); // Re-dessiner le plateau
|
||||
// Vérifier que la tuile ne se chevauche pas avec l'ancienne tuile
|
||||
if (!isTileAtPosition(new Point(newTile.getXCoord(), newTile.getYCoord()))) {
|
||||
addTile(newTile);
|
||||
calculateAvailablePositions(newTile); // Calculer de nouvelles positions disponibles
|
||||
repaint(); // Re-dessiner le plateau
|
||||
}
|
||||
|
||||
autoReFocus(newTile); // Réinitialiser le zoom et le déplacement
|
||||
}else{
|
||||
// NOMBRE DE TUILES MAXIMUM ATTEINT
|
||||
// FIN DE LA PARTIE
|
||||
}
|
||||
|
||||
autoReFocus(newTile); // Réinitialiser le zoom et le déplacement
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,7 +328,10 @@ public class Board extends JPanel{
|
||||
|
||||
// Dessiner les tuiles existantes
|
||||
for (Tile tile : tiles) {
|
||||
tile.paintTileWithPosition(g, 1f);
|
||||
int tileX = tile.getXCoord();
|
||||
int tileY = tile.getYCoord();
|
||||
|
||||
tile.drawTileAt(g,tileX-50,tileY-50,1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -259,6 +259,21 @@ public class Tile extends Cell {
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawTileAt(Graphics g, int x, int y, float scale) {
|
||||
// Sauvegarde de l'état actuel du graphique
|
||||
Graphics2D g2d = (Graphics2D) g.create();
|
||||
|
||||
// Déplacement du contexte graphique à la position souhaitée
|
||||
g2d.translate(x, y);
|
||||
|
||||
// Appel de la méthode de dessin de la tuile à la nouvelle position
|
||||
paintTile(g2d, scale);
|
||||
|
||||
// Restauration de l'état graphique (annule le déplacement)
|
||||
g2d.dispose();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Méthode principale de dessin de la tuile.
|
||||
*
|
||||
@@ -296,39 +311,4 @@ public class Tile extends Cell {
|
||||
g2d.dispose();
|
||||
}
|
||||
|
||||
protected void paintTileWithPosition(Graphics g, float scale) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g.create();
|
||||
int radius = this.getRadius();
|
||||
Point center = new Point(this.getXCoord(), this.getYCoord());
|
||||
radius = (int) (radius * scale);
|
||||
Hexagon hexagon = new Hexagon(center, radius);
|
||||
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2d.setClip(hexagon);
|
||||
|
||||
double hexRadius = radius / Math.sqrt(3) / 3;
|
||||
double paddingX = center.x - radius;
|
||||
double paddingY = center.y - radius;
|
||||
|
||||
this.drawHexagonRow(g2d, paddingX + radius * 0.5, paddingY + radius - radius * Math.sqrt(3) / 2, hexRadius, 4);
|
||||
this.drawHexagonRow(g2d, paddingX, paddingY + radius - radius * Math.sqrt(3) / 3, hexRadius, 6);
|
||||
this.drawHexagonRow(g2d, paddingX - radius * 0.5, paddingY + radius - radius * Math.sqrt(3) / 6, hexRadius, 8);
|
||||
this.drawHexagonRow(g2d, paddingX - radius, paddingY + radius, hexRadius, 10);
|
||||
this.drawHexagonRow(g2d, paddingX - radius * 0.5, paddingY + radius + radius * Math.sqrt(3) / 6, hexRadius, 8);
|
||||
this.drawHexagonRow(g2d, paddingX, paddingY + radius + radius * Math.sqrt(3) / 3, hexRadius, 6);
|
||||
this.drawHexagonRow(g2d, paddingX + radius * 0.5, paddingY + radius + radius * Math.sqrt(3) / 2, hexRadius, 4);
|
||||
|
||||
g2d.setClip(null);
|
||||
g2d.setStroke(new BasicStroke((int) radius / 15));
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawPolygon(hexagon);
|
||||
|
||||
g2d.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
this.paintTile(g, 1f);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user