refactor: better achitecture and next piece preview fixed

This commit is contained in:
Morph01
2025-05-19 22:47:02 +02:00
committed by Morph01
parent aa6ab95728
commit a3854362c8
6 changed files with 26 additions and 16 deletions

View File

@@ -2,20 +2,26 @@ package org.Views;
import org.Models.GridLayoutCarre;
import org.Models.GridLayoutCarre;
import org.Models.Jeu;
import org.Models.PieceCourante;
import javax.swing.*;
import java.awt.*;
import java.util.Observable;
import java.util.Observer;
public class VueBandeauControle extends JPanel {
@SuppressWarnings("deprecation")
public class VueBandeauControle extends JPanel implements Observer {
private JLabel scoreLabel;
private JPanel nextPiecePanel;
private JButton pauseButton;
private JPanel[][] caseNextPiece = new JPanel[4][4];
private JLabel nbLigneLabel;
private JButton quitterButton;
private Jeu jeu;
public VueBandeauControle() {
public VueBandeauControle(Jeu jeu) {
this.jeu = jeu;
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
setBackground(Color.gray);
// setPreferredSize();
@@ -65,6 +71,7 @@ public class VueBandeauControle extends JPanel {
add(boutonsPanel);
// setVisible(true);
jeu.addObserver(this);
}
public void setScore(int score) {
@@ -104,18 +111,31 @@ public class VueBandeauControle extends JPanel {
}
public void afficherPieceSuivante(PieceCourante piece) {
boolean[][] motif = piece.getMotif();
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);
} else {
caseNextPiece[i][j].setBackground(Color.WHITE);
}
}
}
nextPiecePanel.revalidate();
nextPiecePanel.repaint();
}
@Override
public void update(Observable o, Object arg) {
if (o instanceof Jeu) {
afficherPieceSuivante(jeu.getPieceSuivante());
// TODO : setScore ??
}
}
}