Ajout Tours Joueurs et Fenetre modale confirm reset
This commit is contained in:
parent
029356f568
commit
28ca45fbc4
@ -1,25 +1,24 @@
|
||||
package fr.iutfbleau.projetAgile.Controller;
|
||||
|
||||
import fr.iutfbleau.projetAgile.Event.*;
|
||||
import fr.iutfbleau.projetAgile.Utils.Constants;
|
||||
import fr.iutfbleau.projetAgile.View.Grille;
|
||||
import fr.iutfbleau.projetAgile.View.Puissance4Panel;
|
||||
|
||||
public class ModelEventListener implements GridChangedListener {
|
||||
|
||||
private Grille grille;
|
||||
private Puissance4Panel panel;
|
||||
|
||||
public ModelEventListener(Grille g) {
|
||||
this.grille = g;
|
||||
public ModelEventListener(Puissance4Panel p) {
|
||||
this.panel = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gridChanged(GridEvent e) {
|
||||
this.grille.addPlayerPiece(e.getColumn(), e.getRow(), e.getPlayer());
|
||||
this.panel.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"));
|
||||
//System.out.println("Tour du joueur : " + (e.getNewPlayer() == Constants.PLAYER_ONE ? "Rouge" : "Jaune"));
|
||||
this.panel.changeLabel(e.getNewPlayer());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package fr.iutfbleau.projetAgile.Controller;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import fr.iutfbleau.projetAgile.Model.GrilleModel;
|
||||
@ -19,24 +20,31 @@ public class Puissance4Controller {
|
||||
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);
|
||||
ModelEventListener modelListener = new ModelEventListener(panel);
|
||||
this.modele.addGridListener(modelListener);
|
||||
this.grille.addMouseListener(mouseListener);
|
||||
|
||||
this.panel.init();
|
||||
this.panel.changeLabel(this.modele.getPlayerTurn());
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
if(this.modele.getGameStatus() == GameStatus.PLAYING) {
|
||||
|
||||
int confirmation = JOptionPane.showConfirmDialog(this.panel, "Une partie est en cours ! Etes-vous sûr de vouloir recommencer ?", "Recommencer", JOptionPane.YES_NO_OPTION);
|
||||
if(confirmation == 1) return;
|
||||
}
|
||||
this.grille.reset();
|
||||
this.modele.reset();
|
||||
this.panel.changeLabel(this.modele.getPlayerTurn());
|
||||
}
|
||||
|
||||
public void verifyColumn(int x) {
|
||||
|
@ -8,6 +8,7 @@ public interface GridChangedListener extends EventListener{
|
||||
* @param e Evenement contenant la colonne, ligne et joueur du pion placé dans la grille
|
||||
*/
|
||||
void gridChanged(GridEvent e);
|
||||
|
||||
/**
|
||||
* Méthode invoqué lorsque le tour du joueur est modifié
|
||||
* @param e Evenement contenant l'ancien joueur et le nouveau
|
||||
|
@ -5,6 +5,7 @@ import javax.swing.border.EmptyBorder;
|
||||
|
||||
import java.awt.*;
|
||||
import fr.iutfbleau.projetAgile.Controller.ResetGame;
|
||||
import fr.iutfbleau.projetAgile.Utils.Constants;
|
||||
|
||||
public class Puissance4Panel extends JPanel{
|
||||
|
||||
@ -17,7 +18,7 @@ public class Puissance4Panel extends JPanel{
|
||||
super();
|
||||
this.reset = new JButton("RECOMMENCER");
|
||||
this.menu = new JButton("ACCUEIL");
|
||||
this.label = new JLabel("TOUR DU JOUEUR 1");
|
||||
this.label = new JLabel();
|
||||
this.grille = grille;
|
||||
}
|
||||
|
||||
@ -30,10 +31,10 @@ public class Puissance4Panel extends JPanel{
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 0;
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.anchor = GridBagConstraints.CENTER;
|
||||
gbc.gridwidth = 1;
|
||||
gbc.gridheight = 1;
|
||||
gbc.weightx = 0;
|
||||
gbc.weightx = 1;
|
||||
gbc.weighty = 0;
|
||||
gbc.insets = new Insets(0, 0, 0, 0);
|
||||
|
||||
@ -62,7 +63,7 @@ public class Puissance4Panel extends JPanel{
|
||||
gbc.anchor = GridBagConstraints.CENTER;
|
||||
gbc.gridwidth = 1;
|
||||
gbc.gridheight = 1;
|
||||
gbc.weightx = 0;
|
||||
gbc.weightx = 1.75;
|
||||
gbc.weighty = 0;
|
||||
gbc.insets = new Insets(0, 0, 0, 0);
|
||||
|
||||
@ -102,5 +103,26 @@ public class Puissance4Panel extends JPanel{
|
||||
public void addResetListener(ResetGame l) {
|
||||
this.reset.addActionListener(l);
|
||||
}
|
||||
|
||||
public void changeLabel(int joueur) {
|
||||
switch(joueur){
|
||||
|
||||
case Constants.PLAYER_ONE:
|
||||
this.label.setText("Tour Joueur 1");
|
||||
break;
|
||||
|
||||
case Constants.PLAYER_TWO:
|
||||
this.label.setText("Tour Joueur 2");
|
||||
break;
|
||||
|
||||
default:
|
||||
this.label.setText("TOUR JOUEUR INCONNU");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void addPlayerPiece(int column, int row, int player) {
|
||||
this.grille.addPlayerPiece(column, row, player);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user