ajout choix nom et séparation MVC

This commit is contained in:
martins 2022-10-24 20:32:57 +02:00
parent 3caf82f50e
commit eb5ed9886c
9 changed files with 235 additions and 34 deletions

View File

@ -117,7 +117,8 @@ build/$(PACKAGE_PATH)/Menu/View/BoutonsMenu.class : src/$(PACKAGE_PATH)/Menu/Vie
build/$(PACKAGE_PATH)/Menu/View/Menu.class : src/$(PACKAGE_PATH)/Menu/View/Menu.java \
build/$(PACKAGE_PATH)/Menu/Controller/ObservateurMenuSouris.class \
build/$(PACKAGE_PATH)/Menu/View/BoutonsMenu.class \
build/$(PACKAGE_PATH)/Menu/Controller/ObservateurFenetre.class
build/$(PACKAGE_PATH)/Menu/Controller/ObservateurFenetre.class \
build/$(PACKAGE_PATH)/Puissance4/LancementPartie.class
@javac $(@JAVAC_OPT) $<
@ -125,10 +126,16 @@ build/$(PACKAGE_PATH)/Main.class : src/$(PACKAGE_PATH)/Main.java \
build/$(PACKAGE_PATH)/Menu/View/Menu.class \
build/$(PACKAGE_PATH)/Puissance4/Controller/Puissance4Controller.class \
build/$(PACKAGE_PATH)/Puissance4/View/Grille.class \
build/$(PACKAGE_PATH)/Puissance4/Model/GrilleModel.class
build/$(PACKAGE_PATH)/Puissance4/Model/GrilleModel.class \
build/$(PACKAGE_PATH)/Puissance4/LancementPartie.class
@echo "Classes compiled"
@javac $(@JAVAC_OPT) $<
build/$(PACKAGE_PATH)/Puissance4/LancementPartie.class : src/$(PACKAGE_PATH)/Puissance4/LancementPartie.java \
build/$(PACKAGE_PATH)/Puissance4/Controller/Puissance4Controller.class \
build/$(PACKAGE_PATH)/Puissance4/View/Grille.class \
build/$(PACKAGE_PATH)/Puissance4/Model/GrilleModel.class
@javac $(@JAVAC_OPT) $<
# BUT FACTICES:
.PHONY: clear doc run

137
projetAgile/Makefile~ Normal file
View File

@ -0,0 +1,137 @@
JAVAC_OPT = -implicit:none \
-d build -classpath build -sourcepath src
PACKAGE = fr.iutfbleau.projetAgile
PACKAGE_PATH = fr/iutfbleau/projetAgile
#------- Variables ------
View = build/$(PACKAGE_PATH)/View/Pion.class \
build/$(PACKAGE_PATH)/View/Grille.class \
build/$(PACKAGE_PATH)/View/Puissance4Panel.class \
build/$(PACKAGE_PATH)/View/BoutonsMenu.class \
build/$(PACKAGE_PATH)/View/Menu.class
Utils = build/$(PACKAGE_PATH)/Utils/Constants.class \
build/$(PACKAGE_PATH)/Utils/GameStatus.class
Events = build/$(PACKAGE_PATH)/Event/GridChangedListener.class \
build/$(PACKAGE_PATH)/Event/GridEvent.class \
build/$(PACKAGE_PATH)/Event/PlayerEvent.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/ResetGame.class
#BUT PAR DEFAUT
ArgileGames.jar : build/$(PACKAGE_PATH)/Main.class
jar cvfe ArgileGames.jar $(PACKAGE_PATH).Main -C build fr -C res images
#------- Events ------
build/$(PACKAGE_PATH)/Event/PlayerEvent.class : src/$(PACKAGE_PATH)/Event/PlayerEvent.java
javac $(JAVAC_OPT) $<
build/$(PACKAGE_PATH)/Event/GridEvent.class : src/$(PACKAGE_PATH)/Event/GridEvent.java
javac $(JAVAC_OPT) $<
build/$(PACKAGE_PATH)/Event/GridChangedListener.class : src/$(PACKAGE_PATH)/Event/GridChangedListener.java \
build/$(PACKAGE_PATH)/Event/GridEvent.class \
build/$(PACKAGE_PATH)/Event/PlayerEvent.class
javac $(JAVAC_OPT) $<
build/$(PACKAGE_PATH)/Event/AbstractGridInitiater.class : src/$(PACKAGE_PATH)/Event/AbstractGridInitiater.java \
$(Events)
javac $(JAVAC_OPT) $<
#------- Controleur ------
build/$(PACKAGE_PATH)/Controller/ResetGame.class : src/$(PACKAGE_PATH)/Controller/ResetGame.java
javac $(JAVAC_OPT) $<
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 \
build/$(PACKAGE_PATH)/Event/GridChangedListener.class \
build/$(PACKAGE_PATH)/View/Grille.class \
$(Event)
javac $(JAVAC_OPT) $<
build/$(PACKAGE_PATH)/Controller/ObservateurMenuSouris.class : src/$(PACKAGE_PATH)/Controller/ObservateurMenuSouris.java \
build/$(PACKAGE_PATH)/View/BoutonsMenu.class \
build/$(PACKAGE_PATH)/Utils/Constants.class
javac $(JAVAC_OPT) $<
build/$(PACKAGE_PATH)/Controller/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 \
build/$(PACKAGE_PATH)/Event/AbstractGridInitiater.class \
$(Utils)
javac $(JAVAC_OPT) $<
#------- Utils ------
build/$(PACKAGE_PATH)/Utils/Constants.class : src/$(PACKAGE_PATH)/Utils/Constants.java
javac $(JAVAC_OPT) $<
build/$(PACKAGE_PATH)/Utils/GameStatus.class : src/$(PACKAGE_PATH)/Utils/GameStatus.java
javac $(JAVAC_OPT) $<
#------- Vue ------
build/$(PACKAGE_PATH)/View/Pion.class : src/$(PACKAGE_PATH)/View/Pion.java \
build/$(PACKAGE_PATH)/Utils/Constants.class
javac $(JAVAC_OPT) $<
build/$(PACKAGE_PATH)/View/Grille.class : src/$(PACKAGE_PATH)/View/Grille.java \
build/$(PACKAGE_PATH)/View/Pion.class \
build/$(PACKAGE_PATH)/Utils/Constants.class
javac $(JAVAC_OPT) $<
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)/Utils/Constants.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)/Controller/ObservateurMenuSouris.class \
build/$(PACKAGE_PATH)/View/BoutonsMenu.class \
build/$(PACKAGE_PATH)/Utils/Constants.class
javac $(JAVAC_OPT) $<
build/$(PACKAGE_PATH)/Main.class : src/$(PACKAGE_PATH)/Main.java \
build/$(PACKAGE_PATH)/View/Menu.class \
build/$(PACKAGE_PATH)/Controller/Puissance4Controller.class \
build/$(PACKAGE_PATH)/View/Grille.class \
build/$(PACKAGE_PATH)/Model/GrilleModel.class
javac $(JAVAC_OPT) $<
# BUT FACTICES:
.PHONY: clear doc run
doc :
javadoc -d doc src/$(PACKAGE_PATH)/View/*.java src/$(PACKAGE_PATH)/Controller/*.java src/$(PACKAGE_PATH)/Utils/*.java src/$(PACKAGE_PATH)/Model/*.java src/$(PACKAGE_PATH)/Event/*.java
run: ArgileGames.jar
java -jar ArgileGames.jar
clear :
rm -rf build/*

View File

@ -2,10 +2,6 @@ package fr.iutfbleau.projetAgile;
import javax.swing.*;
import java.awt.*;
import fr.iutfbleau.projetAgile.Puissance4.Controller.Puissance4Controller;
import fr.iutfbleau.projetAgile.Puissance4.Model.GrilleModel;
import fr.iutfbleau.projetAgile.Puissance4.View.Grille;
import fr.iutfbleau.projetAgile.Menu.View.Menu;
public class Main {
@ -14,11 +10,7 @@ public class Main {
frame.setLocation(200, 200);
frame.setSize(new Dimension(1280,720));
JPanel menu=Menu.InitMenu();
Grille g = new Grille();
GrilleModel m = new GrilleModel();
Puissance4Controller p = new Puissance4Controller(g, m);
frame.add(menu, Menu.MENU);
frame.add(p.getPanel(), Menu.PUISSANCE_4);
frame.setVisible(true);
}
}

View File

@ -7,14 +7,12 @@ import fr.iutfbleau.projetAgile.Menu.View.Menu;
public class ObservateurAccueil implements ActionListener{
private Component comp;
private String jeu;
public ObservateurAccueil(Component parent, String jeu0){
public ObservateurAccueil(Component parent){
this.comp=parent;
this.jeu=jeu0;
}
public void actionPerformed(ActionEvent evenement){
int confirmation = JOptionPane.showConfirmDialog(this.comp, "Etes-vous sûr de vouloir retourner au menu ?", "Menu", JOptionPane.YES_NO_OPTION);
if(confirmation == 1) return;
Menu.show(Menu.MENU, this.comp, this.jeu);
Menu.show(Menu.MENU, this.comp);
}
}

View File

@ -16,7 +16,7 @@ public class ObservateurMenuSouris implements MouseListener{
public void mouseClicked(MouseEvent evenement){
BoutonsMenu bout=(BoutonsMenu) (evenement.getComponent());
if(bout.getPath()==Menu.PUISSANCE_4){
Menu.show(Menu.PUISSANCE_4, null, null);
Menu.show(Menu.PUISSANCE_4, null);
}
} // un bouton cliqué
public void mouseEntered(MouseEvent evenement){

View File

@ -2,7 +2,6 @@ package fr.iutfbleau.projetAgile.Menu.View;
import javax.swing.JComponent;
import java.awt.*;
import java.awt.geom.*;
/**
* Class Dessinant les boutons du menu

View File

@ -5,10 +5,13 @@ import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import fr.iutfbleau.projetAgile.Menu.Controller.*;
import fr.iutfbleau.projetAgile.Puissance4.View.*;
import fr.iutfbleau.projetAgile.Puissance4.LancementPartie;
import fr.iutfbleau.projetAgile.Puissance4.Controller.*;
import fr.iutfbleau.projetAgile.Puissance4.Model.*;
import fr.iutfbleau.projetAgile.Puissance4.Model.GrilleModel;
import fr.iutfbleau.projetAgile.Puissance4.View.Grille;
import java.awt.event.WindowListener;
import javax.swing.JOptionPane;
public abstract class Menu{
public static String PUISSANCE_4="puissance4";
@ -132,19 +135,19 @@ public abstract class Menu{
* si l'argument ne correspond pas a une Carte
*/
public static void show(String g, Component composent, String proveneur) throws IllegalArgumentException
public static void show(String g, Component composent) throws IllegalArgumentException
{
if((g==Menu.MENU || g==Menu.PUISSANCE_4) && (proveneur==Menu.PUISSANCE_4 || proveneur==null)){
if(g!=Menu.MENU)
Menu.cd.show(Menu.frame.getContentPane(), g);
if((g==Menu.MENU || g==Menu.PUISSANCE_4)){
if(g!=Menu.MENU){
if(g==Menu.PUISSANCE_4){
LancementPartie lm=new LancementPartie(Menu.frame);
lm.addActionListener(new ObservateurAccueil(lm.getPanel()));
Menu.frame.add(lm.getPanel(), Menu.PUISSANCE_4);
}
Menu.cd.show(Menu.frame.getContentPane(), g);
}
else{
Menu.cd.removeLayoutComponent(composent);
if(proveneur==Menu.PUISSANCE_4){
Grille f = new Grille();
GrilleModel m = new GrilleModel();
Puissance4Controller p = new Puissance4Controller(f, m);
Menu.frame.add(p.getPanel(), Menu.PUISSANCE_4);
}
}
}else{
throw new IllegalArgumentException();

View File

@ -3,8 +3,7 @@ package fr.iutfbleau.projetAgile.Puissance4.Controller;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import fr.iutfbleau.projetAgile.Menu.Controller.ObservateurAccueil;
import fr.iutfbleau.projetAgile.Menu.View.Menu;
import java.awt.event.ActionListener;
import fr.iutfbleau.projetAgile.Puissance4.Model.GrilleModel;
import fr.iutfbleau.projetAgile.Puissance4.Utils.GameStatus;
import fr.iutfbleau.projetAgile.Puissance4.View.Grille;
@ -19,7 +18,7 @@ public class Puissance4Controller {
* @param grille La grille
* @param modele Le modèle
*/
public Puissance4Controller(Grille grille, GrilleModel modele) {
public Puissance4Controller(Grille grille, GrilleModel modele, String J1, String J2) {
this.modele = modele;
this.grille = grille;
@ -32,14 +31,13 @@ public class Puissance4Controller {
this.grille.addMouseMotionListener(mouseListener);
//Initialisation des noms des joueurs
this.modele.setPlayerOneName("Joueur 1"); //A changer
this.modele.setPlayerTwoName("Joueur 2");
this.modele.setPlayerOneName(J1);
this.modele.setPlayerTwoName(J2);
//Initialisation du panneau avec la grille, les boutons, etc
this.panel = new Puissance4Panel(this.grille);
this.panel.init();
this.panel.resetButton(resetListener);
this.panel.acceuilButton(new ObservateurAccueil(this.getPanel(), Menu.PUISSANCE_4));
ModelEventListener modelListener = new ModelEventListener(panel);
this.panel.setPlayerOneName(this.modele.getPlayerOneName());
this.panel.setPlayerTwoName(this.modele.getPlayerTwoName());
@ -81,4 +79,12 @@ public class Puissance4Controller {
return this.panel;
}
public void AddActionListener(ActionListener l){
this.panel.acceuilButton(l);
}
public void ChangeName(String J1, String J2)throws IllegalArgumentException{
this.modele.setPlayerOneName(J1);
this.modele.setPlayerTwoName(J2);
}
}

View File

@ -0,0 +1,59 @@
package fr.iutfbleau.projetAgile.Puissance4;
import javax.swing.*;
import fr.iutfbleau.projetAgile.Puissance4.Controller.Puissance4Controller;
import fr.iutfbleau.projetAgile.Puissance4.View.Grille;
import fr.iutfbleau.projetAgile.Puissance4.Model.GrilleModel;
import java.awt.event.ActionListener;
public class LancementPartie {
private Puissance4Controller P4;
public LancementPartie(JFrame fenetre){
JTextField field1 = new JTextField("Joueur 1");
JTextField field2 = new JTextField("Joueur 2");
Object[] message = {
"Entrez le nom du joueur 1", field1,
"Entrez le nom du joueur 2:", field2,
};
int choix = JOptionPane.showConfirmDialog(fenetre, message, "Entrez les noms des joueurs", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if (choix == JOptionPane.OK_OPTION)
{
try {
String J1 = field1.getText();
String J2 = field2.getText();
Grille g=new Grille();
GrilleModel m=new GrilleModel();
this.P4= new Puissance4Controller(g, m, J1, J2);
} catch (Exception e) {
}
}
}
public void addActionListener(ActionListener l){
this.P4.AddActionListener(l);
}
public void ChangeName(JFrame fenetre){
JTextField field1 = new JTextField("Joueur 1");
JTextField field2 = new JTextField("Joueur 2");
Object[] message = {
"Entrez le nom du joueur 1", field1,
"Entrez le nom du joueur 2:", field2,
};
int choix = JOptionPane.showConfirmDialog(fenetre, message, "Entrez les noms des joueurs", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if (choix == JOptionPane.OK_OPTION)
{
try {
String J1 = field1.getText();
String J2 = field2.getText();
this.P4.ChangeName(J1, J2);
}catch(Exception e){
throw e;
}
}
}
public JPanel getPanel(){
return this.P4.getPanel();
}
}