Ajout controleur principal
This commit is contained in:
parent
6abd80a082
commit
1a17541120
@ -23,7 +23,7 @@ Events = build/$(PACKAGE_PATH)/Event/GridChangedListener.class \
|
||||
Model = build/$(PACKAGE_PATH)/Model/GrilleModel.class
|
||||
|
||||
Controller = build/$(PACKAGE_PATH)/Controller/GrilleMouseListener.class \
|
||||
build/$(PACKAGE_PATH)/Controller/ModelEventListener.class
|
||||
build/$(PACKAGE_PATH)/Controller/ModelEventListener.class \
|
||||
#------- Events ------
|
||||
|
||||
build/$(PACKAGE_PATH)/Event/PlayerEvent.class : src/$(PACKAGE_PATH)/Event/PlayerEvent.java
|
||||
@ -44,14 +44,10 @@ build/$(PACKAGE_PATH)/Event/AbstractGridInitiater.class : src/$(PACKAGE_PATH)/Ev
|
||||
#------- Controleur ------
|
||||
|
||||
build/$(PACKAGE_PATH)/Controller/ResetGame.class : src/$(PACKAGE_PATH)/Controller/ResetGame.java \
|
||||
build/$(PACKAGE_PATH)/View/Grille.class \
|
||||
build/$(PACKAGE_PATH)/Model/GrilleModel.class
|
||||
build/$(PACKAGE_PATH)/Puissance4Controller.class
|
||||
javac $(JAVAC_OPT) $<
|
||||
|
||||
build/$(PACKAGE_PATH)/Controller/GrilleMouseListener.class : src/$(PACKAGE_PATH)/Controller/GrilleMouseListener.java \
|
||||
build/$(PACKAGE_PATH)/View/Grille.class \
|
||||
build/$(PACKAGE_PATH)/Model/GrilleModel.class \
|
||||
build/$(PACKAGE_PATH)/Utils/GameStatus.class
|
||||
build/$(PACKAGE_PATH)/Controller/GrilleMouseListener.class : src/$(PACKAGE_PATH)/Controller/GrilleMouseListener.java
|
||||
javac $(JAVAC_OPT) $<
|
||||
|
||||
build/$(PACKAGE_PATH)/Controller/ModelEventListener.class : src/$(PACKAGE_PATH)/Controller/ModelEventListener.java \
|
||||
@ -65,6 +61,14 @@ build/$(PACKAGE_PATH)/Controller/ObservateurMenuSouris.class : src/$(PACKAGE_PAT
|
||||
build/$(PACKAGE_PATH)/View/BoutonsMenu.class
|
||||
javac $(JAVAC_OPT) $<
|
||||
|
||||
build/$(PACKAGE_PATH)/Puissance4Controller.class : src/$(PACKAGE_PATH)/Controller/Puissance4Controller.java \
|
||||
build/$(PACKAGE_PATH)/Model/GrilleModel.class \
|
||||
build/$(PACKAGE_PATH)/View/Grille.class \
|
||||
build/$(PACKAGE_PATH)/Utils/GameStatus.class \
|
||||
build/$(PACKAGE_PATH)/View/Puissance4Panel.class \
|
||||
$(Controller)
|
||||
javac $(JAVAC_OPT) $<
|
||||
|
||||
#------- Modele ------
|
||||
|
||||
build/$(PACKAGE_PATH)/Model/GrilleModel.class : src/$(PACKAGE_PATH)/Model/GrilleModel.java \
|
||||
@ -94,31 +98,25 @@ build/$(PACKAGE_PATH)/View/Grille.class : src/$(PACKAGE_PATH)/View/Grille.java \
|
||||
build/$(PACKAGE_PATH)/View/Puissance4Panel.class : src/$(PACKAGE_PATH)/View/Puissance4Panel.java \
|
||||
build/$(PACKAGE_PATH)/View/Pion.class \
|
||||
build/$(PACKAGE_PATH)/View/Grille.class \
|
||||
build/$(PACKAGE_PATH)/Controller/ResetGame.class \
|
||||
$(Controller)
|
||||
javac $(JAVAC_OPT) $<
|
||||
|
||||
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)/Controller/GrilleMouseListener.class \
|
||||
build/$(PACKAGE_PATH)/View/Menu.class
|
||||
build/$(PACKAGE_PATH)/Controller/ResetGame.class
|
||||
javac $(JAVAC_OPT) $<
|
||||
|
||||
build/$(PACKAGE_PATH)/View/BoutonsMenu.class : src/$(PACKAGE_PATH)/View/BoutonsMenu.java
|
||||
javac $(JAVAC_OPT) $<
|
||||
|
||||
build/$(PACKAGE_PATH)/View.Menu.class : src/$(PACKAGE_PATH)/View/Menu.java \
|
||||
build/$(PACKAGE_PATH)/View/Menu.class : src/$(PACKAGE_PATH)/View/Menu.java \
|
||||
build/$(PACKAGE_PATH)/View/BoutonsMenu.class \
|
||||
build/$(PACKAGE_PATH)/Controller/ObservateurMenuSouris.class
|
||||
javac $(JAVAC_OPT) $<
|
||||
|
||||
|
||||
build/$(PACKAGE_PATH)/Main.class : src/$(PACKAGE_PATH)/Main.java
|
||||
javac $(JAVAC_OPT) $<
|
||||
|
||||
testGrille : build/$(PACKAGE_PATH)/View/TestGrille.class
|
||||
java -cp build $(PACKAGE).View.TestGrille
|
||||
|
||||
puissance4 : build/$(PACKAGE_PATH)/View/Puissance4Panel.class
|
||||
java -cp build $(PACKAGE).View.Puissance4Panel
|
||||
puissance4 : build/$(PACKAGE_PATH)/Main.class \
|
||||
build/$(PACKAGE_PATH)/Puissance4Controller.class \
|
||||
$(Model)
|
||||
java -cp build $(PACKAGE_PATH).Main
|
||||
|
||||
clear :
|
||||
rm -rf build/*
|
||||
|
@ -2,32 +2,19 @@ package fr.iutfbleau.projetAgile.Controller;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import javax.swing.event.MouseInputAdapter;
|
||||
import fr.iutfbleau.projetAgile.Model.GrilleModel;
|
||||
import fr.iutfbleau.projetAgile.View.Grille;
|
||||
import static fr.iutfbleau.projetAgile.Utils.GameStatus.*;
|
||||
|
||||
public class GrilleMouseListener extends MouseInputAdapter{
|
||||
|
||||
private Grille grille;
|
||||
private GrilleModel modele;
|
||||
/**
|
||||
* Listener de la vue qui change le modèle lors des actions des utilisateurs
|
||||
* @param grille La vue
|
||||
* @param modele Le modèle
|
||||
*/
|
||||
public GrilleMouseListener(Grille grille, GrilleModel modele) {
|
||||
this.grille = grille;
|
||||
this.modele = modele;
|
||||
this.grille.init(this.modele.getTab());
|
||||
private Puissance4Controller controller;
|
||||
|
||||
public GrilleMouseListener(Puissance4Controller p) {
|
||||
this.controller = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
if(this.modele.getGameStatus() == PLAYING) {
|
||||
int column = (e.getX() * this.modele.getColumn() / grille.getWidth());
|
||||
this.modele.verifyColumn(column);
|
||||
}
|
||||
this.controller.verifyColumn(e.getX());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,52 @@
|
||||
package fr.iutfbleau.projetAgile.Controller;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import fr.iutfbleau.projetAgile.Model.GrilleModel;
|
||||
import fr.iutfbleau.projetAgile.Utils.GameStatus;
|
||||
import fr.iutfbleau.projetAgile.View.Grille;
|
||||
import fr.iutfbleau.projetAgile.View.Puissance4Panel;
|
||||
|
||||
public class Puissance4Controller {
|
||||
private Grille grille;
|
||||
private GrilleModel modele;
|
||||
private Puissance4Panel panel;
|
||||
/**
|
||||
* Controleur du jeu, il initialise la vue, les listeners, etc..
|
||||
* @param grille La grille
|
||||
* @param modele Le modèle
|
||||
*/
|
||||
public Puissance4Controller(Grille grille, GrilleModel modele) {
|
||||
this.modele = modele;
|
||||
this.grille = grille;
|
||||
|
||||
|
||||
ModelEventListener modelListener = new ModelEventListener(grille);
|
||||
ResetGame resetListener = new ResetGame(this);
|
||||
GrilleMouseListener mouseListener = new GrilleMouseListener(this);
|
||||
|
||||
this.modele.addGridListener(modelListener);
|
||||
this.grille.addMouseListener(mouseListener);
|
||||
|
||||
this.grille.init(modele.getTab());
|
||||
this.panel = new Puissance4Panel(this.grille);
|
||||
this.panel.addResetListener(resetListener);
|
||||
this.panel.init();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.grille.reset();
|
||||
this.modele.reset();
|
||||
}
|
||||
|
||||
public void verifyColumn(int x) {
|
||||
if(this.modele.getGameStatus() == GameStatus.PLAYING) {
|
||||
int column = (x * this.modele.getColumn() / grille.getWidth());
|
||||
this.modele.verifyColumn(column);
|
||||
}
|
||||
}
|
||||
|
||||
public JPanel getPanel() {
|
||||
return this.panel;
|
||||
}
|
||||
}
|
@ -1,9 +1,6 @@
|
||||
package fr.iutfbleau.projetAgile.Controller;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
import fr.iutfbleau.projetAgile.Model.GrilleModel;
|
||||
import fr.iutfbleau.projetAgile.View.Grille;
|
||||
|
||||
|
||||
|
||||
@ -12,18 +9,14 @@ public class ResetGame implements ActionListener {
|
||||
/**
|
||||
* obligatoire car test implémente l'interface ActionListener
|
||||
*/
|
||||
private Grille grille;
|
||||
private GrilleModel modele;
|
||||
private Puissance4Controller controller;
|
||||
|
||||
public ResetGame(Grille grille, GrilleModel modele){
|
||||
|
||||
this.grille = grille;
|
||||
this.modele = modele;
|
||||
public ResetGame(Puissance4Controller p){
|
||||
this.controller = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
this.modele.reset();
|
||||
this.grille.reset();
|
||||
this.controller.reset();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
package fr.iutfbleau.projetAgile;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
import fr.iutfbleau.projetAgile.Controller.Puissance4Controller;
|
||||
import fr.iutfbleau.projetAgile.Model.GrilleModel;
|
||||
import fr.iutfbleau.projetAgile.View.Grille;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Grille g = new Grille();
|
||||
GrilleModel m = new GrilleModel();
|
||||
Puissance4Controller p = new Puissance4Controller(g, m);
|
||||
JFrame frame = new JFrame();
|
||||
frame.add(p.getPanel());
|
||||
frame.setLocation(200, 200);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setSize(new Dimension(1280,720));
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
@ -4,10 +4,7 @@ import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import java.awt.*;
|
||||
import fr.iutfbleau.projetAgile.Controller.GrilleMouseListener;
|
||||
import fr.iutfbleau.projetAgile.Controller.ModelEventListener;
|
||||
import fr.iutfbleau.projetAgile.Controller.ResetGame;
|
||||
import fr.iutfbleau.projetAgile.Model.GrilleModel;
|
||||
|
||||
public class Puissance4Panel extends JPanel{
|
||||
|
||||
@ -16,23 +13,12 @@ public class Puissance4Panel extends JPanel{
|
||||
private JLabel label;
|
||||
private Grille grille;
|
||||
|
||||
public Puissance4Panel() {
|
||||
public Puissance4Panel(Grille grille) {
|
||||
super();
|
||||
this.reset = new JButton("RECOMMENCER");
|
||||
this.menu = new JButton("ACCUEIL");
|
||||
this.label = new JLabel("TOUR DU JOUEUR 1");
|
||||
this.grille = new Grille();
|
||||
|
||||
GrilleModel gm = new GrilleModel();
|
||||
GrilleMouseListener listener = new GrilleMouseListener(this.grille, gm);
|
||||
ResetGame resetGame = new ResetGame(grille, gm);
|
||||
reset.addActionListener(resetGame);
|
||||
ModelEventListener mel = new ModelEventListener(this.grille);
|
||||
this.grille.addMouseListener(listener);
|
||||
gm.addGridListener(mel);
|
||||
|
||||
this.init();
|
||||
//this.grille.requestFocusInWindow();
|
||||
this.grille = grille;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
@ -113,16 +99,8 @@ public class Puissance4Panel extends JPanel{
|
||||
return grille;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Puissance4Panel p = new Puissance4Panel();
|
||||
|
||||
JFrame frame = new JFrame();
|
||||
frame.add(p);
|
||||
frame.setLocation(200, 200);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setSize(new Dimension(1280,720));
|
||||
frame.setVisible(true);
|
||||
public void addResetListener(ResetGame l) {
|
||||
this.reset.addActionListener(l);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user