Séparation listener et vue
This commit is contained in:
parent
58548c4ef8
commit
e8a2d78379
@ -19,8 +19,8 @@ Events : build/$(PACKAGE_PATH)/Controller/EventListener/GridChangedListener.clas
|
||||
|
||||
Model : build/$(PACKAGE_PATH)/Model/GrilleModel.class
|
||||
|
||||
Controller : build/$(PACKAGE_PATH)/Controller/GrilleMouseListener.class
|
||||
|
||||
Controller : build/$(PACKAGE_PATH)/Controller/GrilleMouseListener.class \
|
||||
build/$(PACKAGE_PATH)/Controller/ModelEventListener.class
|
||||
#------- Events ------
|
||||
|
||||
build/$(PACKAGE_PATH)/Controller/EventListener/PlayerEvent.class : src/$(PACKAGE_PATH)/Controller/EventListener/PlayerEvent.java
|
||||
@ -47,6 +47,13 @@ build/$(PACKAGE_PATH)/Controller/GrilleMouseListener.class : src/$(PACKAGE_PATH)
|
||||
build/$(PACKAGE_PATH)/Model/GrilleModel.class
|
||||
javac $(JAVAC_OPT) $<
|
||||
|
||||
build/$(PACKAGE_PATH)/Controller/ModelEventListener.class : src/$(PACKAGE_PATH)/Controller/ModelEventListener.java \
|
||||
build/$(PACKAGE_PATH)/Controller/EventListener/GridChangedListener.class \
|
||||
build/$(PACKAGE_PATH)/Controller/EventListener/GridEvent.class \
|
||||
build/$(PACKAGE_PATH)/Controller/EventListener/PlayerEvent.class \
|
||||
build/$(PACKAGE_PATH)/View/Grille.class
|
||||
javac $(JAVAC_OPT) $<
|
||||
|
||||
#------- Modele ------
|
||||
|
||||
build/$(PACKAGE_PATH)/Model/GrilleModel.class : src/$(PACKAGE_PATH)/Model/GrilleModel.java \
|
||||
@ -66,9 +73,6 @@ 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)/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) $<
|
||||
|
||||
|
@ -14,13 +14,11 @@ 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
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
if(this.modele.getGameStatus() == PLAYING) {
|
||||
int column = (e.getX() * this.modele.getColumn() / grille.getWidth());
|
||||
|
@ -0,0 +1,25 @@
|
||||
package fr.iutfbleau.projetAgile.Controller;
|
||||
|
||||
import fr.iutfbleau.projetAgile.Controller.EventListener.*;
|
||||
import fr.iutfbleau.projetAgile.Utils.Constants;
|
||||
import fr.iutfbleau.projetAgile.View.Grille;
|
||||
|
||||
public class ModelEventListener implements GridChangedListener {
|
||||
|
||||
private Grille grille;
|
||||
|
||||
public ModelEventListener(Grille g) {
|
||||
this.grille = g;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gridChanged(GridEvent e) {
|
||||
this.grille.addPlayerPiece(e.getColumn(), e.getRow(), e.getPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerChanged(PlayerEvent e) {
|
||||
System.out.println("Tour du joueur : " + (e.getNewPlayer() == Constants.PLAYER_ONE ? "Rouge" : "Jaune"));
|
||||
}
|
||||
|
||||
}
|
@ -5,7 +5,7 @@ import java.awt.*;
|
||||
import fr.iutfbleau.projetAgile.Controller.EventListener.*;
|
||||
import fr.iutfbleau.projetAgile.Utils.Constants;
|
||||
|
||||
public class Grille extends JPanel implements GridChangedListener{
|
||||
public class Grille extends JPanel{
|
||||
|
||||
private Pion grille[][];
|
||||
private int column;
|
||||
@ -55,22 +55,12 @@ public class Grille extends JPanel implements GridChangedListener{
|
||||
}
|
||||
|
||||
|
||||
protected void addPlayerPiece(int column, int row, int player) {
|
||||
public void addPlayerPiece(int column, int row, int player) {
|
||||
Color c = player == Constants.PLAYER_ONE ? Constants.PLAYER_ONE_COLOR : Constants.PLAYER_TWO_COLOR;
|
||||
this.grille[column][row].setPlayer(player);
|
||||
this.grille[column][row].repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gridChanged(GridEvent e) {
|
||||
this.addPlayerPiece(e.getColumn(), e.getRow(), e.getPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerChanged(PlayerEvent e) {
|
||||
System.out.println("Tour du joueur : " + (e.getNewPlayer() == Constants.PLAYER_ONE ? "Rouge" : "Jaune"));
|
||||
}
|
||||
|
||||
|
||||
//Fonction de test (pourra être modifié)
|
||||
public void reset() {
|
||||
for (int x = 0; x < this.column; x++) {
|
||||
|
@ -3,6 +3,7 @@ package fr.iutfbleau.projetAgile.View;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import fr.iutfbleau.projetAgile.Controller.GrilleMouseListener;
|
||||
import fr.iutfbleau.projetAgile.Controller.ModelEventListener;
|
||||
import fr.iutfbleau.projetAgile.Model.GrilleModel;
|
||||
|
||||
public class Puissance4Panel extends JPanel{
|
||||
@ -21,6 +22,9 @@ public class Puissance4Panel extends JPanel{
|
||||
|
||||
GrilleModel gm = new GrilleModel();
|
||||
GrilleMouseListener listener = new GrilleMouseListener(this.grille, gm);
|
||||
ModelEventListener mel = new ModelEventListener(this.grille);
|
||||
this.grille.addMouseListener(listener);
|
||||
gm.addGridListener(mel);
|
||||
|
||||
this.init();
|
||||
//this.grille.requestFocusInWindow();
|
||||
|
Loading…
Reference in New Issue
Block a user