Compare commits
7 Commits
1921b523c6
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 25f8dcdc76 | |||
| 823b0fcae0 | |||
| 9f78dad6e5 | |||
| 830729ca21 | |||
| d95d52785e | |||
| ddf9b00c0a | |||
| c1e5de9ed2 |
17
Makefile
17
Makefile
@@ -2,6 +2,10 @@
|
|||||||
SRC_DIR = fr
|
SRC_DIR = fr
|
||||||
BIN_DIR = bin
|
BIN_DIR = bin
|
||||||
|
|
||||||
|
# === Répertoires des ressources ===
|
||||||
|
RES_SRC = fr/iut_fbleau/Res
|
||||||
|
RES_BIN = bin/fr/iut_fbleau/Res
|
||||||
|
|
||||||
# === Recherche automatique des fichiers .java dans tous les sous-dossiers ===
|
# === Recherche automatique des fichiers .java dans tous les sous-dossiers ===
|
||||||
SOURCES := $(shell find $(SRC_DIR) -name "*.java")
|
SOURCES := $(shell find $(SRC_DIR) -name "*.java")
|
||||||
|
|
||||||
@@ -19,11 +23,20 @@ JAVAFLAGS = -cp $(BIN_DIR)
|
|||||||
all: build
|
all: build
|
||||||
|
|
||||||
# === Compilation ===
|
# === Compilation ===
|
||||||
build:
|
build: compile resources
|
||||||
|
@echo "✔ Compilation terminée."
|
||||||
|
|
||||||
|
compile:
|
||||||
@echo "===> Compilation du projet Avalam..."
|
@echo "===> Compilation du projet Avalam..."
|
||||||
@mkdir -p $(BIN_DIR)
|
@mkdir -p $(BIN_DIR)
|
||||||
@$(JC) $(JCFLAGS) $(SOURCES)
|
@$(JC) $(JCFLAGS) $(SOURCES)
|
||||||
@echo "✔ Compilation terminée."
|
|
||||||
|
# === Copie des ressources (.txt) dans bin ===
|
||||||
|
resources:
|
||||||
|
@echo "===> Copie des ressources..."
|
||||||
|
@mkdir -p $(RES_BIN)
|
||||||
|
@cp $(RES_SRC)/* $(RES_BIN)/
|
||||||
|
@echo "✔ Ressources copiées."
|
||||||
|
|
||||||
# === Exécution ===
|
# === Exécution ===
|
||||||
run:
|
run:
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ public class AvalamWindow extends JFrame {
|
|||||||
// Chargement du plateau initial depuis Plateau.txt
|
// Chargement du plateau initial depuis Plateau.txt
|
||||||
// ----------------------------------------------------------
|
// ----------------------------------------------------------
|
||||||
Tower[][] initialGrid = BoardLoader.loadFromFile("fr/iut_fbleau/Res/Plateau.txt");
|
Tower[][] initialGrid = BoardLoader.loadFromFile("fr/iut_fbleau/Res/Plateau.txt");
|
||||||
|
|
||||||
board = new AvalamBoard(initialGrid); // PLAYER1 commence
|
board = new AvalamBoard(initialGrid); // PLAYER1 commence
|
||||||
|
|
||||||
// ----------------------------------------------------------
|
// ----------------------------------------------------------
|
||||||
@@ -97,10 +98,10 @@ public class AvalamWindow extends JFrame {
|
|||||||
String msg;
|
String msg;
|
||||||
|
|
||||||
switch (res) {
|
switch (res) {
|
||||||
case WIN -> msg = "Le joueur jaune a gagné !";
|
case WIN : msg = "Le joueur jaune a gagné !";
|
||||||
case LOSS -> msg = "Le joueur rouge a gagné !";
|
case LOSS : msg = "Le joueur rouge a gagné !";
|
||||||
case DRAW -> msg = "Égalité !";
|
case DRAW : msg = "Égalité !";
|
||||||
default -> msg = "Fin de partie.";
|
default : msg = "Fin de partie.";
|
||||||
}
|
}
|
||||||
|
|
||||||
JOptionPane.showMessageDialog(this, msg, "Partie terminée",
|
JOptionPane.showMessageDialog(this, msg, "Partie terminée",
|
||||||
|
|||||||
@@ -3,39 +3,55 @@ package fr.iut_fbleau.Avalam.logic;
|
|||||||
import fr.iut_fbleau.Avalam.Color;
|
import fr.iut_fbleau.Avalam.Color;
|
||||||
import fr.iut_fbleau.Avalam.Tower;
|
import fr.iut_fbleau.Avalam.Tower;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
/**
|
|
||||||
* Charge un plateau Avalam depuis un fichier texte.
|
|
||||||
* Format attendu : matrice 9×9 de 0,1,2 séparés par virgule.
|
|
||||||
*/
|
|
||||||
public class BoardLoader {
|
public class BoardLoader {
|
||||||
|
|
||||||
public static Tower[][] loadFromFile(String file) {
|
public static Tower[][] loadFromFile(String resourcePath) {
|
||||||
|
|
||||||
Tower[][] grid = new Tower[9][9];
|
Tower[][] grid = new Tower[9][9];
|
||||||
|
|
||||||
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
|
InputStream in = BoardLoader.class.getResourceAsStream("/" + resourcePath);
|
||||||
|
|
||||||
|
if (in == null) {
|
||||||
|
System.err.println("❌ Ressource introuvable : /" + resourcePath);
|
||||||
|
return grid;
|
||||||
|
}
|
||||||
|
|
||||||
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
int row = 0;
|
int row = 0;
|
||||||
|
|
||||||
while ((line = br.readLine()) != null && row < 9) {
|
while ((line = reader.readLine()) != null && row < 9) {
|
||||||
|
|
||||||
String[] vals = line.split(",");
|
// 🔥 Accepte SOIT les espaces, SOIT les virgules
|
||||||
|
line = line.replace(",", " ");
|
||||||
|
String[] parts = line.trim().split("\\s+");
|
||||||
|
|
||||||
for (int col = 0; col < 9; col++) {
|
for (int col = 0; col < 9; col++) {
|
||||||
int v = Integer.parseInt(vals[col].trim());
|
int value = Integer.parseInt(parts[col]);
|
||||||
|
|
||||||
switch (v) {
|
switch (value) {
|
||||||
case 1 -> grid[row][col] = new Tower(Color.YELLOW);
|
case 1:
|
||||||
case 2 -> grid[row][col] = new Tower(Color.RED);
|
grid[row][col] = new Tower(Color.YELLOW);
|
||||||
default -> grid[row][col] = null;
|
break;
|
||||||
|
case 2:
|
||||||
|
grid[row][col] = new Tower(Color.RED);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
grid[row][col] = null;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
row++;
|
row++;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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