Maj BoardLoader + makefile

This commit is contained in:
2025-11-27 13:06:14 +01:00
parent 1921b523c6
commit c1e5de9ed2
27 changed files with 61 additions and 21 deletions

View File

@@ -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:

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.

View File

@@ -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

View File

@@ -40,6 +40,8 @@ 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");
// debug TEMP !!!!!!!!!
System.out.println("DEBUG Plateau: Grid[0][0] = " + initialGrid[0][0]);
board = new AvalamBoard(initialGrid); // PLAYER1 commence board = new AvalamBoard(initialGrid); // PLAYER1 commence
// ---------------------------------------------------------- // ----------------------------------------------------------
@@ -97,10 +99,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",

View File

@@ -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();
} }