Ajout de la visualisation de la prochaine pièce dans vuecontrole

This commit is contained in:
ROGER
2025-05-13 15:16:35 +02:00
parent 6af84d8dda
commit 43037c4174
4 changed files with 53 additions and 20 deletions

View File

@@ -14,4 +14,8 @@ public class PieceCourante {
}
}
}
public boolean[][] getMotif() {
return motif;
}
}

View File

@@ -2,12 +2,16 @@ package org.Models;
public class PieceL extends PieceCourante {
PieceL(){
public PieceL(){
super();
this.motif[1][0] = true;
this.motif[2][0] = true;
this.motif[3][0] = true;
this.motif[3][1] = true;
this.motif[3][2] = true;
}
@Override
public boolean[][] getMotif() {
return super.getMotif();
}
}

View File

@@ -1,5 +1,7 @@
package org.Views;
import org.Models.PieceCourante;
import javax.swing.*;
import java.awt.*;
@@ -7,6 +9,7 @@ public class VueControle extends JPanel {
private JLabel scoreLabel;
private JPanel nextPiecePanel;
private JButton pauseButton;
private JPanel[][] caseNextPiece = new JPanel[4][4];
public VueControle() {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
@@ -56,12 +59,30 @@ public class VueControle extends JPanel {
private void initierNextPiecePanel() {
nextPiecePanel.removeAll();
nextPiecePanel.setLayout(new GridLayout(4, 4));
for (int i = 0; i < 16; i++) {
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) {
boolean[][] motif = piece.getMotif();
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (motif[i][j]) {
caseNextPiece[i][j].setBackground(Color.RED);
} else {
caseNextPiece[i][j].setBackground(Color.WHITE);
}
}
}
nextPiecePanel.revalidate();
nextPiecePanel.repaint();
}

View File

@@ -1,27 +1,31 @@
package org.Views;
import org.Models.Grille;
import org.Models.PieceCourante;
import org.Models.PieceL;
import javax.swing.*;
import java.awt.*;
public class VueTetris extends JFrame {
public VueTetris (Grille grille){
SwingUtilities.invokeLater(() -> {
super("Tetris");
VueGrille vueGrille = new VueGrille(grille);
VueControle vueControle = new VueControle();
//Fenetre principale
JFrame fenetrePrincipale = new JFrame("Tetris");
fenetrePrincipale.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetrePrincipale.setLayout(new BorderLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
fenetrePrincipale.add(vueGrille, BorderLayout.CENTER);
fenetrePrincipale.add(vueControle, BorderLayout.EAST);
add(vueGrille, BorderLayout.CENTER);
add(vueControle, BorderLayout.EAST);
fenetrePrincipale.setSize(1000, 800);
fenetrePrincipale.setLocationRelativeTo(null);
fenetrePrincipale.setVisible(true);
});
setSize(1000, 800);
setLocationRelativeTo(null);
setVisible(true);
// Utilisation de la pièce L
PieceCourante pieceL = new PieceL();
vueControle.afficherPieceSuivante(pieceL);
}
}