Epuration du Makefile, classe Abstraite pour les events, changement nom dossier Controlers -> Controller
This commit is contained in:
parent
9fc468f0c4
commit
01a656af7f
@ -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 :
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package fr.iutfbleau.projetAgile.Controlers.EventListener;
|
||||
package fr.iutfbleau.projetAgile.Controller.EventListener;
|
||||
|
||||
public class GridEvent {
|
||||
private int column;
|
@ -1,4 +1,4 @@
|
||||
package fr.iutfbleau.projetAgile.Controlers.EventListener;
|
||||
package fr.iutfbleau.projetAgile.Controller.EventListener;
|
||||
|
||||
public class PlayerEvent {
|
||||
|
@ -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
|
@ -1,4 +1,4 @@
|
||||
package fr.iutfbleau.projetAgile.Controlers;
|
||||
package fr.iutfbleau.projetAgile.Controller;
|
||||
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.*;
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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{
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user