Maj BoardLoader + makefile
This commit is contained in:
17
Makefile
17
Makefile
@@ -2,6 +2,10 @@
|
||||
SRC_DIR = fr
|
||||
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 ===
|
||||
SOURCES := $(shell find $(SRC_DIR) -name "*.java")
|
||||
|
||||
@@ -19,11 +23,20 @@ JAVAFLAGS = -cp $(BIN_DIR)
|
||||
all: build
|
||||
|
||||
# === Compilation ===
|
||||
build:
|
||||
build: compile resources
|
||||
@echo "✔ Compilation terminée."
|
||||
|
||||
compile:
|
||||
@echo "===> Compilation du projet Avalam..."
|
||||
@mkdir -p $(BIN_DIR)
|
||||
@$(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 ===
|
||||
run:
|
||||
|
||||
BIN
bin/fr/iut_fbleau/Avalam/AvalamBoard.class
Normal file
BIN
bin/fr/iut_fbleau/Avalam/AvalamBoard.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/Avalam/AvalamPly.class
Normal file
BIN
bin/fr/iut_fbleau/Avalam/AvalamPly.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/Avalam/AvalamWindow$1.class
Normal file
BIN
bin/fr/iut_fbleau/Avalam/AvalamWindow$1.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/Avalam/AvalamWindow.class
Normal file
BIN
bin/fr/iut_fbleau/Avalam/AvalamWindow.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/Avalam/Color.class
Normal file
BIN
bin/fr/iut_fbleau/Avalam/Color.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/Avalam/Main.class
Normal file
BIN
bin/fr/iut_fbleau/Avalam/Main.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/Avalam/Tower.class
Normal file
BIN
bin/fr/iut_fbleau/Avalam/Tower.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/Avalam/logic/BoardLoader.class
Normal file
BIN
bin/fr/iut_fbleau/Avalam/logic/BoardLoader.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/Avalam/ui/BoardView.class
Normal file
BIN
bin/fr/iut_fbleau/Avalam/ui/BoardView.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/Avalam/ui/HighlightLayer.class
Normal file
BIN
bin/fr/iut_fbleau/Avalam/ui/HighlightLayer.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/Avalam/ui/InteractionController.class
Normal file
BIN
bin/fr/iut_fbleau/Avalam/ui/InteractionController.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/Avalam/ui/PieceButton$1.class
Normal file
BIN
bin/fr/iut_fbleau/Avalam/ui/PieceButton$1.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/Avalam/ui/PieceButton.class
Normal file
BIN
bin/fr/iut_fbleau/Avalam/ui/PieceButton.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/Avalam/ui/PieceLayer.class
Normal file
BIN
bin/fr/iut_fbleau/Avalam/ui/PieceLayer.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/Avalam/ui/ScoreView.class
Normal file
BIN
bin/fr/iut_fbleau/Avalam/ui/ScoreView.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/Avalam/ui/TurnView.class
Normal file
BIN
bin/fr/iut_fbleau/Avalam/ui/TurnView.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/GameAPI/AbstractBoard.class
Normal file
BIN
bin/fr/iut_fbleau/GameAPI/AbstractBoard.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/GameAPI/AbstractGame.class
Normal file
BIN
bin/fr/iut_fbleau/GameAPI/AbstractGame.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/GameAPI/AbstractGamePlayer.class
Normal file
BIN
bin/fr/iut_fbleau/GameAPI/AbstractGamePlayer.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/GameAPI/AbstractPly.class
Normal file
BIN
bin/fr/iut_fbleau/GameAPI/AbstractPly.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/GameAPI/IBoard.class
Normal file
BIN
bin/fr/iut_fbleau/GameAPI/IBoard.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/GameAPI/Player.class
Normal file
BIN
bin/fr/iut_fbleau/GameAPI/Player.class
Normal file
Binary file not shown.
BIN
bin/fr/iut_fbleau/GameAPI/Result.class
Normal file
BIN
bin/fr/iut_fbleau/GameAPI/Result.class
Normal file
Binary file not shown.
9
bin/fr/iut_fbleau/Res/Plateau.txt
Normal file
9
bin/fr/iut_fbleau/Res/Plateau.txt
Normal 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
|
||||
@@ -40,6 +40,8 @@ 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
|
||||
|
||||
// ----------------------------------------------------------
|
||||
@@ -97,10 +99,10 @@ public class AvalamWindow extends JFrame {
|
||||
String msg;
|
||||
|
||||
switch (res) {
|
||||
case WIN -> msg = "Le joueur jaune a gagné !";
|
||||
case LOSS -> msg = "Le joueur rouge a gagné !";
|
||||
case DRAW -> msg = "Égalité !";
|
||||
default -> msg = "Fin de partie.";
|
||||
case WIN : msg = "Le joueur jaune a gagné !";
|
||||
case LOSS : msg = "Le joueur rouge a gagné !";
|
||||
case DRAW : msg = "Égalité !";
|
||||
default : msg = "Fin de partie.";
|
||||
}
|
||||
|
||||
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.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 static Tower[][] loadFromFile(String file) {
|
||||
public static Tower[][] loadFromFile(String resourcePath) {
|
||||
|
||||
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;
|
||||
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++) {
|
||||
int v = Integer.parseInt(vals[col].trim());
|
||||
int value = Integer.parseInt(parts[col]);
|
||||
|
||||
switch (v) {
|
||||
case 1 -> grid[row][col] = new Tower(Color.YELLOW);
|
||||
case 2 -> grid[row][col] = new Tower(Color.RED);
|
||||
default -> grid[row][col] = null;
|
||||
switch (value) {
|
||||
case 1:
|
||||
grid[row][col] = new Tower(Color.YELLOW);
|
||||
break;
|
||||
case 2:
|
||||
grid[row][col] = new Tower(Color.RED);
|
||||
break;
|
||||
default:
|
||||
grid[row][col] = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
row++;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user