Files
Tetris/app/src/main/java/org/Views/VueBandeauControle.java
Morph01 3232cd136f Squashed commit of the following:
commit ab2fbeb8be52dc2886f39b72c158483793185b5c
Author: Morph01 <thibaut6969delastreet@gmail.com>
Date:   Tue May 20 15:18:20 2025 +0200

    feat: wav music file rather than mp3

commit e4ea00b4dfbe32a9a03d078a8b77c35bd934f2e6
Author: Morph01 <thibaut6969delastreet@gmail.com>
Date:   Tue May 20 14:34:34 2025 +0200

    refactor: refactor imports

commit 68ee1318f8f450f6c9358de8484c17978428949e
Author: Morph01 <thibaut6969delastreet@gmail.com>
Date:   Tue May 20 13:56:35 2025 +0200

    feat: add rotation support

commit c106cc74e351f40afbf5f03395ea14627f10b29b
Author: Morph01 <thibaut6969delastreet@gmail.com>
Date:   Tue May 20 11:44:48 2025 +0200

    fix: upper bound of generated pieces

commit 3caa2a69a49424e46078749eab53827df160af6c
Author: Morph01 <thibaut6969delastreet@gmail.com>
Date:   Tue May 20 11:40:37 2025 +0200

    Merge branch 'Gwendal' into Thibaut

commit be1fd8ddd58df1a0ab02d005ba68da154ae199c7
Author: Morph01 <thibaut6969delastreet@gmail.com>
Date:   Mon May 19 23:01:43 2025 +0200

    refactor: split in init vueGrille initialization of vueGrille rather than in constructor

commit 5ec983979b363bf671945757234047ddcc9a333e
Author: Morph01 <145839520+Morph01@users.noreply.github.com>
Date:   Mon May 19 22:47:02 2025 +0200

    refactor: better achitecture and next piece preview fixed

commit 524d96ef493c6053cfff4958697cea8583927aca
Author: Morph01 <145839520+Morph01@users.noreply.github.com>
Date:   Mon May 19 22:16:42 2025 +0200

    Squashed commit of the following:

    commit a8f543114e
    Author: ROGER <gwendal.roger@etu.univ-lyon1.fr>
    Date:   Mon May 19 21:59:38 2025 +0200

        ajout d'une fonctionnalité permettant de mettre en pause le Jeu grace à un bouton. Ajout d'un vérouillage du clavier pendant lause

    commit 27862eb3cd
    Author: ROGER <gwendal.roger@etu.univ-lyon1.fr>
    Date:   Fri May 16 17:10:15 2025 +0200

        Ajoute de l'arret de la musique en fin de partie + arret propre de l'ordonanceur

    commit 2fec9fc96e
    Author: ROGER <gwendal.roger@etu.univ-lyon1.fr>
    Date:   Fri May 16 16:17:58 2025 +0200

        integration du responsive dans l'affichage de la grille

commit 671d12f418bb6c5a0ae623e5195d78eebef4e641
Author: Morph01 <145839520+Morph01@users.noreply.github.com>
Date:   Mon May 19 22:02:16 2025 +0200

    fix: piece generation
2025-05-20 16:10:52 +02:00

182 lines
6.0 KiB
Java

package org.Views;
import org.Models.Jeu;
import org.Models.PieceCourante;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import java.util.Observable;
import java.util.Observer;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
@SuppressWarnings("deprecation")
public class VueBandeauControle extends JPanel implements Observer {
private JLabel scoreLabel;
private JPanel nextPiecePanel;
private JButton pauseButton;
private JButton aideButton;
private JPanel[][] caseNextPiece = new JPanel[4][4];
private JLabel nbLigneLabel;
private JButton quitterButton;
private Jeu jeu;
private JButton relancerButton;
public VueBandeauControle(Jeu jeu) {
this.jeu = jeu;
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
setBackground(Color.gray);
// setPreferredSize();
// SCORE
scoreLabel = new JLabel("SCORE : " + jeu.getGrille().getScore());
scoreLabel.setForeground(Color.white);
scoreLabel.setFont(new Font("Arial", Font.PLAIN, 16));
scoreLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
// NB LIGNE
nbLigneLabel = new JLabel("LIGNES : " + jeu.getGrille().getNbLignesSupprimees());
nbLigneLabel.setForeground(Color.white);
nbLigneLabel.setFont(new Font("Arial", Font.PLAIN, 16));
nbLigneLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
// NEXT PIECE
nextPiecePanel = new JPanel();
nextPiecePanel.setBackground(Color.LIGHT_GRAY);
nextPiecePanel.setAlignmentX(Component.CENTER_ALIGNMENT);
initierNextPiecePanel();
// PAUSE BUTTON & QUIT BUTTON
pauseButton = new JButton("PAUSE");
quitterButton = new JButton("QUITTER");
Dimension buttonSize = new Dimension(85, 30);
Insets margeBoutton = new Insets(2, 2, 2, 2);
pauseButton.setPreferredSize(buttonSize);
pauseButton.setMargin(margeBoutton);
quitterButton.setPreferredSize(buttonSize);
quitterButton.setMargin(margeBoutton);
JPanel hautBoutonsPanel = new JPanel();
// boutonsPanel.setLayout(new BoxLayout(boutonsPanel, BoxLayout.X_AXIS));
hautBoutonsPanel.setOpaque(false);
hautBoutonsPanel.add(pauseButton);
hautBoutonsPanel.add(Box.createRigidArea(new Dimension(10, 0)));
hautBoutonsPanel.add(quitterButton);
pauseButton.setFocusable(false);
quitterButton.setFocusable(false);
// Relancer button
relancerButton = new JButton("RESTART");
relancerButton.setPreferredSize(buttonSize);
relancerButton.setMargin(margeBoutton);
relancerButton.setFocusable(false);
// AIDE BUTTON
aideButton = new JButton("?");
aideButton.setToolTipText("AFFICHER L'AIDE");
aideButton.setPreferredSize(new Dimension(45, 20));
aideButton.setFocusable(false);
JPanel footerPanel = new JPanel(new BorderLayout());
footerPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 40));
footerPanel.setOpaque(false);
footerPanel.add(relancerButton, BorderLayout.WEST);
footerPanel.add(aideButton, BorderLayout.EAST);
add(Box.createVerticalStrut(20));
add(scoreLabel);
add(Box.createVerticalStrut(20));
add(nbLigneLabel);
add(Box.createVerticalStrut(20));
add(nextPiecePanel);
add(Box.createVerticalStrut(20));
add(hautBoutonsPanel);
add(Box.createVerticalGlue()); // force le JPanel à prendre toute la hauteur
add(footerPanel);
// setVisible(true);
jeu.addObserver(this);
}
public void setScore(int score) {
scoreLabel.setText("Score: " + score);
}
public JButton getPauseButton() {
return pauseButton;
}
public JButton getQuitterButton() {
return quitterButton;
}
public JPanel getNextPiecePanel() {
return nextPiecePanel;
}
private void initierNextPiecePanel() {
nextPiecePanel.removeAll();
nextPiecePanel.setLayout(new GridLayoutCarre(4, 4));
Dimension tailleCarre = new Dimension(120, 120);
nextPiecePanel.setPreferredSize(tailleCarre);
nextPiecePanel.setMaximumSize(tailleCarre);
nextPiecePanel.setMinimumSize(tailleCarre);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
JPanel caseG = new JPanel();
caseG.setBorder(BorderFactory.createLineBorder(Color.BLACK));
caseG.setBackground(Color.WHITE);
caseNextPiece[i][j] = caseG;
nextPiecePanel.add(caseG);
}
}
nextPiecePanel.revalidate();
nextPiecePanel.repaint();
}
public void afficherPieceSuivante(PieceCourante piece) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
caseNextPiece[i][j].setBackground(Color.WHITE);
}
}
boolean[][] motif = piece.getMotif();
for (int i = 0; i < motif.length; i++) {
for (int j = 0; j < motif[i].length; j++) {
if (motif[i][j]) {
caseNextPiece[i][j].setBackground(Color.RED);
}
}
}
nextPiecePanel.revalidate();
nextPiecePanel.repaint();
}
public JButton getAideButton() {
return aideButton;
}
public JButton getRelancerButton() {
return relancerButton;
}
@Override
public void update(Observable o, Object arg) {
if (o instanceof Jeu) {
afficherPieceSuivante(jeu.getPieceSuivante());
setScore(jeu.getGrille().getScore());
nbLigneLabel.setText("LIGNES : " + jeu.getGrille().getNbLignesSupprimees());
scoreLabel.setText("SCORE : " + jeu.getGrille().getScore());
}
}
}