refactor: better achitecture and next piece preview fixed
This commit is contained in:
@@ -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 ??
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user