diff --git a/.gitignore b/.gitignore index a85e4f7..fdaccd7 100644 --- a/.gitignore +++ b/.gitignore @@ -149,3 +149,4 @@ tags ### Java *.class +.jar \ No newline at end of file diff --git a/DorfJavaTik.jar b/DorfJavaTik.jar new file mode 100644 index 0000000..285f4cb Binary files /dev/null and b/DorfJavaTik.jar differ diff --git a/DorfJavaTik_Juliette_Loris.jar b/DorfJavaTik_Juliette_Loris.jar new file mode 100644 index 0000000..9dc6220 Binary files /dev/null and b/DorfJavaTik_Juliette_Loris.jar differ diff --git a/MANIFEST.MF b/MANIFEST.MF new file mode 100644 index 0000000..7d5e400 --- /dev/null +++ b/MANIFEST.MF @@ -0,0 +1 @@ +Main-Class: com.charpentierbalocchi.dorfjavatik.view.FenetreDemarrage diff --git a/ScriptCompilation.ps1 b/ScriptCompilation.ps1 index 641b13a..aa1352f 100644 --- a/ScriptCompilation.ps1 +++ b/ScriptCompilation.ps1 @@ -3,6 +3,8 @@ # Définir le chemin de base du projet $projectPath = "C:\Users\Loris\OneDrive - UPEC\Documents\DEV\SAE_DEV_JAVA\src" $outputDir = "C:\Users\Loris\OneDrive - UPEC\Documents\DEV\SAE_DEV_JAVA\bin" # Dossier pour les fichiers .class +$resourcesPath = "C:\Users\Loris\OneDrive - UPEC\Documents\DEV\SAE_DEV_JAVA\src\com\charpentierbalocchi\dorfjavatik\resources\" +$resourcesOutputDir = "C:\Users\Loris\OneDrive - UPEC\Documents\DEV\SAE_DEV_JAVA\bin\com\charpentierbalocchi\dorfjavatik\resources\" # Dossier pour les ressources # Créer le dossier de sortie s'il n'existe pas if (-not (Test-Path $outputDir)) { @@ -10,10 +12,18 @@ if (-not (Test-Path $outputDir)) { } # Naviguer au répertoire racine du projet -cd $projectPath +Set-Location $projectPath -# Compiler tous les fichiers Java en spécifiant le dossier de sortie pour les fichiers .class -javac -d $outputDir (Get-ChildItem -Path $projectPath -Recurse -Filter *.java).FullName +# Compiler tous les fichiers Java en spécifiant le dossier de sortie pour les fichiers .class et en utilisant UTF-8 pour l'encodage +javac -d $outputDir -encoding UTF-8 (Get-ChildItem -Path $projectPath -Recurse -Filter *.java).FullName + +# Copier les ressources dans le répertoire de sortie +if (-not (Test-Path $resourcesOutputDir)) { + New-Item -Path $resourcesOutputDir -ItemType Directory +} +Copy-Item -Path $resourcesPath* -Destination $resourcesOutputDir -Recurse -Force # Afficher un message de fin -Write-Host "Compilation terminée avec succès. Les fichiers .class sont dans le dossier '$outputDir'." +Write-Host "Compilation terminée avec succès. Les fichiers .class et les ressources sont dans le dossier '$outputDir'." + +cd .. diff --git a/ScriptCompilationJar.ps1 b/ScriptCompilationJar.ps1 new file mode 100644 index 0000000..c5760be --- /dev/null +++ b/ScriptCompilationJar.ps1 @@ -0,0 +1,37 @@ +# Script de Compilation pour PowerShell + +# Définir le chemin de base du projet +$projectPath = "C:\Users\Loris\OneDrive - UPEC\Documents\DEV\SAE_DEV_JAVA\src" +$outputDir = "C:\Users\Loris\OneDrive - UPEC\Documents\DEV\SAE_DEV_JAVA\bin" # Dossier pour les fichiers .class +$resourcesPath = "C:\Users\Loris\OneDrive - UPEC\Documents\DEV\SAE_DEV_JAVA\src\com\charpentierbalocchi\dorfjavatik\resources\" +$resourcesOutputDir = "C:\Users\Loris\OneDrive - UPEC\Documents\DEV\SAE_DEV_JAVA\bin\com\charpentierbalocchi\dorfjavatik\resources\" # Dossier pour les ressources +$manifestPath = "C:\Users\Loris\OneDrive - UPEC\Documents\DEV\SAE_DEV_JAVA\MANIFEST.MF" +$jarFile = "C:\Users\Loris\OneDrive - UPEC\Documents\DEV\SAE_DEV_JAVA\DorfJavaTik.jar" +$jdkBinPath = "C:\Program Files\Java\jdk-17\bin" # Remplacer par le chemin correct vers le dossier bin du JDK + +# Créer le dossier de sortie s'il n'existe pas +if (-not (Test-Path $outputDir)) { + New-Item -Path $outputDir -ItemType Directory +} + +# Naviguer au répertoire racine du projet +Set-Location $projectPath + +# Compiler tous les fichiers Java en spécifiant le dossier de sortie pour les fichiers .class et en utilisant UTF-8 pour l'encodage +javac -d $outputDir -encoding UTF-8 (Get-ChildItem -Path $projectPath -Recurse -Filter *.java).FullName + +# Copier les ressources dans le répertoire de sortie +if (-not (Test-Path $resourcesOutputDir)) { + New-Item -Path $resourcesOutputDir -ItemType Directory +} +Copy-Item -Path $resourcesPath* -Destination $resourcesOutputDir -Recurse -Force + +# Créer le fichier JAR exécutable +Set-Location $outputDir +& "$jdkBinPath\jar.exe" cfm $jarFile $manifestPath -C $outputDir . + +# Afficher un message de fin +Write-Host "Compilation terminée avec succès. Les fichiers .class et les ressources sont dans le dossier '$outputDir'." +Write-Host "Le fichier JAR exécutable a été créé : '$jarFile'." + +cd .. diff --git a/bin/com/charpentierbalocchi/dorfjavatik/resources/image.gif b/bin/com/charpentierbalocchi/dorfjavatik/resources/image.gif new file mode 100644 index 0000000..d7084e6 Binary files /dev/null and b/bin/com/charpentierbalocchi/dorfjavatik/resources/image.gif differ diff --git a/src/com/charpentierbalocchi/dorfjavatik/controller/ControleurJeu.java b/src/com/charpentierbalocchi/dorfjavatik/controller/ControleurJeu.java index 5f84b19..0d92e9d 100644 --- a/src/com/charpentierbalocchi/dorfjavatik/controller/ControleurJeu.java +++ b/src/com/charpentierbalocchi/dorfjavatik/controller/ControleurJeu.java @@ -1,65 +1,59 @@ package com.charpentierbalocchi.dorfjavatik.controller; -import com.charpentierbalocchi.dorfjavatik.view.FenetreJeu; import com.charpentierbalocchi.dorfjavatik.model.Plateau; import com.charpentierbalocchi.dorfjavatik.model.Tuile; import com.charpentierbalocchi.dorfjavatik.util.GenerateurTuile; +import com.charpentierbalocchi.dorfjavatik.view.FenetreJeu; public class ControleurJeu { private FenetreJeu fenetreJeu; private Plateau plateau; private GenerateurTuile generateurTuile; - private int score; - public ControleurJeu(FenetreJeu fenetreJeu) { + public ControleurJeu(FenetreJeu fenetreJeu, int taillePlateau) { this.fenetreJeu = fenetreJeu; - this.plateau = new Plateau(); // Assurez-vous que Plateau a une implémentation appropriée. - this.generateurTuile = new GenerateurTuile(); // Génère des tuiles avec des biomes aléatoires. - this.score = 0; - initGame(); + this.plateau = new Plateau(taillePlateau); // Initialisation du plateau de jeu avec la taille spécifiée + this.generateurTuile = new GenerateurTuile(); // Générateur de tuiles aléatoires } public void setFenetreJeu(FenetreJeu fenetreJeu) { this.fenetreJeu = fenetreJeu; } - private void initGame() { - // Initialiser le jeu, par exemple, placer la première tuile aléatoire ou - // configurer le plateau. - // Affichez une tuile initiale sur l'interface utilisateur si nécessaire. - Tuile tuileInitiale = generateurTuile.genererTuileAleatoire(); - fenetreJeu.setTuileCourante(tuileInitiale); + public void demarrerJeu() { + plateau.reset(); + fenetreJeu.setScore(0); + fenetreJeu.resetBoard(); + genererNouvelleTuile(); } - // Gérer le placement d'une tuile sur le plateau public void handleTilePlacement(int x, int y) { Tuile tuileCourante = fenetreJeu.getTuileCourante(); - if (plateau.placeTile(tuileCourante, x, y)) { // Vérifie si la tuile peut être placée à la position x, y - fenetreJeu.updateBoard(x, y, tuileCourante); // Mettre à jour la vue avec la nouvelle tuile placée - updateScore(x, y, tuileCourante); // Mettre à jour le score après le placement - if (!plateau.estComplet()) { - // Générer et afficher une nouvelle tuile aléatoire - Tuile nouvelleTuile = generateurTuile.genererTuileAleatoire(); - fenetreJeu.setTuileCourante(nouvelleTuile); + if (tuileCourante != null && plateau.placerTuile(tuileCourante, x, y)) { + int score = plateau.calculerScore(x, y, tuileCourante); + fenetreJeu.setScore(plateau.getScore()); + fenetreJeu.updateBoard(x, y, tuileCourante); + if (plateauEstComplet()) { + fenetreJeu.afficherMessage("Partie terminée ! Votre score final est : " + plateau.getScore()); } else { - // Le plateau est complet, fin du jeu - fenetreJeu.afficherMessage("Le jeu est terminé. Score final: " + score); + genererNouvelleTuile(); } - } else { - fenetreJeu.afficherMessage("Placement invalide. Veuillez choisir une autre case."); } } - private void updateScore(int x, int y, Tuile tuile) { - // Calculez le score basé sur les règles du jeu - int points = plateau.calculerScore(x, y, tuile); - score += points; - fenetreJeu.setScore(score); + public void genererNouvelleTuile() { + Tuile nouvelleTuile = generateurTuile.genererTuileAleatoire(); + fenetreJeu.setTuileCourante(nouvelleTuile); } - // Méthode pour démarrer le jeu (peut être appelée depuis une interface - // utilisateur) - public void startGame() { - initGame(); + private boolean plateauEstComplet() { + for (int i = 0; i < plateau.getTaille(); i++) { + for (int j = 0; j < plateau.getTaille(); j++) { + if (plateau.getCase(i, j).estVide()) { + return false; + } + } + } + return true; } } diff --git a/src/com/charpentierbalocchi/dorfjavatik/main/DorfJavaTik.java b/src/com/charpentierbalocchi/dorfjavatik/main/DorfJavaTik.java index 315d9ff..0d8da9b 100644 --- a/src/com/charpentierbalocchi/dorfjavatik/main/DorfJavaTik.java +++ b/src/com/charpentierbalocchi/dorfjavatik/main/DorfJavaTik.java @@ -1,20 +1,13 @@ package com.charpentierbalocchi.dorfjavatik.main; -import com.charpentierbalocchi.dorfjavatik.view.FenetreJeu; -import com.charpentierbalocchi.dorfjavatik.controller.ControleurJeu; +import com.charpentierbalocchi.dorfjavatik.view.FenetreDemarrage; public class DorfJavaTik { public static void main(String[] args) { + // Lancer la fenêtre de démarrage javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { - // Créez d'abord une instance de FenetreJeu avec une instance de ControleurJeu - FenetreJeu fenetreJeu = new FenetreJeu(null); - // Créez ensuite une instance de ControleurJeu en passant FenetreJeu - ControleurJeu controleurJeu = new ControleurJeu(fenetreJeu); - // Assurez-vous de lier correctement les deux - fenetreJeu.setControleurJeu(controleurJeu); - // Rendre la fenêtre visible - fenetreJeu.setVisible(true); + new FenetreDemarrage(); } }); } diff --git a/src/com/charpentierbalocchi/dorfjavatik/model/Plateau.java b/src/com/charpentierbalocchi/dorfjavatik/model/Plateau.java index e90a667..b154040 100644 --- a/src/com/charpentierbalocchi/dorfjavatik/model/Plateau.java +++ b/src/com/charpentierbalocchi/dorfjavatik/model/Plateau.java @@ -1,60 +1,67 @@ package com.charpentierbalocchi.dorfjavatik.model; public class Plateau { - private final int TAILLE = 5; // Taille standard du plateau + private int taille; private Case[][] cases; // Grille de cases + private int score; - public Plateau() { - this.cases = new Case[TAILLE][TAILLE]; - for (int i = 0; i < TAILLE; i++) { - for (int j = 0; j < TAILLE; j++) { - this.cases[i][j] = new Case(); // Initialisation de chaque case du plateau + public Plateau(int taille) { + this.taille = taille; + cases = new Case[taille][taille]; + for (int i = 0; i < taille; i++) { + for (int j = 0; j < taille; j++) { + cases[i][j] = new Case(); // Initialisation de chaque case du plateau } } + score = 0; } - // Méthode pour placer une tuile sur le plateau à la position (x, y) - public boolean placeTile(Tuile tuile, int x, int y) { - if (x < 0 || x >= TAILLE || y < 0 || y >= TAILLE) { - return false; // Vérifie que les coordonnées sont dans les limites du plateau + public void reset() { + for (int i = 0; i < taille; i++) { + for (int j = 0; j < taille; j++) { + cases[i][j] = new Case(); + } } - if (!cases[x][y].estVide()) { - return false; // Vérifie que la case est vide avant de placer la tuile - } - cases[x][y].setTuile(tuile); // Place la tuile sur le plateau - return true; + score = 0; + } + + public boolean placerTuile(Tuile tuile, int x, int y) { + if (cases[x][y].estVide()) { + cases[x][y].setTuile(tuile); + score += calculerScore(x, y, tuile); + return true; + } + return false; } - // Méthode pour calculer le score après placement d'une tuile public int calculerScore(int x, int y, Tuile tuile) { int score = 0; - // Vérifier les tuiles adjacentes pour les correspondances de biomes if (x > 0 && cases[x - 1][y].getTuile() != null && cases[x - 1][y].getTuile().getSud() == tuile.getNord()) { score++; } - if (x < TAILLE - 1 && cases[x + 1][y].getTuile() != null + if (x < taille - 1 && cases[x + 1][y].getTuile() != null && cases[x + 1][y].getTuile().getNord() == tuile.getSud()) { score++; } if (y > 0 && cases[x][y - 1].getTuile() != null && cases[x][y - 1].getTuile().getEst() == tuile.getOuest()) { score++; } - if (y < TAILLE - 1 && cases[x][y + 1].getTuile() != null + if (y < taille - 1 && cases[x][y + 1].getTuile() != null && cases[x][y + 1].getTuile().getOuest() == tuile.getEst()) { score++; } return score; } - // Vérifie si le plateau est complètement rempli - public boolean estComplet() { - for (int i = 0; i < TAILLE; i++) { - for (int j = 0; j < TAILLE; j++) { - if (cases[i][j].estVide()) { - return false; - } - } - } - return true; + public int getScore() { + return score; + } + + public Case getCase(int x, int y) { + return cases[x][y]; + } + + public int getTaille() { + return taille; } } diff --git a/src/com/charpentierbalocchi/dorfjavatik/model/Tuile.java b/src/com/charpentierbalocchi/dorfjavatik/model/Tuile.java index d778731..0d87e16 100644 --- a/src/com/charpentierbalocchi/dorfjavatik/model/Tuile.java +++ b/src/com/charpentierbalocchi/dorfjavatik/model/Tuile.java @@ -1,29 +1,17 @@ package com.charpentierbalocchi.dorfjavatik.model; +import java.awt.Color; + public class Tuile { - // Enum pour les biomes public enum Biome { - RIVIERE("Bleu"), FORET("Vert"), CHAMP("Jaune"), VILLAGE("Rouge"), MONTAGNE("Gris"); - - private final String couleur; - - Biome(String couleur) { - this.couleur = couleur; - } - - @Override - public String toString() { - return this.couleur; - } + RIVIERE, FORET, CHAMP, VILLAGE, MONTAGNE } - // Zones de la tuile avec un biome pour chaque private Biome nord; private Biome sud; private Biome est; private Biome ouest; - // Constructeur de Tuile avec les biomes pour chaque zone public Tuile(Biome nord, Biome sud, Biome est, Biome ouest) { this.nord = nord; this.sud = sud; @@ -31,7 +19,6 @@ public class Tuile { this.ouest = ouest; } - // Getters pour chaque zone public Biome getNord() { return nord; } @@ -48,9 +35,25 @@ public class Tuile { return ouest; } - // Représentation de la Tuile sous forme de chaîne de caractères + public static Color getColorForBiome(Biome biome) { + switch (biome) { + case RIVIERE: + return Color.BLUE; + case FORET: + return Color.GREEN; + case CHAMP: + return Color.YELLOW; + case VILLAGE: + return Color.RED; + case MONTAGNE: + return Color.GRAY; + default: + return Color.BLACK; + } + } + @Override public String toString() { - return String.format("[N: %s, S: %s, E: %s, O: %s]", nord, sud, est, ouest); + return "[N: " + nord + ", S: " + sud + ", E: " + est + ", O: " + ouest + "]"; } } diff --git a/src/com/charpentierbalocchi/dorfjavatik/resources/image.gif b/src/com/charpentierbalocchi/dorfjavatik/resources/image.gif new file mode 100644 index 0000000..d7084e6 Binary files /dev/null and b/src/com/charpentierbalocchi/dorfjavatik/resources/image.gif differ diff --git a/src/com/charpentierbalocchi/dorfjavatik/view/FenetreDemarrage.java b/src/com/charpentierbalocchi/dorfjavatik/view/FenetreDemarrage.java new file mode 100644 index 0000000..4118908 --- /dev/null +++ b/src/com/charpentierbalocchi/dorfjavatik/view/FenetreDemarrage.java @@ -0,0 +1,96 @@ +package com.charpentierbalocchi.dorfjavatik.view; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class FenetreDemarrage extends JFrame { + + public FenetreDemarrage() { + super("Démarrage du jeu"); + initUI(); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setSize(400, 200); + setLocationRelativeTo(null); // Centre la fenêtre sur l'écran + setVisible(true); + } + + private void initUI() { + // Création des composants + JPanel panelPrincipal = new JPanel(new BorderLayout()); + JLabel label = new JLabel("Entrez la taille de la grille (1-15):"); + JTextField textField = new JTextField(); + textField.setText("5"); // Définir la valeur par défaut à 5 + JButton button = new JButton("Démarrer la partie"); + + // Ajout des composants au panneau principal + panelPrincipal.add(label, BorderLayout.NORTH); + panelPrincipal.add(textField, BorderLayout.CENTER); + panelPrincipal.add(button, BorderLayout.SOUTH); + + // Ajout du panneau principal à la fenêtre + add(panelPrincipal); + + // Action listener pour le bouton + button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + int taille = Integer.parseInt(textField.getText()); + if (taille == 1) { + // Charger le GIF à partir du chemin de fichier + String gifPath = "bin/com/charpentierbalocchi/dorfjavatik/resources/image.gif"; // Remplacer par + // le chemin + // correct + ImageIcon gifIcon = new ImageIcon(gifPath); + + // Vérifier si le GIF est chargé correctement + if (gifIcon.getIconWidth() == -1) { + JOptionPane.showMessageDialog(null, "Le fichier GIF n'a pas pu être chargé.", "Erreur", + JOptionPane.ERROR_MESSAGE); + } else { + // Créer un JLabel avec le GIF + JLabel gifLabel = new JLabel(gifIcon); + JPanel panelMessage = new JPanel(new BorderLayout()); + panelMessage.add(new JLabel("UNE TUILE!"), BorderLayout.SOUTH); + panelMessage.add(gifLabel, BorderLayout.CENTER); + + // Afficher le message avec le GIF dans un JOptionPane + JOptionPane.showMessageDialog(null, panelMessage, "UNE TUILE !", + JOptionPane.WARNING_MESSAGE); + } + } else if (taille >= 2 && taille <= 4) { + int response = JOptionPane.showConfirmDialog(null, + "Êtes-vous sûr de vouloir continuer avec cette taille de grille ?", + "Confirmation", + JOptionPane.YES_NO_OPTION); + if (response == JOptionPane.YES_OPTION) { + new FenetreJeu(taille); + dispose(); + } else { + textField.setText(""); // Réinitialiser le champ de texte pour permettre une nouvelle saisie + } + } else if (taille > 4 && taille <= 15) { + new FenetreJeu(taille); + dispose(); + } else { + JOptionPane.showMessageDialog(null, "Veuillez entrer une taille de grille entre 1 et 15.", + "Erreur", JOptionPane.ERROR_MESSAGE); + } + } catch (NumberFormatException ex) { + JOptionPane.showMessageDialog(null, "Veuillez entrer un nombre valide.", "Erreur", + JOptionPane.ERROR_MESSAGE); + } + } + }); + } + + // Méthode principale pour démarrer l'application + public static void main(String[] args) { + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + new FenetreDemarrage(); + } + }); + } +} diff --git a/src/com/charpentierbalocchi/dorfjavatik/view/FenetreJeu.java b/src/com/charpentierbalocchi/dorfjavatik/view/FenetreJeu.java index ae02684..13e18ad 100644 --- a/src/com/charpentierbalocchi/dorfjavatik/view/FenetreJeu.java +++ b/src/com/charpentierbalocchi/dorfjavatik/view/FenetreJeu.java @@ -7,36 +7,40 @@ import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; public class FenetreJeu extends JFrame { - private static final int TAILLE_PLATEAU = 5; // Taille du plateau 5x5 + private int taillePlateau; // Taille du plateau private TileButton[][] boutons; // Boutons représentant les cases du plateau private JLabel labelScore; // Label pour afficher le score private Tuile tuileCourante; // La tuile actuellement proposée private ControleurJeu controleurJeu; // Instance du contrôleur de jeu + private JPanel panelPlateau; // Panneau pour le plateau de jeu + private JPanel panelTuileCourante; // Panneau pour la tuile courante - public FenetreJeu(ControleurJeu controleurJeu) { + public FenetreJeu(int taillePlateau) { super("DorfJavaTik"); // Titre de la fenêtre - this.controleurJeu = controleurJeu; + this.taillePlateau = taillePlateau; initUI(); + this.controleurJeu = new ControleurJeu(this, taillePlateau); // Initialiser le contrôleur après la configuration + // de l'interface + controleurJeu.demarrerJeu(); // Démarrer le jeu après l'initialisation setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Ferme l'application à la fermeture de la fenêtre + setSize(1300, 1000); // Fixe la taille de la fenêtre à 1300 x 1000 setLocationRelativeTo(null); // Centre la fenêtre sur l'écran - pack(); // Ajuste la taille de la fenêtre en fonction des composants - } - - public void setControleurJeu(ControleurJeu controleurJeu) { - this.controleurJeu = controleurJeu; + setVisible(true); // Rendre la fenêtre visible } private void initUI() { - // Panel principal + // Panel principal avec BorderLayout JPanel panelPrincipal = new JPanel(new BorderLayout()); - // Panel pour le plateau de jeu - JPanel plateau = new JPanel(new GridLayout(TAILLE_PLATEAU, TAILLE_PLATEAU)); - boutons = new TileButton[TAILLE_PLATEAU][TAILLE_PLATEAU]; - for (int i = 0; i < TAILLE_PLATEAU; i++) { - for (int j = 0; j < TAILLE_PLATEAU; j++) { + // Panel pour le plateau de jeu sur la droite + panelPlateau = new JPanel(new GridLayout(taillePlateau, taillePlateau)); + boutons = new TileButton[taillePlateau][taillePlateau]; + for (int i = 0; i < taillePlateau; i++) { + for (int j = 0; j < taillePlateau; j++) { TileButton bouton = new TileButton(); final int x = i; final int y = j; @@ -47,16 +51,98 @@ public class FenetreJeu extends JFrame { } }); boutons[i][j] = bouton; - plateau.add(bouton); + panelPlateau.add(bouton); } } - // Label pour le score + // Panel pour afficher la tuile courante et le score sur la gauche, centré + // verticalement + JPanel panelGauche = new JPanel(); + panelGauche.setLayout(new BoxLayout(panelGauche, BoxLayout.Y_AXIS)); + panelGauche.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); + labelScore = new JLabel("Score: 0"); - panelPrincipal.add(labelScore, BorderLayout.NORTH); - panelPrincipal.add(plateau, BorderLayout.CENTER); + labelScore.setAlignmentX(Component.CENTER_ALIGNMENT); + labelScore.setFont(new Font("Serif", Font.BOLD, 24)); // Définir la police plus grande pour le score + + panelTuileCourante = new JPanel() { + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + if (tuileCourante != null) { + int size = Math.min(getWidth(), getHeight()); + dessinerTuile(g, tuileCourante, size, size); + } + } + }; + panelTuileCourante.setPreferredSize(new Dimension(150, 150)); + panelTuileCourante.setMaximumSize(new Dimension(150, 150)); + panelTuileCourante.setAlignmentX(Component.CENTER_ALIGNMENT); + + JButton boutonRecommencer = new JButton("Reset"); + boutonRecommencer.setAlignmentX(Component.CENTER_ALIGNMENT); + boutonRecommencer.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + controleurJeu.demarrerJeu(); + } + }); + + panelGauche.add(Box.createVerticalGlue()); + panelGauche.add(labelScore); + panelGauche.add(Box.createVerticalStrut(20)); // Espace entre les composants + panelGauche.add(panelTuileCourante); + panelGauche.add(Box.createVerticalStrut(20)); // Espace entre les composants + panelGauche.add(boutonRecommencer); + panelGauche.add(Box.createVerticalGlue()); + + panelPrincipal.add(panelGauche, BorderLayout.WEST); + panelPrincipal.add(panelPlateau, BorderLayout.CENTER); add(panelPrincipal); + + // Ajouter un écouteur pour garantir que le panneau du plateau reste un carré + addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + Dimension size = panelPlateau.getSize(); + int side = Math.min(size.width, size.height); + panelPlateau.setPreferredSize(new Dimension(side, side)); + panelPlateau.revalidate(); + } + }); + } + + // Méthode pour dessiner les biomes sur un bouton + private void dessinerTuile(Graphics g, Tuile tuile, int width, int height) { + Graphics2D g2d = (Graphics2D) g.create(); + int halfWidth = width / 2; + int halfHeight = height / 2; + + // Dessiner le triangle nord + g2d.setColor(Tuile.getColorForBiome(tuile.getNord())); + int[] xPointsNord = { 0, halfWidth, width }; + int[] yPointsNord = { 0, halfHeight, 0 }; + g2d.fillPolygon(xPointsNord, yPointsNord, 3); + + // Dessiner le triangle sud + g2d.setColor(Tuile.getColorForBiome(tuile.getSud())); + int[] xPointsSud = { 0, halfWidth, width }; + int[] yPointsSud = { height, halfHeight, height }; + g2d.fillPolygon(xPointsSud, yPointsSud, 3); + + // Dessiner le triangle est + g2d.setColor(Tuile.getColorForBiome(tuile.getEst())); + int[] xPointsEst = { width, halfWidth, width }; + int[] yPointsEst = { 0, halfHeight, height }; + g2d.fillPolygon(xPointsEst, yPointsEst, 3); + + // Dessiner le triangle ouest + g2d.setColor(Tuile.getColorForBiome(tuile.getOuest())); + int[] xPointsOuest = { 0, halfWidth, 0 }; + int[] yPointsOuest = { 0, halfHeight, height }; + g2d.fillPolygon(xPointsOuest, yPointsOuest, 3); + + g2d.dispose(); } // Méthode pour mettre à jour le plateau après placement d'une tuile @@ -67,6 +153,16 @@ public class FenetreJeu extends JFrame { // position } + public void resetBoard() { + for (int i = 0; i < taillePlateau; i++) { + for (int j = 0; j < taillePlateau; j++) { + boutons[i][j].setTuile(null); // Réinitialiser la tuile sur le bouton + boutons[i][j].setEnabled(true); // Réactiver le bouton + } + } + repaint(); + } + public void setScore(int score) { labelScore.setText("Score: " + score); } @@ -77,11 +173,16 @@ public class FenetreJeu extends JFrame { public void setTuileCourante(Tuile tuile) { this.tuileCourante = tuile; - // Affichez la tuile courante dans l'interface utilisateur si nécessaire + panelTuileCourante.repaint(); } public void afficherMessage(String message) { - JOptionPane.showMessageDialog(this, message); + int result = JOptionPane.showOptionDialog(this, message, "Fin de la partie", + JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, + null, new Object[] { "Quitter" }, "Quitter"); + if (result == JOptionPane.OK_OPTION) { + System.exit(0); + } } // Classe interne pour représenter un bouton avec une tuile @@ -101,52 +202,9 @@ public class FenetreJeu extends JFrame { protected void paintComponent(Graphics g) { super.paintComponent(g); if (tuile != null) { - Graphics2D g2d = (Graphics2D) g.create(); int width = getWidth(); int height = getHeight(); - - // Dessiner le triangle nord - g2d.setColor(getColorForBiome(tuile.getNord())); - int[] xPointsNord = { 0, width / 2, width }; - int[] yPointsNord = { 0, height / 2, 0 }; - g2d.fillPolygon(xPointsNord, yPointsNord, 3); - - // Dessiner le triangle sud - g2d.setColor(getColorForBiome(tuile.getSud())); - int[] xPointsSud = { 0, width / 2, width }; - int[] yPointsSud = { height, height / 2, height }; - g2d.fillPolygon(xPointsSud, yPointsSud, 3); - - // Dessiner le triangle est - g2d.setColor(getColorForBiome(tuile.getEst())); - int[] xPointsEst = { width, width / 2, width }; - int[] yPointsEst = { 0, height / 2, height }; - g2d.fillPolygon(xPointsEst, yPointsEst, 3); - - // Dessiner le triangle ouest - g2d.setColor(getColorForBiome(tuile.getOuest())); - int[] xPointsOuest = { 0, width / 2, 0 }; - int[] yPointsOuest = { 0, height / 2, height }; - g2d.fillPolygon(xPointsOuest, yPointsOuest, 3); - - g2d.dispose(); - } - } - - private Color getColorForBiome(Tuile.Biome biome) { - switch (biome) { - case RIVIERE: - return Color.BLUE; - case FORET: - return Color.GREEN; - case CHAMP: - return Color.YELLOW; - case VILLAGE: - return Color.RED; - case MONTAGNE: - return Color.GRAY; - default: - return Color.BLACK; + dessinerTuile(g, tuile, width, height); } } } @@ -155,11 +213,7 @@ public class FenetreJeu extends JFrame { public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { - ControleurJeu controleurJeu = new ControleurJeu(null); // Vous devez initialiser le contrôleur ici avec - // une instance de FenetreJeu - FenetreJeu fenetreJeu = new FenetreJeu(controleurJeu); - controleurJeu.setFenetreJeu(fenetreJeu); - fenetreJeu.setVisible(true); + new FenetreDemarrage(); } }); } diff --git a/tests/Debut.java b/tests/Debut.java new file mode 100644 index 0000000..e5c98b6 --- /dev/null +++ b/tests/Debut.java @@ -0,0 +1,35 @@ +package tests; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; + +public class Debut { + public static void main(String[] args) { + + JFrame fenetre = new JFrame(); + fenetre.setSize(500, 300); + fenetre.setLocation(0, 0); + fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + JLabel etiquette = new JLabel(); + etiquette.setHorizontalAlignment(JLabel.RIGHT); + etiquette.setVerticalAlignment(JLabel.BOTTOM); + fenetre.add(etiquette, BorderLayout.CENTER); + + JButton Nouveau = new JButton("Nouvelle Partie"); + etiquette.setHorizontalAlignment(JLabel.RIGHT); + etiquette.setVerticalAlignment(JLabel.BOTTOM); + fenetre.add(etiquette, BorderLayout.SOUTH); + + fenetre.setVisible(true); + + /* + * public void actionPerformed(ActionEvent e){ + * String action=e.getActionCommand(); + * if(action.equals("Nouvelle Partie")){ + * // Do something + * } + */ + } +} \ No newline at end of file