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 :
|
* Elle gère :
|
||||||
* - l’affichage des tours (PieceLayer)
|
* - l’affichage des tours (PieceLayer)
|
||||||
* - l’affichage des coups possibles (HighlightLayer)
|
* - l’affichage des coups possibles (HighlightLayer)
|
||||||
|
* - un fond graphique personnalisé
|
||||||
* - les clics via InteractionController
|
* - 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 {
|
public class BoardView extends JLayeredPane {
|
||||||
|
|
||||||
/** Référence au moteur Avalam */
|
/** Référence au moteur Avalam */
|
||||||
private AvalamBoard board;
|
private AvalamBoard board;
|
||||||
|
|
||||||
|
/** Couche d’affichage du fond */
|
||||||
|
private BackgroundLayer backgroundLayer;
|
||||||
|
|
||||||
/** Couche d’affichage des rond verts */
|
/** Couche d’affichage des rond verts */
|
||||||
private HighlightLayer highlightLayer;
|
private HighlightLayer highlightLayer;
|
||||||
|
|
||||||
/** Couche d’affichage des tours */
|
/** Couche d’affichage des pièces */
|
||||||
private PieceLayer pieceLayer;
|
private PieceLayer pieceLayer;
|
||||||
|
|
||||||
/** Contrôleur des interactions */
|
/** Contrôleur des interactions */
|
||||||
@@ -37,14 +38,11 @@ public class BoardView extends JLayeredPane {
|
|||||||
private final int xBase = 60;
|
private final int xBase = 60;
|
||||||
private final int yBase = 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;
|
private Runnable boardUpdateCallback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructeur de la vue du plateau.
|
* Constructeur.
|
||||||
*
|
|
||||||
* @param board moteur Avalam utilisé pour afficher la grille
|
|
||||||
* @param boardUpdateCallback callback appelé après chaque coup
|
|
||||||
*/
|
*/
|
||||||
public BoardView(AvalamBoard board, Runnable boardUpdateCallback) {
|
public BoardView(AvalamBoard board, Runnable boardUpdateCallback) {
|
||||||
this.board = board;
|
this.board = board;
|
||||||
@@ -52,28 +50,29 @@ public class BoardView extends JLayeredPane {
|
|||||||
|
|
||||||
setLayout(null);
|
setLayout(null);
|
||||||
|
|
||||||
// Contrôleur
|
// --- Contrôleur ---
|
||||||
this.controller = new InteractionController(board, this);
|
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);
|
highlightLayer = new HighlightLayer(xBase, yBase, spacing, size);
|
||||||
add(highlightLayer, JLayeredPane.DEFAULT_LAYER);
|
add(highlightLayer, JLayeredPane.DEFAULT_LAYER);
|
||||||
|
|
||||||
// Couche des pièces
|
// --- Couche des pièces ---
|
||||||
pieceLayer = new PieceLayer();
|
pieceLayer = new PieceLayer();
|
||||||
add(pieceLayer, JLayeredPane.PALETTE_LAYER);
|
add(pieceLayer, JLayeredPane.PALETTE_LAYER);
|
||||||
|
|
||||||
setPreferredSize(new Dimension(800, 800));
|
setPreferredSize(new Dimension(725, 725));
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Appelée par InteractionController quand un coup est joué.
|
* Appelé par le contrôleur après un coup.
|
||||||
* Permet à AvalamWindow de rafraîchir :
|
|
||||||
* - scores
|
|
||||||
* - affichage du joueur courant
|
|
||||||
* - détection fin de partie
|
|
||||||
*/
|
*/
|
||||||
public void onBoardUpdated() {
|
public void onBoardUpdated() {
|
||||||
if (boardUpdateCallback != null) {
|
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() {
|
public void refresh() {
|
||||||
|
|
||||||
// Mise à jour des pièces
|
|
||||||
pieceLayer.displayGrid(
|
pieceLayer.displayGrid(
|
||||||
boardGrid(),
|
boardGrid(),
|
||||||
xBase, yBase, spacing, size,
|
xBase, yBase, spacing, size,
|
||||||
(r, c) -> controller.onPieceClicked(r, c)
|
(r, c) -> controller.onPieceClicked(r, c)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Mise à jour des highlights
|
|
||||||
highlightLayer.setLegalMoves(controller.getLegalMoves());
|
highlightLayer.setLegalMoves(controller.getLegalMoves());
|
||||||
|
|
||||||
|
backgroundLayer.repaint();
|
||||||
highlightLayer.repaint();
|
highlightLayer.repaint();
|
||||||
pieceLayer.repaint();
|
pieceLayer.repaint();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renvoie la grille de tours depuis AvalamBoard.
|
* Récupère la grille depuis le moteur.
|
||||||
*/
|
*/
|
||||||
private Tower[][] boardGrid() {
|
private Tower[][] boardGrid() {
|
||||||
Tower[][] grid = new Tower[AvalamBoard.SIZE][AvalamBoard.SIZE];
|
Tower[][] grid = new Tower[AvalamBoard.SIZE][AvalamBoard.SIZE];
|
||||||
@@ -112,7 +110,27 @@ public class BoardView extends JLayeredPane {
|
|||||||
grid[r][c] = board.getTowerAt(r, c);
|
grid[r][c] = board.getTowerAt(r, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return grid;
|
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