diff --git a/app/src/main/java/org/Models/PieceCourante.java b/app/src/main/java/org/Models/PieceCourante.java index 86d1530..08c51b0 100644 --- a/app/src/main/java/org/Models/PieceCourante.java +++ b/app/src/main/java/org/Models/PieceCourante.java @@ -14,4 +14,8 @@ public class PieceCourante { } } } + + public boolean[][] getMotif() { + return motif; + } } diff --git a/app/src/main/java/org/Models/PieceL.java b/app/src/main/java/org/Models/PieceL.java index 226a9b0..0e81a40 100644 --- a/app/src/main/java/org/Models/PieceL.java +++ b/app/src/main/java/org/Models/PieceL.java @@ -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(); } } diff --git a/app/src/main/java/org/Views/VueControle.java b/app/src/main/java/org/Views/VueControle.java index 0a74b7c..ecf3e5e 100644 --- a/app/src/main/java/org/Views/VueControle.java +++ b/app/src/main/java/org/Views/VueControle.java @@ -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,11 +59,29 @@ public class VueControle extends JPanel { private void initierNextPiecePanel() { nextPiecePanel.removeAll(); nextPiecePanel.setLayout(new GridLayout(4, 4)); - for (int i = 0; i < 16; i++) { - JPanel caseG = new JPanel(); - caseG.setBorder(BorderFactory.createLineBorder(Color.BLACK)); - caseG.setBackground(Color.WHITE); - nextPiecePanel.add(caseG); + 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(); diff --git a/app/src/main/java/org/Views/VueTetris.java b/app/src/main/java/org/Views/VueTetris.java index 9bea88d..a0fcdf9 100644 --- a/app/src/main/java/org/Views/VueTetris.java +++ b/app/src/main/java/org/Views/VueTetris.java @@ -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(() -> { - VueGrille vueGrille = new VueGrille(grille); - VueControle vueControle = new VueControle(); + super("Tetris"); - //Fenetre principale - JFrame fenetrePrincipale = new JFrame("Tetris"); - fenetrePrincipale.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - fenetrePrincipale.setLayout(new BorderLayout()); + VueGrille vueGrille = new VueGrille(grille); + VueControle vueControle = new VueControle(); - fenetrePrincipale.add(vueGrille, BorderLayout.CENTER); - fenetrePrincipale.add(vueControle, BorderLayout.EAST); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setLayout(new BorderLayout()); - fenetrePrincipale.setSize(1000, 800); - fenetrePrincipale.setLocationRelativeTo(null); - fenetrePrincipale.setVisible(true); - }); + add(vueGrille, BorderLayout.CENTER); + add(vueControle, BorderLayout.EAST); + + setSize(1000, 800); + setLocationRelativeTo(null); + setVisible(true); + + // Utilisation de la pièce L + PieceCourante pieceL = new PieceL(); + vueControle.afficherPieceSuivante(pieceL); } }