Compare commits
5 Commits
MecaniqueJ
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 25f8dcdc76 | |||
| 823b0fcae0 | |||
| 9f78dad6e5 | |||
| 830729ca21 | |||
| d95d52785e |
@@ -40,8 +40,7 @@ public class AvalamWindow extends JFrame {
|
||||
// Chargement du plateau initial depuis Plateau.txt
|
||||
// ----------------------------------------------------------
|
||||
Tower[][] initialGrid = BoardLoader.loadFromFile("fr/iut_fbleau/Res/Plateau.txt");
|
||||
// debug TEMP !!!!!!!!!
|
||||
System.out.println("DEBUG Plateau: Grid[0][0] = " + initialGrid[0][0]);
|
||||
|
||||
board = new AvalamBoard(initialGrid); // PLAYER1 commence
|
||||
|
||||
// ----------------------------------------------------------
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
fr/iut_fbleau/Res/BackgroundAvalam.png
Normal file
BIN
fr/iut_fbleau/Res/BackgroundAvalam.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
Reference in New Issue
Block a user