Fond avalam board
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
@@ -0,0 +1,9 @@
|
||||
0,0,1,2,0,0,0,0,0
|
||||
0,1,2,1,2,0,0,0,0
|
||||
0,2,1,2,1,2,1,0,0
|
||||
0,1,2,1,2,1,2,1,2
|
||||
1,2,1,2,0,2,1,2,1
|
||||
2,1,2,1,2,1,2,1,0
|
||||
0,0,1,2,1,2,1,2,0
|
||||
0,0,0,0,2,1,2,1,0
|
||||
0,0,0,0,0,2,1,0,0
|
||||
@@ -12,20 +12,21 @@ import java.awt.*;
|
||||
* Elle gère :
|
||||
* - l’affichage des tours (PieceLayer)
|
||||
* - l’affichage des coups possibles (HighlightLayer)
|
||||
* - un fond graphique personnalisé
|
||||
* - les clics via InteractionController
|
||||
*
|
||||
* Toute la logique de jeu est déléguée au moteur AvalamBoard
|
||||
* et au contrôleur InteractionController.
|
||||
*/
|
||||
public class BoardView extends JLayeredPane {
|
||||
|
||||
/** Référence au moteur Avalam */
|
||||
private AvalamBoard board;
|
||||
|
||||
/** Couche d’affichage du fond */
|
||||
private BackgroundLayer backgroundLayer;
|
||||
|
||||
/** Couche d’affichage des rond verts */
|
||||
private HighlightLayer highlightLayer;
|
||||
|
||||
/** Couche d’affichage des tours */
|
||||
/** Couche d’affichage des pièces */
|
||||
private PieceLayer pieceLayer;
|
||||
|
||||
/** Contrôleur des interactions */
|
||||
@@ -37,14 +38,11 @@ public class BoardView extends JLayeredPane {
|
||||
private final int xBase = 60;
|
||||
private final int yBase = 60;
|
||||
|
||||
/** Callback vers AvalamWindow pour mises à jour (score, tour, fin de partie) */
|
||||
/** Callback vers AvalamWindow pour mises à jour (score, tour, fin) */
|
||||
private Runnable boardUpdateCallback;
|
||||
|
||||
/**
|
||||
* Constructeur de la vue du plateau.
|
||||
*
|
||||
* @param board moteur Avalam utilisé pour afficher la grille
|
||||
* @param boardUpdateCallback callback appelé après chaque coup
|
||||
* Constructeur.
|
||||
*/
|
||||
public BoardView(AvalamBoard board, Runnable boardUpdateCallback) {
|
||||
this.board = board;
|
||||
@@ -52,28 +50,29 @@ public class BoardView extends JLayeredPane {
|
||||
|
||||
setLayout(null);
|
||||
|
||||
// Contrôleur
|
||||
// --- Contrôleur ---
|
||||
this.controller = new InteractionController(board, this);
|
||||
|
||||
// Couche Highlight
|
||||
// --- Couche fond ---
|
||||
backgroundLayer = new BackgroundLayer("fr/iut_fbleau/Res/BackgroundAvalam.png");
|
||||
backgroundLayer.setBounds(0, 0, 725, 725);
|
||||
add(backgroundLayer, JLayeredPane.FRAME_CONTENT_LAYER);
|
||||
|
||||
// --- Couche highlight ---
|
||||
highlightLayer = new HighlightLayer(xBase, yBase, spacing, size);
|
||||
add(highlightLayer, JLayeredPane.DEFAULT_LAYER);
|
||||
|
||||
// Couche des pièces
|
||||
// --- Couche des pièces ---
|
||||
pieceLayer = new PieceLayer();
|
||||
add(pieceLayer, JLayeredPane.PALETTE_LAYER);
|
||||
|
||||
setPreferredSize(new Dimension(800, 800));
|
||||
setPreferredSize(new Dimension(725, 725));
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Appelée par InteractionController quand un coup est joué.
|
||||
* Permet à AvalamWindow de rafraîchir :
|
||||
* - scores
|
||||
* - affichage du joueur courant
|
||||
* - détection fin de partie
|
||||
* Appelé par le contrôleur après un coup.
|
||||
*/
|
||||
public void onBoardUpdated() {
|
||||
if (boardUpdateCallback != null) {
|
||||
@@ -82,27 +81,26 @@ public class BoardView extends JLayeredPane {
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour toutes les couches visuelles.
|
||||
* Rafraîchit les couches visuelles.
|
||||
*/
|
||||
public void refresh() {
|
||||
|
||||
// Mise à jour des pièces
|
||||
pieceLayer.displayGrid(
|
||||
boardGrid(),
|
||||
xBase, yBase, spacing, size,
|
||||
(r, c) -> controller.onPieceClicked(r, c)
|
||||
);
|
||||
|
||||
// Mise à jour des highlights
|
||||
highlightLayer.setLegalMoves(controller.getLegalMoves());
|
||||
|
||||
backgroundLayer.repaint();
|
||||
highlightLayer.repaint();
|
||||
pieceLayer.repaint();
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie la grille de tours depuis AvalamBoard.
|
||||
* Récupère la grille depuis le moteur.
|
||||
*/
|
||||
private Tower[][] boardGrid() {
|
||||
Tower[][] grid = new Tower[AvalamBoard.SIZE][AvalamBoard.SIZE];
|
||||
@@ -112,7 +110,27 @@ public class BoardView extends JLayeredPane {
|
||||
grid[r][c] = board.getTowerAt(r, c);
|
||||
}
|
||||
}
|
||||
|
||||
return grid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Composant affichant l’image de fond.
|
||||
*/
|
||||
private static class BackgroundLayer extends JComponent {
|
||||
private Image img;
|
||||
|
||||
public BackgroundLayer(String resourcePath) {
|
||||
img = Toolkit.getDefaultToolkit().getImage(
|
||||
getClass().getClassLoader().getResource(resourcePath)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (img != null) {
|
||||
g.drawImage(img, 0, 0, getWidth(), getHeight(), this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user