diff --git a/projetAgile/Makefile b/projetAgile/Makefile index 8af9f83..b88e3b3 100644 --- a/projetAgile/Makefile +++ b/projetAgile/Makefile @@ -11,34 +11,42 @@ View : build/$(PACKAGE_PATH)/View/Pion.class \ Utils : build/$(PACKAGE_PATH)/Utils/Constants.class -Events : build/$(PACKAGE_PATH)/Controlers/EventListener/GridChangedListener.class \ - build/$(PACKAGE_PATH)/Controlers/EventListener/GridEvent.class \ - build/$(PACKAGE_PATH)/Controlers/EventListener/PlayerEvent.class +Events : build/$(PACKAGE_PATH)/Controller/EventListener/GridChangedListener.class \ + build/$(PACKAGE_PATH)/Controller/EventListener/GridEvent.class \ + build/$(PACKAGE_PATH)/Controller/EventListener/PlayerEvent.class + +Model : build/$(PACKAGE_PATH)/Model/GrilleModel.class #------- Events ------ -build/$(PACKAGE_PATH)/Controlers/EventListener/PlayerEvent.class : src/$(PACKAGE_PATH)/Controlers/EventListener/PlayerEvent.java - javac $(JAVAC_OPT) src/$(PACKAGE_PATH)/Controlers/EventListener/PlayerEvent.java +build/$(PACKAGE_PATH)/Controller/EventListener/PlayerEvent.class : src/$(PACKAGE_PATH)/Controller/EventListener/PlayerEvent.java + javac $(JAVAC_OPT) src/$(PACKAGE_PATH)/Controller/EventListener/PlayerEvent.java -build/$(PACKAGE_PATH)/Controlers/EventListener/GridEvent.class : src/$(PACKAGE_PATH)/Controlers/EventListener/GridEvent.java - javac $(JAVAC_OPT) src/$(PACKAGE_PATH)/Controlers/EventListener/GridEvent.java +build/$(PACKAGE_PATH)/Controller/EventListener/GridEvent.class : src/$(PACKAGE_PATH)/Controller/EventListener/GridEvent.java + javac $(JAVAC_OPT) src/$(PACKAGE_PATH)/Controller/EventListener/GridEvent.java -build/$(PACKAGE_PATH)/Controlers/EventListener/GridChangedListener.class : src/$(PACKAGE_PATH)/Controlers/EventListener/GridChangedListener.java \ - build/$(PACKAGE_PATH)/Controlers/EventListener/GridEvent.class \ - build/$(PACKAGE_PATH)/Controlers/EventListener/GridEvent.class - javac $(JAVAC_OPT) src/$(PACKAGE_PATH)/Controlers/EventListener/GridChangedListener.java +build/$(PACKAGE_PATH)/Controller/EventListener/GridChangedListener.class : src/$(PACKAGE_PATH)/Controller/EventListener/GridChangedListener.java \ + build/$(PACKAGE_PATH)/Controller/EventListener/GridEvent.class \ + build/$(PACKAGE_PATH)/Controller/EventListener/PlayerEvent.class + javac $(JAVAC_OPT) src/$(PACKAGE_PATH)/Controller/EventListener/GridChangedListener.java + +build/$(PACKAGE_PATH)/Controller/EventListener/AbstractGridInitiater.class : src/$(PACKAGE_PATH)/Controller/EventListener/AbstractGridInitiater.java \ + build/$(PACKAGE_PATH)/Controller/EventListener/GridChangedListener.class \ + build/$(PACKAGE_PATH)/Controller/EventListener/GridEvent.class \ + build/$(PACKAGE_PATH)/Controller/EventListener/PlayerEvent.class + javac $(JAVAC_OPT) src/$(PACKAGE_PATH)/Controller/EventListener/AbstractGridInitiater.java #------- Controleur ------ -build/$(PACKAGE_PATH)/Controlers/GrilleMouseListener.class : src/$(PACKAGE_PATH)/Controlers/GrilleMouseListener.java \ - build/$(PACKAGE_PATH)/View/Grille.class \ - build/$(PACKAGE_PATH)/Model/GrilleModel.class - javac $(JAVAC_OPT) src/$(PACKAGE_PATH)/Controlers/GrilleMouseListener.java +build/$(PACKAGE_PATH)/Controller/GrilleMouseListener.class : src/$(PACKAGE_PATH)/Controller/GrilleMouseListener.java \ + build/$(PACKAGE_PATH)/View/Grille.class \ + build/$(PACKAGE_PATH)/Model/GrilleModel.class + javac $(JAVAC_OPT) src/$(PACKAGE_PATH)/Controller/GrilleMouseListener.java #------- Modele ------ build/$(PACKAGE_PATH)/Model/GrilleModel.class : src/$(PACKAGE_PATH)/Model/GrilleModel.java \ - Events + build/$(PACKAGE_PATH)/Controller/EventListener/AbstractGridInitiater.class javac $(JAVAC_OPT) src/$(PACKAGE_PATH)/Model/GrilleModel.java #------- Utils ------ @@ -54,8 +62,10 @@ build/$(PACKAGE_PATH)/View/Pion.class : src/$(PACKAGE_PATH)/View/Pion.java \ build/$(PACKAGE_PATH)/View/Grille.class : src/$(PACKAGE_PATH)/View/Grille.java \ build/$(PACKAGE_PATH)/View/Pion.class \ - build/$(PACKAGE_PATH)/Utils/Constants.class \ - Events + build/$(PACKAGE_PATH)/Controller/EventListener/GridChangedListener.class \ + build/$(PACKAGE_PATH)/Controller/EventListener/GridEvent.class \ + build/$(PACKAGE_PATH)/Controller/EventListener/PlayerEvent.class \ + build/$(PACKAGE_PATH)/Utils/Constants.class javac $(JAVAC_OPT) src/$(PACKAGE_PATH)/View/Grille.java build/$(PACKAGE_PATH)/View/Puissance4Panel.class : src/$(PACKAGE_PATH)/View/Puissance4Panel.java \ @@ -66,13 +76,12 @@ build/$(PACKAGE_PATH)/View/Puissance4Panel.class : src/$(PACKAGE_PATH)/View/Pui build/$(PACKAGE_PATH)/View/TestGrille.class : src/$(PACKAGE_PATH)/View/TestGrille.java \ build/$(PACKAGE_PATH)/View/Puissance4Panel.class \ build/$(PACKAGE_PATH)/Model/GrilleModel.class \ - build/$(PACKAGE_PATH)/Controlers/GrilleMouseListener.class \ - + build/$(PACKAGE_PATH)/Controller/GrilleMouseListener.class javac $(JAVAC_OPT) src/$(PACKAGE_PATH)/View/TestGrille.java -testGrille : build/$(PACKAGE_PATH)/View/TestGrille.class +testGrille : Model View Utils Events java -cp build $(PACKAGE).View.TestGrille clear : diff --git a/projetAgile/src/fr/iutfbleau/projetAgile/Controller/EventListener/AbstractGridInitiater.java b/projetAgile/src/fr/iutfbleau/projetAgile/Controller/EventListener/AbstractGridInitiater.java new file mode 100644 index 0000000..77c193c --- /dev/null +++ b/projetAgile/src/fr/iutfbleau/projetAgile/Controller/EventListener/AbstractGridInitiater.java @@ -0,0 +1,37 @@ +package fr.iutfbleau.projetAgile.Controller.EventListener; +import javax.swing.event.EventListenerList; + +public abstract class AbstractGridInitiater { + + protected EventListenerList listeners = new EventListenerList(); + + public void addGridListener(GridChangedListener listener) { + listeners.add(GridChangedListener.class, listener); + } + + public void removeTGridListener(GridChangedListener listener) { + listeners.remove(GridChangedListener.class, listener); + } + + public GridChangedListener[] getGridListeners() { + return listeners.getListeners(GridChangedListener.class); + } + + protected void fireGridChanged(int column, int row, int player) { + GridEvent event = null; + for(GridChangedListener listener : getGridListeners()) { + if(event == null) + event = new GridEvent(column, row, player); + listener.gridChanged(event); + } + } + + protected void firePlayerChanged(int oldPlayer, int newPlayer) { + PlayerEvent event = null; + for(GridChangedListener listener : getGridListeners()) { + if(event == null) + event = new PlayerEvent(oldPlayer, newPlayer); + listener.playerChanged(event); + } + } +} diff --git a/projetAgile/src/fr/iutfbleau/projetAgile/Controlers/EventListener/GridChangedListener.java b/projetAgile/src/fr/iutfbleau/projetAgile/Controller/EventListener/GridChangedListener.java similarity index 72% rename from projetAgile/src/fr/iutfbleau/projetAgile/Controlers/EventListener/GridChangedListener.java rename to projetAgile/src/fr/iutfbleau/projetAgile/Controller/EventListener/GridChangedListener.java index 0c108a4..b2b9fee 100644 --- a/projetAgile/src/fr/iutfbleau/projetAgile/Controlers/EventListener/GridChangedListener.java +++ b/projetAgile/src/fr/iutfbleau/projetAgile/Controller/EventListener/GridChangedListener.java @@ -1,8 +1,9 @@ -package fr.iutfbleau.projetAgile.Controlers.EventListener; +package fr.iutfbleau.projetAgile.Controller.EventListener; import java.util.EventListener; public interface GridChangedListener extends EventListener{ void gridChanged(GridEvent e); void playerChanged(PlayerEvent e); + } diff --git a/projetAgile/src/fr/iutfbleau/projetAgile/Controlers/EventListener/GridEvent.java b/projetAgile/src/fr/iutfbleau/projetAgile/Controller/EventListener/GridEvent.java similarity index 87% rename from projetAgile/src/fr/iutfbleau/projetAgile/Controlers/EventListener/GridEvent.java rename to projetAgile/src/fr/iutfbleau/projetAgile/Controller/EventListener/GridEvent.java index 4e501e2..3b891cb 100644 --- a/projetAgile/src/fr/iutfbleau/projetAgile/Controlers/EventListener/GridEvent.java +++ b/projetAgile/src/fr/iutfbleau/projetAgile/Controller/EventListener/GridEvent.java @@ -1,4 +1,4 @@ -package fr.iutfbleau.projetAgile.Controlers.EventListener; +package fr.iutfbleau.projetAgile.Controller.EventListener; public class GridEvent { private int column; diff --git a/projetAgile/src/fr/iutfbleau/projetAgile/Controlers/EventListener/PlayerEvent.java b/projetAgile/src/fr/iutfbleau/projetAgile/Controller/EventListener/PlayerEvent.java similarity index 85% rename from projetAgile/src/fr/iutfbleau/projetAgile/Controlers/EventListener/PlayerEvent.java rename to projetAgile/src/fr/iutfbleau/projetAgile/Controller/EventListener/PlayerEvent.java index 56c2cfb..ae682e7 100644 --- a/projetAgile/src/fr/iutfbleau/projetAgile/Controlers/EventListener/PlayerEvent.java +++ b/projetAgile/src/fr/iutfbleau/projetAgile/Controller/EventListener/PlayerEvent.java @@ -1,4 +1,4 @@ -package fr.iutfbleau.projetAgile.Controlers.EventListener; +package fr.iutfbleau.projetAgile.Controller.EventListener; public class PlayerEvent { diff --git a/projetAgile/src/fr/iutfbleau/projetAgile/Controlers/GrilleMouseListener.java b/projetAgile/src/fr/iutfbleau/projetAgile/Controller/GrilleMouseListener.java similarity index 83% rename from projetAgile/src/fr/iutfbleau/projetAgile/Controlers/GrilleMouseListener.java rename to projetAgile/src/fr/iutfbleau/projetAgile/Controller/GrilleMouseListener.java index f46dc13..41cf01a 100644 --- a/projetAgile/src/fr/iutfbleau/projetAgile/Controlers/GrilleMouseListener.java +++ b/projetAgile/src/fr/iutfbleau/projetAgile/Controller/GrilleMouseListener.java @@ -1,4 +1,4 @@ -package fr.iutfbleau.projetAgile.Controlers; +package fr.iutfbleau.projetAgile.Controller; import java.awt.event.MouseEvent; import javax.swing.event.MouseInputAdapter; @@ -14,7 +14,9 @@ public class GrilleMouseListener extends MouseInputAdapter{ public GrilleMouseListener(Grille grille, GrilleModel modele) { this.grille = grille; this.modele = modele; + this.grille.addMouseListener(this); this.modele.addGridListener(grille); + this.grille.init(this.modele.getTab()); } @Override diff --git a/projetAgile/src/fr/iutfbleau/projetAgile/Controlers/ObservateurMenuSouris.java b/projetAgile/src/fr/iutfbleau/projetAgile/Controller/ObservateurMenuSouris.java similarity index 95% rename from projetAgile/src/fr/iutfbleau/projetAgile/Controlers/ObservateurMenuSouris.java rename to projetAgile/src/fr/iutfbleau/projetAgile/Controller/ObservateurMenuSouris.java index 144afcc..07f9eef 100644 --- a/projetAgile/src/fr/iutfbleau/projetAgile/Controlers/ObservateurMenuSouris.java +++ b/projetAgile/src/fr/iutfbleau/projetAgile/Controller/ObservateurMenuSouris.java @@ -1,4 +1,4 @@ -package fr.iutfbleau.projetAgile.Controlers; +package fr.iutfbleau.projetAgile.Controller; import java.awt.event.MouseListener; import java.awt.event.*; diff --git a/projetAgile/src/fr/iutfbleau/projetAgile/Model/GrilleModel.java b/projetAgile/src/fr/iutfbleau/projetAgile/Model/GrilleModel.java index f82a1c8..c68ae80 100644 --- a/projetAgile/src/fr/iutfbleau/projetAgile/Model/GrilleModel.java +++ b/projetAgile/src/fr/iutfbleau/projetAgile/Model/GrilleModel.java @@ -1,18 +1,16 @@ package fr.iutfbleau.projetAgile.Model; -import javax.swing.event.EventListenerList; -import fr.iutfbleau.projetAgile.Controlers.EventListener.*; +import fr.iutfbleau.projetAgile.Controller.EventListener.AbstractGridInitiater; import fr.iutfbleau.projetAgile.Utils.Constants; -public class GrilleModel { +public class GrilleModel extends AbstractGridInitiater{ private int[][] grille; private boolean partyEnd; private int playerTurn; private int column, row; - private EventListenerList listeners = new EventListenerList(); - public GrilleModel() { + super(); this.init(); } @@ -46,34 +44,8 @@ public class GrilleModel { firePlayerChanged(oldPlayer, this.playerTurn); } - public void addGridListener(GridChangedListener listener) { - listeners.add(GridChangedListener.class, listener); - } - - public void removeTGridListener(GridChangedListener listener) { - listeners.remove(GridChangedListener.class, listener); - } - - public GridChangedListener[] getGridListeners() { - return listeners.getListeners(GridChangedListener.class); - } - - private void fireGridChanged(int column, int row, int player) { - GridEvent event = null; - for(GridChangedListener listener : getGridListeners()) { - if(event == null) - event = new GridEvent(column, row, player); - listener.gridChanged(event); - } - } - - private void firePlayerChanged(int oldPlayer, int newPlayer) { - PlayerEvent event = null; - for(GridChangedListener listener : getGridListeners()) { - if(event == null) - event = new PlayerEvent(oldPlayer, newPlayer); - listener.playerChanged(event); - } + public int[][] getTab() { + return grille; } } diff --git a/projetAgile/src/fr/iutfbleau/projetAgile/View/Grille.java b/projetAgile/src/fr/iutfbleau/projetAgile/View/Grille.java index 3083e7c..6e707d2 100644 --- a/projetAgile/src/fr/iutfbleau/projetAgile/View/Grille.java +++ b/projetAgile/src/fr/iutfbleau/projetAgile/View/Grille.java @@ -2,7 +2,7 @@ package fr.iutfbleau.projetAgile.View; import javax.swing.*; import java.awt.*; -import fr.iutfbleau.projetAgile.Controlers.EventListener.*; +import fr.iutfbleau.projetAgile.Controller.EventListener.*; import fr.iutfbleau.projetAgile.Utils.Constants; public class Grille extends JPanel implements GridChangedListener{ @@ -11,16 +11,11 @@ public class Grille extends JPanel implements GridChangedListener{ public Grille() { super(); - this.init(); } - protected void init() { + public void init(int[][] tab) { this.setBackground(new Color(31,31,31)); - this.reset(); - } - - public void reset() { - /* + /* * On peut remplacer GridBagLayout par un GridLayout */ GridBagLayout gbl = new GridBagLayout(); @@ -29,7 +24,7 @@ public class Grille extends JPanel implements GridChangedListener{ this.grille = new Pion[Constants.COLUMN_COUNT][Constants.ROW_COUNT]; for (int x = 0; x < Constants.COLUMN_COUNT; x++) { for (int y = 0; y < Constants.ROW_COUNT; y++) { - Pion pion = new Pion(-1); + Pion pion = new Pion(tab[x][y]); gbc.gridx = x; gbc.gridy = y; gbc.fill = GridBagConstraints.BOTH; @@ -54,7 +49,7 @@ public class Grille extends JPanel implements GridChangedListener{ this.setMinimumSize(new Dimension(minimumWidth, minimumHeight)); this.setPreferredSize(new Dimension(preferredWidth, preferredHeight)); } - + protected void addPlayerPawn(int column, int row, int player) { Color c = player == Constants.PLAYER_ONE ? Constants.PLAYER_ONE_COLOR : Constants.PLAYER_TWO_COLOR; diff --git a/projetAgile/src/fr/iutfbleau/projetAgile/View/Menu.java b/projetAgile/src/fr/iutfbleau/projetAgile/View/Menu.java index 5318be7..e282e7d 100644 --- a/projetAgile/src/fr/iutfbleau/projetAgile/View/Menu.java +++ b/projetAgile/src/fr/iutfbleau/projetAgile/View/Menu.java @@ -3,7 +3,7 @@ package fr.iutfbleau.projetAgile.View; import java.awt.*; import javax.swing.JFrame; import javax.swing.JLabel; -import fr.iutfbleau.projetAgile.Controlers.*; +import fr.iutfbleau.projetAgile.Controller.*; public class Menu extends JFrame{ diff --git a/projetAgile/src/fr/iutfbleau/projetAgile/View/TestGrille.java b/projetAgile/src/fr/iutfbleau/projetAgile/View/TestGrille.java index 31dab12..4837eb8 100644 --- a/projetAgile/src/fr/iutfbleau/projetAgile/View/TestGrille.java +++ b/projetAgile/src/fr/iutfbleau/projetAgile/View/TestGrille.java @@ -2,7 +2,7 @@ package fr.iutfbleau.projetAgile.View; import javax.swing.*; import java.awt.*; -import fr.iutfbleau.projetAgile.Controlers.GrilleMouseListener; +import fr.iutfbleau.projetAgile.Controller.GrilleMouseListener; import fr.iutfbleau.projetAgile.Model.GrilleModel; @@ -14,7 +14,6 @@ public class TestGrille extends JFrame{ Grille g = p.getGrille(); GrilleModel gm = new GrilleModel(); GrilleMouseListener listener = new GrilleMouseListener(g, gm); - g.addMouseListener(listener); this.add(p); this.setLocation(200, 200); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);