Ajout de la visualisation de la prochaine pièce dans vuecontrole
This commit is contained in:
@@ -14,4 +14,8 @@ public class PieceCourante {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean[][] getMotif() {
|
||||||
|
return motif;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,16 @@ package org.Models;
|
|||||||
|
|
||||||
public class PieceL extends PieceCourante {
|
public class PieceL extends PieceCourante {
|
||||||
|
|
||||||
PieceL(){
|
public PieceL(){
|
||||||
super();
|
super();
|
||||||
this.motif[1][0] = true;
|
this.motif[1][0] = true;
|
||||||
this.motif[2][0] = true;
|
this.motif[2][0] = true;
|
||||||
this.motif[3][0] = true;
|
this.motif[3][0] = true;
|
||||||
this.motif[3][1] = true;
|
this.motif[3][1] = true;
|
||||||
this.motif[3][2] = true;
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean[][] getMotif() {
|
||||||
|
return super.getMotif();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.Views;
|
package org.Views;
|
||||||
|
|
||||||
|
import org.Models.PieceCourante;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
@@ -7,6 +9,7 @@ public class VueControle extends JPanel {
|
|||||||
private JLabel scoreLabel;
|
private JLabel scoreLabel;
|
||||||
private JPanel nextPiecePanel;
|
private JPanel nextPiecePanel;
|
||||||
private JButton pauseButton;
|
private JButton pauseButton;
|
||||||
|
private JPanel[][] caseNextPiece = new JPanel[4][4];
|
||||||
|
|
||||||
public VueControle() {
|
public VueControle() {
|
||||||
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||||
@@ -56,11 +59,29 @@ public class VueControle extends JPanel {
|
|||||||
private void initierNextPiecePanel() {
|
private void initierNextPiecePanel() {
|
||||||
nextPiecePanel.removeAll();
|
nextPiecePanel.removeAll();
|
||||||
nextPiecePanel.setLayout(new GridLayout(4, 4));
|
nextPiecePanel.setLayout(new GridLayout(4, 4));
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
JPanel caseG = new JPanel();
|
for (int j = 0; j < 4; j++) {
|
||||||
caseG.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
JPanel caseG = new JPanel();
|
||||||
caseG.setBackground(Color.WHITE);
|
caseG.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||||
nextPiecePanel.add(caseG);
|
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.revalidate();
|
||||||
nextPiecePanel.repaint();
|
nextPiecePanel.repaint();
|
||||||
|
|||||||
@@ -1,27 +1,31 @@
|
|||||||
package org.Views;
|
package org.Views;
|
||||||
|
|
||||||
import org.Models.Grille;
|
import org.Models.Grille;
|
||||||
|
import org.Models.PieceCourante;
|
||||||
|
import org.Models.PieceL;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class VueTetris extends JFrame {
|
public class VueTetris extends JFrame {
|
||||||
public VueTetris (Grille grille){
|
public VueTetris (Grille grille){
|
||||||
SwingUtilities.invokeLater(() -> {
|
super("Tetris");
|
||||||
VueGrille vueGrille = new VueGrille(grille);
|
|
||||||
VueControle vueControle = new VueControle();
|
|
||||||
|
|
||||||
//Fenetre principale
|
VueGrille vueGrille = new VueGrille(grille);
|
||||||
JFrame fenetrePrincipale = new JFrame("Tetris");
|
VueControle vueControle = new VueControle();
|
||||||
fenetrePrincipale.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
fenetrePrincipale.setLayout(new BorderLayout());
|
|
||||||
|
|
||||||
fenetrePrincipale.add(vueGrille, BorderLayout.CENTER);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
fenetrePrincipale.add(vueControle, BorderLayout.EAST);
|
setLayout(new BorderLayout());
|
||||||
|
|
||||||
fenetrePrincipale.setSize(1000, 800);
|
add(vueGrille, BorderLayout.CENTER);
|
||||||
fenetrePrincipale.setLocationRelativeTo(null);
|
add(vueControle, BorderLayout.EAST);
|
||||||
fenetrePrincipale.setVisible(true);
|
|
||||||
});
|
setSize(1000, 800);
|
||||||
|
setLocationRelativeTo(null);
|
||||||
|
setVisible(true);
|
||||||
|
|
||||||
|
// Utilisation de la pièce L
|
||||||
|
PieceCourante pieceL = new PieceL();
|
||||||
|
vueControle.afficherPieceSuivante(pieceL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user