From 7bb6b79d532820d2077088cc2afe5e466a9f38d2 Mon Sep 17 00:00:00 2001 From: dick Date: Thu, 20 Nov 2025 13:25:09 -0500 Subject: [PATCH] Plateau graphique v1 --- Makefile | 41 ++++ fr/iut_fbleau/Avalam/AvalamPanel.java | 184 ++++++++++++++++++ fr/iut_fbleau/Avalam/AvalamWindow.java | 30 +++ fr/iut_fbleau/Avalam/Color.java | 37 +++- fr/iut_fbleau/Avalam/Main.java | 17 ++ fr/iut_fbleau/AvalamTests/TestTower.class | Bin 0 -> 1577 bytes fr/iut_fbleau/GameAPI/AbstractBoard.class | Bin 0 -> 2065 bytes fr/iut_fbleau/GameAPI/AbstractGame.class | Bin 0 -> 2148 bytes .../GameAPI/AbstractGamePlayer.class | Bin 0 -> 431 bytes fr/iut_fbleau/GameAPI/AbstractPly.class | Bin 0 -> 417 bytes fr/iut_fbleau/GameAPI/IBoard.class | Bin 0 -> 636 bytes fr/iut_fbleau/GameAPI/Player.class | Bin 0 -> 998 bytes fr/iut_fbleau/GameAPI/Result.class | Bin 0 -> 1042 bytes fr/iut_fbleau/Res/Plateau.txt | 9 + 14 files changed, 313 insertions(+), 5 deletions(-) create mode 100644 Makefile create mode 100644 fr/iut_fbleau/Avalam/AvalamPanel.java create mode 100644 fr/iut_fbleau/Avalam/AvalamWindow.java create mode 100644 fr/iut_fbleau/Avalam/Main.java create mode 100644 fr/iut_fbleau/AvalamTests/TestTower.class create mode 100644 fr/iut_fbleau/GameAPI/AbstractBoard.class create mode 100644 fr/iut_fbleau/GameAPI/AbstractGame.class create mode 100644 fr/iut_fbleau/GameAPI/AbstractGamePlayer.class create mode 100644 fr/iut_fbleau/GameAPI/AbstractPly.class create mode 100644 fr/iut_fbleau/GameAPI/IBoard.class create mode 100644 fr/iut_fbleau/GameAPI/Player.class create mode 100644 fr/iut_fbleau/GameAPI/Result.class create mode 100644 fr/iut_fbleau/Res/Plateau.txt diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..eb07785 --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ +# Répertoires +SRC_DIR = . +BIN_DIR = bin + +# Trouve tous les fichiers .java +SOURCES := $(shell find $(SRC_DIR) -name "*.java") + +# Classe principale +MAIN = fr.iut_fbleau.Avalam.Main + +# Options javac +JC = javac +JCFLAGS = -d $(BIN_DIR) + +# Options java +JAVA = java +JAVAFLAGS = -cp $(BIN_DIR) + +# Règle par défaut +all: build + +# Compilation +build: + @echo "Compilation du projet..." + @mkdir -p $(BIN_DIR) + @$(JC) $(JCFLAGS) $(SOURCES) + @echo "✔ Compilation terminée !" + +# Exécution +run: + @echo "Lancement du jeu Avalam..." + @$(JAVA) $(JAVAFLAGS) $(MAIN) + +# Nettoyage des .class +clean: + @echo "Suppression des fichiers compilés..." + @rm -rf $(BIN_DIR) + @echo "✔ Nettoyage terminé !" + +# Recompile + run +re: clean all run diff --git a/fr/iut_fbleau/Avalam/AvalamPanel.java b/fr/iut_fbleau/Avalam/AvalamPanel.java new file mode 100644 index 0000000..17a9408 --- /dev/null +++ b/fr/iut_fbleau/Avalam/AvalamPanel.java @@ -0,0 +1,184 @@ +package fr.iut_fbleau.Avalam; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.io.*; + +/** + * La classe AvalamPanel gère l'affichage graphique du plateau Avalam. + * + * Elle a pour rôle : + * - de charger la configuration initiale du plateau depuis le fichier Plateau.txt + * - d'afficher les pions sous forme de boutons ronds cliquables + * - de gérer leur positionnement visuel sur une fenêtre Swing + * + * À ce stade, les clics ne modifient pas le modèle (aucune règle appliquée), + * ils servent seulement à confirmer que la sélection fonctionne. + * + * @version 1.0 + * @author --- + */ +public class AvalamPanel extends JPanel { + + /** Grille du plateau contenant des objets Tower ou null (case vide). */ + private Tower[][] grid = new Tower[9][9]; + + /** Taille visuelle d’un pion. */ + private final int pionTaille = 50; + + /** Distance entre deux pions. */ + private final int pas = 70; + + /** Décalage horizontal pour centrer le plateau. */ + private final int xBase = 60; + + /** Décalage vertical pour centrer le plateau. */ + private final int yBase = 60; + + /** + * Constructeur. + * Initialise le layout, charge le plateau et affiche les pions. + */ + public AvalamPanel() { + setLayout(null); + chargerPlateau(); + afficherPions(); + } + + /** + * Charge la grille du plateau depuis le fichier Plateau.txt (matrice du plateau). + * + * 0 → case vide + * 1 → pion du joueur 1 (couleur YELLOW) + * 2 → pion du joueur 2 (couleur RED) + */ + private void chargerPlateau() { + try { + File f = new File("fr/iut_fbleau/Res/Plateau.txt"); + BufferedReader br = new BufferedReader(new FileReader(f)); + + String line; + int row = 0; + + while ((line = br.readLine()) != null && row < 9) { + String[] parts = line.split(","); + for (int col = 0; col < 9; col++) { + int valeur = Integer.parseInt(parts[col]); + + if (valeur == 1) grid[row][col] = new Tower(Color.YELLOW); + else if (valeur == 2) grid[row][col] = new Tower(Color.RED); + else grid[row][col] = null; + } + row++; + } + + br.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Ajoute graphiquement les pions sur le plateau. + * Chaque pion est représenté par un bouton rond Swing. + */ + private void afficherPions() { + for (int i = 0; i < 9; i++) { + for (int j = 0; j < 9; j++) { + Tower t = grid[i][j]; + + if (t != null) { + + // Conversion couleur Avalam → couleur Swing + java.awt.Color swingColor = t.getColor().getSwingColor(); + + JButton pion = creerBoutonRond(swingColor); + + int x = xBase + j * pas; + int y = yBase + i * pas; + pion.setBounds(x, y, pionTaille, pionTaille); + + int finalI = i; + int finalJ = j; + + // !!!TEMPORAIRE!!! permet de voir quel endroit cliqué + pion.addActionListener(e -> + JOptionPane.showMessageDialog(null, + "Tu as cliqué sur (" + finalI + ", " + finalJ + ")") + ); + + add(pion); + } + } + } + } + + /** + * Crée un bouton rond représentant un pion. + * + * Un effet d'assombrissement est appliqué au survol pour un meilleur feedback visuel. + * + * @param couleurSwing la couleur Swing du pion + * @return un bouton circulaire + */ + private JButton creerBoutonRond(java.awt.Color couleurSwing) { + + JButton bouton = new JButton() { + + /** Indique si la souris survole le bouton. */ + private boolean hover = false; + + { + setBorderPainted(false); + setContentAreaFilled(false); + setFocusPainted(false); + setOpaque(false); + + // Gestion du survol + addMouseListener(new MouseAdapter() { + @Override + public void mouseEntered(MouseEvent e) { + hover = true; + repaint(); + } + + @Override + public void mouseExited(MouseEvent e) { + hover = false; + repaint(); + } + }); + } + + /** + * Dessine le pion sous forme de cercle. + */ + @Override + protected void paintComponent(Graphics g) { + Graphics2D g2 = (Graphics2D) g.create(); + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + + g2.setColor(hover ? couleurSwing.darker() : couleurSwing); + g2.fillOval(0, 0, getWidth(), getHeight()); + + g2.dispose(); + } + + /** + * Rend le clique précis au cercle (pas carré). + */ + @Override + public boolean contains(int x, int y) { + double dx = x - getWidth() / 2.0; + double dy = y - getHeight() / 2.0; + return dx * dx + dy * dy <= (getWidth() / 2.0) * (getWidth() / 2.0); + } + }; + + bouton.setPreferredSize(new Dimension(pionTaille, pionTaille)); + return bouton; + } +} diff --git a/fr/iut_fbleau/Avalam/AvalamWindow.java b/fr/iut_fbleau/Avalam/AvalamWindow.java new file mode 100644 index 0000000..7d7038a --- /dev/null +++ b/fr/iut_fbleau/Avalam/AvalamWindow.java @@ -0,0 +1,30 @@ +package fr.iut_fbleau.Avalam; + +import javax.swing.*; + +/** + * La classe AvalamWindow représente la fenêtre principale du jeu Avalam. + * + * Elle crée une fenêtre Swing, lui donne une taille, un titre, + * puis y ajoute un AvalamPanel qui contient l'affichage réel du plateau. + * + * @version 1.0 + */ +public class AvalamWindow extends JFrame { + + /** + * Constructeur : initialise la fenêtre du jeu. + */ + public AvalamWindow() { + super("Avalam - Plateau Graphique"); + + setSize(750, 750); + setLocationRelativeTo(null); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + // Ajout du panneau contenant le plateau + add(new AvalamPanel()); + + setVisible(true); + } +} diff --git a/fr/iut_fbleau/Avalam/Color.java b/fr/iut_fbleau/Avalam/Color.java index 5b91d92..cf75509 100644 --- a/fr/iut_fbleau/Avalam/Color.java +++ b/fr/iut_fbleau/Avalam/Color.java @@ -1,6 +1,33 @@ -package fr.iut_fbleau.Avalam ; +package fr.iut_fbleau.Avalam; -public enum Color{ - RED, - YELLOW -} \ No newline at end of file +/** + * L'énumération Color représente la couleur du sommet d'une tour Avalam. + * + * Chaque valeur contient directement sa couleur Swing associée, + * ce qui évite les conversions dans le code graphique. + * + * @version 2.0 + */ +public enum Color { + + RED(java.awt.Color.RED), + YELLOW(java.awt.Color.YELLOW); + + /** Couleur Swing associée à la couleur Avalam. */ + private final java.awt.Color swingColor; + + /** + * Constructeur interne de l’énumération. + * @param col couleur Swing associée. + */ + Color(java.awt.Color col) { + this.swingColor = col; + } + + /** + * Retourne la couleur Swing (java.awt.Color) associée. + */ + public java.awt.Color getSwingColor() { + return this.swingColor; + } +} diff --git a/fr/iut_fbleau/Avalam/Main.java b/fr/iut_fbleau/Avalam/Main.java new file mode 100644 index 0000000..ef3497d --- /dev/null +++ b/fr/iut_fbleau/Avalam/Main.java @@ -0,0 +1,17 @@ +package fr.iut_fbleau.Avalam; + +import fr.iut_fbleau.Avalam.AvalamWindow; + +/** + * Classe principale lançant le programme Avalam. + * + * Le point d'entrée du programme crée simplement une fenêtre AvalamWindow, + * qui initialise l'affichage du jeu. + * + * @version 1.0 + */ +public class Main { + public static void main(String[] args) { + new AvalamWindow(); + } +} diff --git a/fr/iut_fbleau/AvalamTests/TestTower.class b/fr/iut_fbleau/AvalamTests/TestTower.class new file mode 100644 index 0000000000000000000000000000000000000000..a832969a069861bfc59a4d4962ff0ac22bc92163 GIT binary patch literal 1577 zcmX^0Z`VEs1_nolSS|)824;2!79Ivx1~x_pfvm)`ME#t^ymWp4q^#8B5=I6#o6Nk- z5<5l)W)00Sb_Nbc2C1|n{mjym__U;))WlMK$Fjtn#9aN5{PNTyP6jRpZgvJ99tK_p zK3poD^Kfg?S&1ng@@200B)e17F(&|uJH zXVBtd&}Ps<^%mG*Mh5n>#GKMp|1?GhHDr4sQEI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ut_fbleau/GameAPI/AbstractGame.class b/fr/iut_fbleau/GameAPI/AbstractGame.class new file mode 100644 index 0000000000000000000000000000000000000000..9c63903f185feb1d7de32a42c7c025003f6eaaa5 GIT binary patch literal 2148 zcmX^0Z`VEs1_nolL@ov<24;2!79Ivx1~x_pfvm)`ME#t^ymWp4q^#8B5=I6#o6Nk- z5<5l)W)00SP6iGJPId+^9tLg(9!3VGv?Be?(vtYJq@2{mQhoQt+*HQ^PkqOv;*z4o z^1x5xz3e;3!T^OLfjKsKn=LXb5vL zC^Bg9FlaJpF*5L^XO^W#=9d=v=9i^1GB|7C@Gw*>uJC|4E+D58949(F47v<@j126V z#XhO&i881OI{G8i#3u%_e(kVFs--N3}a+qan4UkWn|#@$;?aj zE6q(xEec6Y%1LEps3X}tDtZUxGUlSvJVplI;F84TY~REJu(Q}1{23V(38rgC2Cm@z z(xT*4w@i>%1d)SG50u0h83dg2^GiU5W`S>NNk)E3F$Y5kBZC?wKouAjGK&=w6_RrD z^HVAnk~2~hOY{^x6+n4cp|n7cpN%1miy@pLf}J4}ln|pB8B{>VLdx;Xyt4f4RDDPS zf}~Bi#N?9vqDn@F8OTWtsu1D;kHox`oYZ0!pZxsn(gJHpbb<2~#2{o56pbO31*yoA zQ037`CSb`+P$QfZb8><+OH!>F8F)PN@=}YOa}tY-Q;XRdVi_4!G5mzhsq75#j0|%4 zl`=B0LHxy{$iTtC#K6G7#J~iq(ZDQz1_1^}1~)Lsgk%5)LgMo>`lYxQ37*t&{ zFfj0IZD(NA(%#CzuBEe;fp;SV0|O(27Xt%>5CaPX1A__!3xg^HCxaRTAA>s7C~pQv z1|J4j21c+!I~kb4Dl@dUFtG1r5M*SS#Sp5sg@G5s7iVPH#vpxwLD2`oS7v1J)z;a@ zpza6a>+WRGW@4DhAOPj)Gchb@5ZTRO9I3s7!E_gcH3P$T2K)WX|1Sk8*va6;$glzI z9gqvv7&sXi7z`LdrK|#j5rY2Gc@?2Wm u85p&+w=%GA1gqv}U|`^5U}j)o5M*Fs5MtnD5N2Uy5MU4l%L;+b5e5L^=xGT6 literal 0 HcmV?d00001 diff --git a/fr/iut_fbleau/GameAPI/AbstractPly.class b/fr/iut_fbleau/GameAPI/AbstractPly.class new file mode 100644 index 0000000000000000000000000000000000000000..5a3a4d20f066e14f40c4519eb2abb9c8c4c97a13 GIT binary patch literal 417 zcmX^0Z`VEs1_nn45iSNM24;2!79Ivx1~x_pfvm)`ME#t^ymWp4q^#8B5=I6#o6Nk- z5<5l)W)00SP6iGJPId+^9tLg(9!3Vmv?Be?(vtYJq@2{mQhoQt+*HQ^PkqOv;*z4o zw!XmMUjDnfr){E zfsug;lsEGaEYWn{3%s>p^2 z+w80v8CX;D19B>fbzT@F1AA#6R133)W*8#_M{#0Ws&jrpCBE>0M2Hz{1EN$RGq37iJJ)U|?Wm5M>Z!U}O+y kU|^790GZ6dz@)VSEF;0dz`(}9$iTqh%fQGW2{u6r0MzTEOaK4? literal 0 HcmV?d00001 diff --git a/fr/iut_fbleau/GameAPI/Player.class b/fr/iut_fbleau/GameAPI/Player.class new file mode 100644 index 0000000000000000000000000000000000000000..c659c8b3dfd9f18f69828f989b5b73e4ea30458f GIT binary patch literal 998 zcmX^0Z`VEs1_nn4eRc*WMh2O*BK^$LlK8ZwoYcfpefPxNRL1~M{eYar%G4rG21W)J z9tKthHbw^a03XLl*C0bi200&mdaOa3ICvO1ku({B#JG7Fco=vY8Q4|A9DPDvgBcm* zqw$->#lX)Xz|O$S!yw2Y#K^#!oRgoI%E%z1q3M&ASeB@tlbDyT@1K;Fnp|Sd#UR2U z%FZCh!ywKe!N|aeP~e(Zn#;(*UY3|sn(Cj%$Y830q}w?svAEb8Ng%kSC^IkJ8rcSr z0bui`co?J^WEdIPY%=pQOY9gK#E^}G>h#nM<6vOrVqj#D;$Ywe(TY3_N({;%kAvM% z%*ddqp-I5&j0|ir#VpSGDXEMM{63j^seYxoNvTC4iAg!Bj0{FtY}dpeqKpgzzNsY{ z`6&U3MTxnoC8V!f*sUxKybP=iQVh%tObihB=rHJl H-K7TrLd?jw literal 0 HcmV?d00001 diff --git a/fr/iut_fbleau/GameAPI/Result.class b/fr/iut_fbleau/GameAPI/Result.class new file mode 100644 index 0000000000000000000000000000000000000000..4234ba934331213fdbeea51a1ec69d20b4ed21e5 GIT binary patch literal 1042 zcmX^0Z`VEs1_nn4V|E56Mh2O*BK^$LlK8ZwoYcfpefPxNRL1~M{h-w1(wq`b21W)J z9tKthHbw^Ka8Ex*200&m>a9T8waPOv zGcYqSFtBTB%WP+m*@$5eNFOH?1A_nq80#{C^y>+5f#MkITzv)>kZT#l+4eFpMlx?= zU=EIC*~Gve9Lc(gfh!o(EgTH`40=$_K~T+lyBQcGg%p^#GbnCmUpt6~P7vWAJuzn5(UT}zTF{m@JGcYkgoN2&d2zIU!0Nw7+@&Et; literal 0 HcmV?d00001 diff --git a/fr/iut_fbleau/Res/Plateau.txt b/fr/iut_fbleau/Res/Plateau.txt new file mode 100644 index 0000000..250d0c9 --- /dev/null +++ b/fr/iut_fbleau/Res/Plateau.txt @@ -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 -- 2.52.0