ajout d'un bouton restart
This commit is contained in:
@@ -31,7 +31,7 @@ public class App {
|
|||||||
IO io = new IO(jeu);
|
IO io = new IO(jeu);
|
||||||
vueTetris.addKeyListener(io);
|
vueTetris.addKeyListener(io);
|
||||||
|
|
||||||
new TetrisBandeauControleur(vueTetris.getVueBandeauControle(), musique, grille);// Création d'un controleur de
|
new TetrisBandeauControleur(vueTetris.getVueBandeauControle(), musique, grille, jeu);// Création d'un controleur de
|
||||||
// bandeau avec la musique
|
// bandeau avec la musique
|
||||||
// instanciée
|
// instanciée
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package org.Controllers;
|
package org.Controllers;
|
||||||
|
|
||||||
import org.Models.Grille;
|
import org.Models.Grille;
|
||||||
|
import org.Models.Jeu;
|
||||||
import org.Models.Musique;
|
import org.Models.Musique;
|
||||||
|
import org.Models.PieceCourante;
|
||||||
import org.Views.VueBandeauControle;
|
import org.Views.VueBandeauControle;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@@ -12,12 +14,14 @@ public class TetrisBandeauControleur {
|
|||||||
private Musique musique;
|
private Musique musique;
|
||||||
private VueBandeauControle vueControle;
|
private VueBandeauControle vueControle;
|
||||||
private Grille grille;
|
private Grille grille;
|
||||||
|
private Jeu jeu;
|
||||||
private JButton aideButton;
|
private JButton aideButton;
|
||||||
|
|
||||||
public TetrisBandeauControleur(VueBandeauControle vueControle, Musique musique, Grille grille) {
|
public TetrisBandeauControleur(VueBandeauControle vueControle, Musique musique, Grille grille, Jeu jeu) {
|
||||||
this.vueControle = vueControle;
|
this.vueControle = vueControle;
|
||||||
this.musique = musique;
|
this.musique = musique;
|
||||||
this.grille = grille;
|
this.grille = grille;
|
||||||
|
this.jeu = jeu;
|
||||||
// action play/pause
|
// action play/pause
|
||||||
//Listener pour le bouton play/pause
|
//Listener pour le bouton play/pause
|
||||||
this.vueControle.getPauseButton().addActionListener(e -> switchPlayPause());
|
this.vueControle.getPauseButton().addActionListener(e -> switchPlayPause());
|
||||||
@@ -28,6 +32,13 @@ public class TetrisBandeauControleur {
|
|||||||
});
|
});
|
||||||
//Listener pour le bouton aide
|
//Listener pour le bouton aide
|
||||||
this.vueControle.getAideButton().addActionListener(e -> afficherAide());
|
this.vueControle.getAideButton().addActionListener(e -> afficherAide());
|
||||||
|
//Listener pour le bouton recommencer
|
||||||
|
this.vueControle.getRelancerButton().addActionListener(e -> {
|
||||||
|
jeu.reinitialiserPartie();
|
||||||
|
vueControle.getPauseButton().setText("PAUSE");
|
||||||
|
partieEnPause = false;
|
||||||
|
partieTerminee = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void switchPlayPause() {
|
public void switchPlayPause() {
|
||||||
|
|||||||
@@ -360,4 +360,15 @@ public class Grille extends Observable { // TODO: ?? implements Runnable {
|
|||||||
public void setNbLignesSupprimees(int nbLignesSupprimees) {
|
public void setNbLignesSupprimees(int nbLignesSupprimees) {
|
||||||
this.nbLignesSupprimees = nbLignesSupprimees;
|
this.nbLignesSupprimees = nbLignesSupprimees;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reinitialiserGrille() {
|
||||||
|
initGrille();
|
||||||
|
score = 0;
|
||||||
|
nbLignesSupprimees = 0;
|
||||||
|
pieceCourante = null;
|
||||||
|
pieceCouranteX = 3;
|
||||||
|
pieceCouranteY = 0;
|
||||||
|
setChanged();
|
||||||
|
notifyObservers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -19,6 +19,7 @@ public class VueBandeauControle extends JPanel implements Observer {
|
|||||||
private JLabel nbLigneLabel;
|
private JLabel nbLigneLabel;
|
||||||
private JButton quitterButton;
|
private JButton quitterButton;
|
||||||
private Jeu jeu;
|
private Jeu jeu;
|
||||||
|
private JButton relancerButton;
|
||||||
|
|
||||||
public VueBandeauControle(Jeu jeu) {
|
public VueBandeauControle(Jeu jeu) {
|
||||||
this.jeu = jeu;
|
this.jeu = jeu;
|
||||||
@@ -53,29 +54,32 @@ public class VueBandeauControle extends JPanel implements Observer {
|
|||||||
pauseButton.setMargin(margeBoutton);
|
pauseButton.setMargin(margeBoutton);
|
||||||
quitterButton.setPreferredSize(buttonSize);
|
quitterButton.setPreferredSize(buttonSize);
|
||||||
quitterButton.setMargin(margeBoutton);
|
quitterButton.setMargin(margeBoutton);
|
||||||
JPanel boutonsPanel = new JPanel();
|
JPanel hautBoutonsPanel = new JPanel();
|
||||||
//boutonsPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 0));
|
//boutonsPanel.setLayout(new BoxLayout(boutonsPanel, BoxLayout.X_AXIS));
|
||||||
boutonsPanel.setLayout(new BoxLayout(boutonsPanel, BoxLayout.X_AXIS));
|
hautBoutonsPanel.setOpaque(false);
|
||||||
boutonsPanel.setOpaque(false);
|
hautBoutonsPanel.add(pauseButton);
|
||||||
boutonsPanel.add(pauseButton);
|
hautBoutonsPanel.add(Box.createRigidArea(new Dimension(10, 0)));
|
||||||
boutonsPanel.add(Box.createRigidArea(new Dimension(10, 0)));
|
hautBoutonsPanel.add(quitterButton);
|
||||||
boutonsPanel.add(quitterButton);
|
|
||||||
pauseButton.setFocusable(false);
|
pauseButton.setFocusable(false);
|
||||||
quitterButton.setFocusable(false);
|
quitterButton.setFocusable(false);
|
||||||
|
|
||||||
|
//Relancer button
|
||||||
|
relancerButton = new JButton("RESTART");
|
||||||
|
relancerButton.setPreferredSize(buttonSize);
|
||||||
|
relancerButton.setMargin(margeBoutton);
|
||||||
|
relancerButton.setFocusable(false);
|
||||||
|
|
||||||
// AIDE BUTTON
|
// AIDE BUTTON
|
||||||
aideButton = new JButton("?");
|
aideButton = new JButton("?");
|
||||||
aideButton.setToolTipText("AFFICHER L'AIDE");
|
aideButton.setToolTipText("AFFICHER L'AIDE");
|
||||||
aideButton.setPreferredSize(new Dimension(45, 20));
|
aideButton.setPreferredSize(new Dimension(45, 20));
|
||||||
aideButton.setFocusable(false);
|
aideButton.setFocusable(false);
|
||||||
JPanel footerPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 5));
|
|
||||||
|
JPanel footerPanel = new JPanel(new BorderLayout());
|
||||||
footerPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 40));
|
footerPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 40));
|
||||||
footerPanel.setOpaque(false);
|
footerPanel.setOpaque(false);
|
||||||
footerPanel.add(aideButton);
|
footerPanel.add(relancerButton, BorderLayout.WEST);
|
||||||
|
footerPanel.add(aideButton, BorderLayout.EAST);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
add(Box.createVerticalStrut(20));
|
add(Box.createVerticalStrut(20));
|
||||||
add(scoreLabel);
|
add(scoreLabel);
|
||||||
@@ -84,9 +88,8 @@ public class VueBandeauControle extends JPanel implements Observer {
|
|||||||
add(Box.createVerticalStrut(20));
|
add(Box.createVerticalStrut(20));
|
||||||
add(nextPiecePanel);
|
add(nextPiecePanel);
|
||||||
add(Box.createVerticalStrut(20));
|
add(Box.createVerticalStrut(20));
|
||||||
add(boutonsPanel);
|
add(hautBoutonsPanel);
|
||||||
add(Box.createVerticalGlue()); //force le JPanel à prendre toute la hauteur
|
add(Box.createVerticalGlue()); //force le JPanel à prendre toute la hauteur
|
||||||
|
|
||||||
add(footerPanel);
|
add(footerPanel);
|
||||||
|
|
||||||
// setVisible(true);
|
// setVisible(true);
|
||||||
@@ -153,6 +156,10 @@ public class VueBandeauControle extends JPanel implements Observer {
|
|||||||
return aideButton;
|
return aideButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JButton getRelancerButton() {
|
||||||
|
return relancerButton;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Observable o, Object arg) {
|
public void update(Observable o, Object arg) {
|
||||||
if (o instanceof Jeu) {
|
if (o instanceof Jeu) {
|
||||||
|
|||||||
Reference in New Issue
Block a user